mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-12 17:19:05 -05:00
FindGit: Add imported target
This commit is contained in:
@@ -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
|
FindGit
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
The module defines the following ``IMPORTED`` targets:
|
||||||
|
|
||||||
|
``Git::Git``
|
||||||
|
Executable of the Git command-line client.
|
||||||
|
|
||||||
The module defines the following variables:
|
The module defines the following variables:
|
||||||
|
|
||||||
``GIT_EXECUTABLE``
|
``GIT_EXECUTABLE``
|
||||||
@@ -78,6 +83,12 @@ if(GIT_EXECUTABLE)
|
|||||||
string(REPLACE "git version " "" GIT_VERSION_STRING "${git_version}")
|
string(REPLACE "git version " "" GIT_VERSION_STRING "${git_version}")
|
||||||
endif()
|
endif()
|
||||||
unset(git_version)
|
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()
|
endif()
|
||||||
|
|
||||||
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
|
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)
|
add_subdirectory(FindGIF)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(CMake_TEST_FindGit)
|
||||||
|
add_subdirectory(FindGit)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(CMake_TEST_FindGSL)
|
if(CMake_TEST_FindGSL)
|
||||||
add_subdirectory(FindGSL)
|
add_subdirectory(FindGSL)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -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>
|
||||||
|
)
|
||||||
@@ -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"
|
||||||
|
)
|
||||||
@@ -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