diff options
author | Craig Scott <craig.scott@crascit.com> | 2020-10-01 11:43:29 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-10-01 11:43:38 (GMT) |
commit | 431f1183ef0b700168befb27b13c7d258004bba9 (patch) | |
tree | a8d7a37f6e4f28f1edaf1203cd98ec65fbe5c16d /Tests | |
parent | c70d083b43e3a0b76e52d7911572ebda1aa0fad9 (diff) | |
parent | e4b7049230afabd7f2cc0186f26176b103682100 (diff) | |
download | CMake-431f1183ef0b700168befb27b13c7d258004bba9.zip CMake-431f1183ef0b700168befb27b13c7d258004bba9.tar.gz CMake-431f1183ef0b700168befb27b13c7d258004bba9.tar.bz2 |
Merge topic 'FindPython-version_range'
e4b7049230 FindPython: Add version range support
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5265
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/FindPython/CMakeLists.txt | 104 | ||||
-rw-r--r-- | Tests/FindPython/VersionRange/CMakeLists.txt | 55 |
2 files changed, 159 insertions, 0 deletions
diff --git a/Tests/FindPython/CMakeLists.txt b/Tests/FindPython/CMakeLists.txt index fdfa36e..44484c3 100644 --- a/Tests/FindPython/CMakeLists.txt +++ b/Tests/FindPython/CMakeLists.txt @@ -243,6 +243,87 @@ if(CMake_TEST_FindPython) --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> ) + add_test(NAME FindPython.Python3.VersionRange.LOCATION COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/VersionRange" + "${CMake_BINARY_DIR}/Tests/FindPython/Python3.VersionRange.LOCATION" + ${build_generator_args} + --build-project TestVersionRange + --build-options ${build_options} -DPython=Python3 -DPython_REQUESTED_VERSION=3 + -DPython3_FIND_STRATEGY=LOCATION + ) + add_test(NAME FindPython.Python3.VersionRange.VERSION COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/VersionRange" + "${CMake_BINARY_DIR}/Tests/FindPython/Python3.VersionRange.VERSION" + ${build_generator_args} + --build-project TestVersionRange + --build-options ${build_options} -DPython=Python3 -DPython_REQUESTED_VERSION=3 + -DPython3_FIND_STRATEGY=VERSION + ) + add_test(NAME FindPython.Python2.VersionRange.LOCATION COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/VersionRange" + "${CMake_BINARY_DIR}/Tests/FindPython/Python2.VersionRange.LOCATION" + ${build_generator_args} + --build-project TestVersionRange + --build-options ${build_options} -DPython=Python2 -DPython_REQUESTED_VERSION=2 + -DPython2_FIND_STRATEGY=LOCATION + ) + add_test(NAME FindPython.Python2.VersionRange.VERSION COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/VersionRange" + "${CMake_BINARY_DIR}/Tests/FindPython/Python2.VersionRange.VERSION" + ${build_generator_args} + --build-project TestVersionRange + --build-options ${build_options} -DPython=Python2 -DPython_REQUESTED_VERSION=2 + -DPython2_FIND_STRATEGY=VERSION + ) + add_test(NAME FindPython.Python.V2.VersionRange.LOCATION COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/VersionRange" + "${CMake_BINARY_DIR}/Tests/FindPython/Python.V2.VersionRange.LOCATION" + ${build_generator_args} + --build-project TestVersionRange + --build-options ${build_options} -DPython=Python -DPython_REQUESTED_VERSION=2 + -DPython_FIND_STRATEGY=LOCATION + ) + add_test(NAME FindPython.Python.V2.VersionRange.VERSION COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/VersionRange" + "${CMake_BINARY_DIR}/Tests/FindPython/Python.V2.VersionRange.VERSION" + ${build_generator_args} + --build-project TestVersionRange + --build-options ${build_options} -DPython=Python -DPython_REQUESTED_VERSION=2 + -DPython_FIND_STRATEGY=VERSION + ) + add_test(NAME FindPython.Python.V3.VersionRange.LOCATION COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/VersionRange" + "${CMake_BINARY_DIR}/Tests/FindPython/Python.V3.VersionRange.LOCATION" + ${build_generator_args} + --build-project TestVersionRange + --build-options ${build_options} -DPython=Python -DPython_REQUESTED_VERSION=3 + -DPython_FIND_STRATEGY=LOCATION + ) + add_test(NAME FindPython.Python.V3.VersionRange.VERSION COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/VersionRange" + "${CMake_BINARY_DIR}/Tests/FindPython/Python.V3.VersionRange.VERSION" + ${build_generator_args} + --build-project TestVersionRange + --build-options ${build_options} -DPython=Python -DPython_REQUESTED_VERSION=3 + -DPython_FIND_STRATEGY=VERSION + ) + add_test(NAME FindPython.MultiplePackages COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> --build-and-test @@ -492,6 +573,29 @@ if(CMake_TEST_FindPython_IronPython) --build-options ${build_options} -DPython_REQUESTED_VERSION=2 -DPython_FIND_STRATEGY=VERSION --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> ) + + add_test(NAME FindPython.IronPython2.VersionRange.LOCATION COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/VersionRange" + "${CMake_BINARY_DIR}/Tests/FindPython/IronPython2.VersionRange.LOCATION" + ${build_generator_args} + --build-project TestVersionRange + --build-options ${build_options} -DPython=Python2 -DPython_REQUESTED_VERSION=2 + -DPython2_FIND_IMPLEMENTATIONS=IronPython + -DPython2_FIND_STRATEGY=LOCATION + ) + add_test(NAME FindPython.IronPython2.VersionRange.VERSION COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/VersionRange" + "${CMake_BINARY_DIR}/Tests/FindPython/IronPython2.VersionRange.VERSION" + ${build_generator_args} + --build-project TestVersionRange + --build-options ${build_options} -DPython=Python2 -DPython_REQUESTED_VERSION=2 + -DPython2_FIND_IMPLEMENTATIONS=IronPython + -DPython2_FIND_STRATEGY=VERSION + ) endif() if(CMake_TEST_FindPython_PyPy) diff --git a/Tests/FindPython/VersionRange/CMakeLists.txt b/Tests/FindPython/VersionRange/CMakeLists.txt new file mode 100644 index 0000000..0d946f5 --- /dev/null +++ b/Tests/FindPython/VersionRange/CMakeLists.txt @@ -0,0 +1,55 @@ +cmake_minimum_required (VERSION 3.18...3.19) + +project (TestVersionRange LANGUAGES NONE) + + +find_package (${Python} ${Python_REQUESTED_VERSION} EXACT COMPONENTS Interpreter) +if (NOT ${Python}_FOUND) + message (FATAL_ERROR "Failed to find ${Python} ${Python_REQUESTED_VERSION}") +endif() + +if (Python_REQUESTED_VERSION VERSION_LESS 3.0) + set (IN_VERSION_RANGE 2.0...<3.0) + set (OUT_VERSION_RANGE 2.0...<${${Python}_VERSION}) +else() + set (IN_VERSION_RANGE 3.0...<4.0) + set (OUT_VERSION_RANGE 3.0...<${${Python}_VERSION}) +endif() + +function (FIND_PYTHON EXPECTED_VERSION) + unset (_${Python}_EXECUTABLE CACHE) + unset (_${Python}_LIBRARY_RELEASE CACHE) + unset (_${Python}_INCLUDE_DIR CACHE) + unset (${Python}_FOUND) + + find_package (${ARGN}) + + if (EXPECTED_VERSION STREQUAL "NONE") + if (${Python}_FOUND) + message (SEND_ERROR "Unexpectedly found version: ${${Python}_VERSION} for ${ARGN}") + endif() + return() + endif() + + if (NOT ${Python}_FOUND) + message (SEND_ERROR "Not found: ${ARGN}") + elseif (NOT ${Python}_VERSION VERSION_EQUAL EXPECTED_VERSION) + message (SEND_ERROR "Wrong version: ${${Python}_VERSION} for ${ARGN}") + endif() +endfunction() + +find_python (${${Python}_VERSION} ${Python} ${IN_VERSION_RANGE} COMPONENTS Interpreter) +if (${Python}_FIND_IMPLEMENTATIONS STREQUAL "IronPython") + find_python (${${Python}_VERSION} ${Python} ${IN_VERSION_RANGE} COMPONENTS Compiler) +else() + find_python (${${Python}_VERSION} ${Python} ${IN_VERSION_RANGE} COMPONENTS Development) +endif() + +find_python ("NONE" ${Python} ${OUT_VERSION_RANGE} COMPONENTS Interpreter) +if (${Python}_FIND_IMPLEMENTATIONS STREQUAL "IronPython") + find_python ("NONE" ${Python} ${OUT_VERSION_RANGE} COMPONENTS Compiler) +else() + find_python ("NONE" ${Python} ${OUT_VERSION_RANGE} COMPONENTS Development) +endif() + +find_python ("NONE" ${Python} 5...6 COMPONENTS Interpreter) |