mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
FindGit: Add imported target
This commit is contained in:
5
Help/release/dev/findgit-imported-target.rst
Normal file
5
Help/release/dev/findgit-imported-target.rst
Normal file
@@ -0,0 +1,5 @@
|
||||
findgit-imported-target
|
||||
-----------------------
|
||||
|
||||
* The :module:`FindGit` module now provides an ``IMPORTED`` target for the Git
|
||||
executable.
|
||||
@@ -5,6 +5,11 @@
|
||||
FindGit
|
||||
-------
|
||||
|
||||
The module defines the following ``IMPORTED`` targets:
|
||||
|
||||
``Git::Git``
|
||||
Executable of the Git command-line client.
|
||||
|
||||
The module defines the following variables:
|
||||
|
||||
``GIT_EXECUTABLE``
|
||||
@@ -78,6 +83,12 @@ if(GIT_EXECUTABLE)
|
||||
string(REPLACE "git version " "" GIT_VERSION_STRING "${git_version}")
|
||||
endif()
|
||||
unset(git_version)
|
||||
|
||||
get_property(_findgit_role GLOBAL PROPERTY CMAKE_ROLE)
|
||||
if(_findgit_role STREQUAL "PROJECT" AND NOT TARGET Git::Git)
|
||||
add_executable(Git::Git IMPORTED)
|
||||
set_property(TARGET Git::Git PROPERTY IMPORTED_LOCATION "${GIT_EXECUTABLE}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
|
||||
|
||||
@@ -1437,6 +1437,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
|
||||
add_subdirectory(FindGIF)
|
||||
endif()
|
||||
|
||||
if(CMake_TEST_FindGit)
|
||||
add_subdirectory(FindGit)
|
||||
endif()
|
||||
|
||||
if(CMake_TEST_FindGSL)
|
||||
add_subdirectory(FindGSL)
|
||||
endif()
|
||||
|
||||
10
Tests/FindGit/CMakeLists.txt
Normal file
10
Tests/FindGit/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
add_test(NAME FindGit.Test COMMAND
|
||||
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
|
||||
--build-and-test
|
||||
"${CMake_SOURCE_DIR}/Tests/FindGit/Test"
|
||||
"${CMake_BINARY_DIR}/Tests/FindGit/Test"
|
||||
${build_generator_args}
|
||||
--build-project TestFindGit
|
||||
--build-options ${build_options}
|
||||
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
|
||||
)
|
||||
13
Tests/FindGit/Test/CMakeLists.txt
Normal file
13
Tests/FindGit/Test/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(TestFindGit NONE)
|
||||
include(CTest)
|
||||
|
||||
find_package(Git REQUIRED)
|
||||
|
||||
add_test(NAME test_git
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
"-DGIT_EXECUTABLE=${GIT_EXECUTABLE}"
|
||||
"-DGIT_EXECUTABLE_TARGET=$<TARGET_FILE:Git::Git>"
|
||||
"-DGIT_VERSION_STRING=${GIT_VERSION_STRING}"
|
||||
-P "${CMAKE_CURRENT_LIST_DIR}/RunGit.cmake"
|
||||
)
|
||||
20
Tests/FindGit/Test/RunGit.cmake
Normal file
20
Tests/FindGit/Test/RunGit.cmake
Normal file
@@ -0,0 +1,20 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
|
||||
function(run_git exe exe_display)
|
||||
execute_process(COMMAND ${exe} --version
|
||||
OUTPUT_VARIABLE output
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE result
|
||||
)
|
||||
|
||||
if(NOT result EQUAL 0)
|
||||
message(SEND_ERROR "Result of ${exe_display} --version is ${result}, should be 0")
|
||||
endif()
|
||||
|
||||
if(NOT output STREQUAL "git version ${GIT_VERSION_STRING}")
|
||||
message(SEND_ERROR "Output of ${exe_display} --version is \"${output}\", should be \"git version ${GIT_VERSION_STRING}\"")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
run_git("${GIT_EXECUTABLE}" "\${GIT_EXECUTABLE}")
|
||||
run_git("${GIT_EXECUTABLE_TARGET}" "Git::Git")
|
||||
Reference in New Issue
Block a user