diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2022-11-18 15:24:17 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2022-11-29 15:48:08 (GMT) |
commit | 77d734aede807a038ab10520620cfbb24e84e76e (patch) | |
tree | bc20ce786a249862842c82484393d61edef2b0ca /Tests/FindPython | |
parent | f72c405d4ee4ad4775a10a944774b91f49726dad (diff) | |
download | CMake-77d734aede807a038ab10520620cfbb24e84e76e.zip CMake-77d734aede807a038ab10520620cfbb24e84e76e.tar.gz CMake-77d734aede807a038ab10520620cfbb24e84e76e.tar.bz2 |
FindPython: add support for Stable ABI
Fixes: #24141
Diffstat (limited to 'Tests/FindPython')
-rw-r--r-- | Tests/FindPython/CMakeLists.txt | 30 | ||||
-rw-r--r-- | Tests/FindPython/Python2SABIModule/CMakeLists.txt | 5 | ||||
-rw-r--r-- | Tests/FindPython/Python3Module/CMakeLists.txt | 9 | ||||
-rw-r--r-- | Tests/FindPython/Python3SABIModule/CMakeLists.txt | 51 | ||||
-rw-r--r-- | Tests/FindPython/RequiredArtifacts/CMakeLists.txt | 32 | ||||
-rw-r--r-- | Tests/FindPython/RequiredArtifacts/Check/CMakeLists.txt | 8 |
6 files changed, 134 insertions, 1 deletions
diff --git a/Tests/FindPython/CMakeLists.txt b/Tests/FindPython/CMakeLists.txt index d4cf36b..b6942c9 100644 --- a/Tests/FindPython/CMakeLists.txt +++ b/Tests/FindPython/CMakeLists.txt @@ -377,6 +377,7 @@ if(CMake_TEST_FindPython) --build-options ${build_options} "-Dbuild_generator_args=${build_generator_args}" "-DCMake_SOURCE_DIR=${CMake_SOURCE_DIR}" "-DCMake_BINARY_DIR=${CMake_BINARY_DIR}" + "-DCMake_TEST_FindPython_SABIModule=${CMake_TEST_FindPython_SABIModule}" --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> ) @@ -478,6 +479,35 @@ if(CMake_TEST_FindPython) endif() endif() +if(CMake_TEST_FindPython_SABIModule) + add_test(NAME FindPython.Python2.Development.SABIModule COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/Python2SABIModule" + "${CMake_BINARY_DIR}/Tests/FindPython/Python2SABIModule" + ${build_generator_args} + --build-project TestPython2SABIModule + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) + set_tests_properties(FindPython.Python2.Development.SABIModule PROPERTIES + PASS_REGULAR_EXPRESSION "Could NOT find Python2 \\(missing: .*Development\\.SABIModule") + + # Use exclusively Release configuration because Debug is, on Windows with MSVC, + # unusable with SABI: Python force link with debug version of full versioned library rather than + # the stable ABI one. + add_test(NAME FindPython.Python3.Development.SABIModule COMMAND + ${CMAKE_CTEST_COMMAND} -C Release + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/Python3SABIModule" + "${CMake_BINARY_DIR}/Tests/FindPython/Python3SABIModule" + ${build_generator_args} + --build-project TestPython3SABIModule + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C Release + ) +endif() + if(CMake_TEST_FindPython_NumPy) add_test(NAME FindPython.NumPy COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> diff --git a/Tests/FindPython/Python2SABIModule/CMakeLists.txt b/Tests/FindPython/Python2SABIModule/CMakeLists.txt new file mode 100644 index 0000000..4f01197 --- /dev/null +++ b/Tests/FindPython/Python2SABIModule/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.1) + +project(TestPython2SABIModule LANGUAGES C) + +find_package(Python2 REQUIRED COMPONENTS Interpreter Development.Module Development.SABIModule) diff --git a/Tests/FindPython/Python3Module/CMakeLists.txt b/Tests/FindPython/Python3Module/CMakeLists.txt index 5945962..ccc1fdb 100644 --- a/Tests/FindPython/Python3Module/CMakeLists.txt +++ b/Tests/FindPython/Python3Module/CMakeLists.txt @@ -11,6 +11,9 @@ endif() if (Python3_Development_FOUND) message (FATAL_ERROR "Python 3, COMPONENT 'Development' unexpectedly found") endif() +if (Python3_Development.SABIModule_FOUND) + message (FATAL_ERROR "Python 3, COMPONENT 'Development.SABIModule' unexpectedly found") +endif() if (Python3_Development.Embed_FOUND) message (FATAL_ERROR "Python 3, COMPONENT 'Development.Embed' unexpectedly found") endif() @@ -25,6 +28,12 @@ endif() if(TARGET Python3::Python) message(SEND_ERROR "Python3::Python unexpectedly found") endif() +if(TARGET Python3::SABIMOdule) + message(SEND_ERROR "Python3::SABIModule unexpectedly found") +endif() +if(TARGET Python3::Embed) + message(SEND_ERROR "Python3::Embed unexpectedly found") +endif() if(NOT TARGET Python3::Module) message(SEND_ERROR "Python3::Module not found") endif() diff --git a/Tests/FindPython/Python3SABIModule/CMakeLists.txt b/Tests/FindPython/Python3SABIModule/CMakeLists.txt new file mode 100644 index 0000000..2a067d0 --- /dev/null +++ b/Tests/FindPython/Python3SABIModule/CMakeLists.txt @@ -0,0 +1,51 @@ +cmake_minimum_required(VERSION 3.1) + +project(TestPython3SABIModule LANGUAGES C) + +include(CTest) + +find_package(Python3 REQUIRED COMPONENTS Interpreter Development.SABIModule) +if (NOT Python3_FOUND) + message (FATAL_ERROR "Failed to find Python 3") +endif() +if (Python3_Development_FOUND) + message (FATAL_ERROR "Python 3, COMPONENT 'Development' unexpectedly found") +endif() +if (Python3_Development.Embed_FOUND) + message (FATAL_ERROR "Python 3, COMPONENT 'Development.Embed' unexpectedly found") +endif() +if (Python3_Development.Module_FOUND) + message (FATAL_ERROR "Python 3, COMPONENT 'Development.Module' unexpectedly found") +endif() +if (NOT Python3_Development.SABIModule_FOUND) + message (FATAL_ERROR "Python 3, COMPONENT 'Development.SABIModule' not found") +endif() + +if(NOT TARGET Python3::Interpreter) + message(SEND_ERROR "Python3::Interpreter not found") +endif() + +if(TARGET Python3::Python) + message(SEND_ERROR "Python3::Python unexpectedly found") +endif() +if(TARGET Python3::Module) + message(SEND_ERROR "Python3::Module unexpectedly found") +endif() +if(NOT TARGET Python3::SABIModule) + message(SEND_ERROR "Python3::SABIModule not found") +endif() + +Python3_add_library (spam3 MODULE USE_SABI 3 WITH_SOABI ../spam.c) +target_compile_definitions (spam3 PRIVATE PYTHON3) + +if (Python3_SOSABI) + get_property (suffix TARGET spam3 PROPERTY SUFFIX) + if (NOT suffix MATCHES "^.${Python3_SOSABI}") + message(FATAL_ERROR "Module suffix do not include Python3_SOSABI") + endif() +endif() + + +add_test (NAME python3_spam3 + COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:spam3>" + "${Python3_EXECUTABLE}" -c "import spam3; spam3.system(\"cd\")") diff --git a/Tests/FindPython/RequiredArtifacts/CMakeLists.txt b/Tests/FindPython/RequiredArtifacts/CMakeLists.txt index ae50f32..42d282d 100644 --- a/Tests/FindPython/RequiredArtifacts/CMakeLists.txt +++ b/Tests/FindPython/RequiredArtifacts/CMakeLists.txt @@ -8,7 +8,12 @@ find_package(Python2 REQUIRED COMPONENTS Interpreter Development) if (NOT Python2_FOUND) message (FATAL_ERROR "Failed to find Python 2") endif() -find_package(Python3 REQUIRED COMPONENTS Interpreter Development) + +set(components Interpreter Development) +if (CMake_TEST_FindPython_SABIModule AND WIN32) + list (APPEND components Development.SABIModule) +endif() +find_package(Python3 REQUIRED COMPONENTS ${components}) if (NOT Python3_FOUND) message (FATAL_ERROR "Failed to find Python 3") endif() @@ -108,3 +113,28 @@ add_test(NAME FindPython.RequiredArtifacts.Library-Include.INVALID COMMAND "-DPython3_INCLUDE_DIR=${Python2_INCLUDE_DIRS}" --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> ) + +if (CMake_TEST_FindPython_SABIModule AND WIN32) + add_test(NAME FindPython.RequiredArtifacts.SABILibrary.VALID COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/RequiredArtifacts/Check" + "${CMake_BINARY_DIR}/Tests/FindPython/RequiredArtifacts/SABILibrary.VALID" + ${build_generator_args} + --build-project TestRequiredArtifacts.Check + --build-options -DPYTHON_IS_FOUND=TRUE -DCHECK_SABI_LIBRARY=ON + "-DPython3_SABI_LIBRARY=${Python3_SABI_LIBRARY_RELEASE}" + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) + add_test(NAME FindPython.RequiredArtifacts.SABILibrary.INVALID COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/RequiredArtifacts/Check" + "${CMake_BINARY_DIR}/Tests/FindPython/RequiredArtifacts/SABILibrary.INVALID" + ${build_generator_args} + --build-project TestRequiredArtifacts.Check + --build-options -DPYTHON_IS_FOUND=FALSE -DCHECK_SABI_LIBRARY=ON + "-DPython3_SABI_LIBRARY=${Python2_LIBRARY_RELEASE}" + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) +endif() diff --git a/Tests/FindPython/RequiredArtifacts/Check/CMakeLists.txt b/Tests/FindPython/RequiredArtifacts/Check/CMakeLists.txt index 287cfdb..bb4f67c 100644 --- a/Tests/FindPython/RequiredArtifacts/Check/CMakeLists.txt +++ b/Tests/FindPython/RequiredArtifacts/Check/CMakeLists.txt @@ -16,6 +16,10 @@ if (CHECK_LIBRARY OR CHECK_INCLUDE) set (required_include "${Python3_INCLUDE_DIR}") endif() endif() +if (CHECK_SABI_LIBRARY) + list (APPEND components Development.SABIModule) + set (required_sabi_library "${Python3_SABI_LIBRARY}") +endif() find_package (Python3 COMPONENTS ${components}) @@ -39,3 +43,7 @@ endif() if (CHECK_INCLUDE AND NOT Python3_INCLUDE_DIRS STREQUAL required_include) message (FATAL_ERROR "Failed to use input variable Python3_INCLUDE_DIR") endif() + +if (CHECK_SABI_LIBRARY AND NOT Python3_SABI_LIBRARY_RELEASE STREQUAL required_sabi_library) + message (FATAL_ERROR "Failed to use input variable Python3_SABI_LIBRARY") +endif() |