mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-05 05:39:57 -05:00
@@ -1538,8 +1538,11 @@ if(BUILD_TESTING)
|
||||
add_subdirectory(GoogleTest)
|
||||
endif()
|
||||
|
||||
if(CMake_TEST_FindPython OR CMake_TEST_FindPython_NumPy
|
||||
if(CMake_TEST_FindPython OR CMake_TEST_FindPython_SABIModule OR CMake_TEST_FindPython_NumPy
|
||||
OR CMake_TEST_FindPython_Conda OR CMake_TEST_FindPython_IronPython OR CMake_TEST_FindPython_PyPy)
|
||||
if (CMake_TEST_FindPython AND CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin")
|
||||
set(CMake_TEST_FindPython_SABIModule TRUE)
|
||||
endif()
|
||||
add_subdirectory(FindPython)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
|
||||
project(TestPython2SABIModule LANGUAGES C)
|
||||
|
||||
find_package(Python2 REQUIRED COMPONENTS Interpreter Development.Module Development.SABIModule)
|
||||
@@ -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()
|
||||
|
||||
@@ -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\")")
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user