diff options
author | Brad King <brad.king@kitware.com> | 2019-01-22 14:40:33 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-01-22 14:40:39 (GMT) |
commit | ad2ed96a85ff2548222093723b923305732a79cb (patch) | |
tree | 523433b8c6f2fca6925d9588326f06bdf1a97088 | |
parent | 4b017d579d00f1d4d032eda7e179f57bdd1da080 (diff) | |
parent | 97700e9f5b17b1631f6bfef4fec62dad88dc9319 (diff) | |
download | CMake-ad2ed96a85ff2548222093723b923305732a79cb.zip CMake-ad2ed96a85ff2548222093723b923305732a79cb.tar.gz CMake-ad2ed96a85ff2548222093723b923305732a79cb.tar.bz2 |
Merge topic 'findgit-imported-target'
97700e9f5b FindGit: Add imported target
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2790
-rw-r--r-- | Help/release/dev/findgit-imported-target.rst | 5 | ||||
-rw-r--r-- | Modules/FindGit.cmake | 11 | ||||
-rw-r--r-- | Tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Tests/FindGit/CMakeLists.txt | 10 | ||||
-rw-r--r-- | Tests/FindGit/Test/CMakeLists.txt | 13 | ||||
-rw-r--r-- | Tests/FindGit/Test/RunGit.cmake | 20 |
6 files changed, 63 insertions, 0 deletions
diff --git a/Help/release/dev/findgit-imported-target.rst b/Help/release/dev/findgit-imported-target.rst new file mode 100644 index 0000000..cabbae5 --- /dev/null +++ b/Help/release/dev/findgit-imported-target.rst @@ -0,0 +1,5 @@ +findgit-imported-target +----------------------- + +* The :module:`FindGit` module now provides an ``IMPORTED`` target for the Git + executable. diff --git a/Modules/FindGit.cmake b/Modules/FindGit.cmake index c447a1a..900e4f5 100644 --- a/Modules/FindGit.cmake +++ b/Modules/FindGit.cmake @@ -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) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 86f4c56..c1703cc 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -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() diff --git a/Tests/FindGit/CMakeLists.txt b/Tests/FindGit/CMakeLists.txt new file mode 100644 index 0000000..5d061f4 --- /dev/null +++ b/Tests/FindGit/CMakeLists.txt @@ -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> + ) diff --git a/Tests/FindGit/Test/CMakeLists.txt b/Tests/FindGit/Test/CMakeLists.txt new file mode 100644 index 0000000..26fb372 --- /dev/null +++ b/Tests/FindGit/Test/CMakeLists.txt @@ -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" + ) diff --git a/Tests/FindGit/Test/RunGit.cmake b/Tests/FindGit/Test/RunGit.cmake new file mode 100644 index 0000000..f798cd3 --- /dev/null +++ b/Tests/FindGit/Test/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") |