mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-07 22:59:56 -05:00
FindPython: Add possibility to control scope of artifacts.
Fixes: #20362
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
|
||||
project(TestArtifactsInteractive LANGUAGES C)
|
||||
|
||||
set (components Interpreter Development)
|
||||
if (CMake_TEST_FindPython_NumPy)
|
||||
list (APPEND components NumPy)
|
||||
endif()
|
||||
|
||||
find_package(Python3 REQUIRED COMPONENTS ${components})
|
||||
|
||||
if (Python3_ARTIFACTS_INTERACTIVE)
|
||||
if (NOT DEFINED CACHE{Python3_EXECUTABLE}
|
||||
OR NOT DEFINED CACHE{Python3_LIBRARY} OR NOT DEFINED CACHE{Python3_INCLUDE_DIR}
|
||||
OR (CMake_TEST_FindPython_NumPy AND NOT DEFINED CACHE{Python3_NumPy_INCLUDE_DIR}))
|
||||
message (FATAL_ERROR "Python3_ARTIFACTS_INTERACTIVE=ON Failed.")
|
||||
endif()
|
||||
else()
|
||||
if (DEFINED CACHE{Python3_EXECUTABLE}
|
||||
OR DEFINED CACHE{Python3_LIBRARY} OR DEFINED CACHE{Python3_INCLUDE_DIR}
|
||||
OR (CMake_TEST_FindPython_NumPy AND DEFINED CACHE{Python3_NumPy_INCLUDE_DIR}))
|
||||
message (FATAL_ERROR "Python3_ARTIFACTS_INTERACTIVE=OFF Failed.")
|
||||
endif()
|
||||
endif()
|
||||
@@ -134,6 +134,35 @@ if(CMake_TEST_FindPython)
|
||||
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
|
||||
)
|
||||
|
||||
add_test(NAME FindPython.ArtifactsInteractive.ON COMMAND
|
||||
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
|
||||
--build-and-test
|
||||
"${CMake_SOURCE_DIR}/Tests/FindPython/ArtifactsInteractive"
|
||||
"${CMake_BINARY_DIR}/Tests/FindPython/ArtifactsInteractive.ON"
|
||||
${build_generator_args}
|
||||
--build-project TestArtifactsScope
|
||||
--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_NumPy=${CMake_TEST_FindPython_NumPy}"
|
||||
"-DPython3_ARTIFACTS_INTERACTIVE=ON"
|
||||
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
|
||||
)
|
||||
add_test(NAME FindPython.ArtifactsInteractive.OFF COMMAND
|
||||
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
|
||||
--build-and-test
|
||||
"${CMake_SOURCE_DIR}/Tests/FindPython/ArtifactsInteractive"
|
||||
"${CMake_BINARY_DIR}/Tests/FindPython/ArtifactsInteractive.OFF"
|
||||
${build_generator_args}
|
||||
--build-project TestArtifactsScope
|
||||
--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_NumPy=${CMake_TEST_FindPython_NumPy}"
|
||||
"-DPython3_ARTIFACTS_INTERACTIVE=OFF"
|
||||
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
|
||||
)
|
||||
|
||||
add_test(NAME FindPython.CustomFailureMessage COMMAND
|
||||
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
|
||||
--build-and-test
|
||||
|
||||
@@ -15,14 +15,14 @@ if (NOT Python3_FOUND)
|
||||
endif()
|
||||
|
||||
if(NOT TARGET Python3::Interpreter)
|
||||
message(SEND_ERROR "Python2::Interpreter not found")
|
||||
message(SEND_ERROR "Python3::Interpreter not found")
|
||||
endif()
|
||||
|
||||
if(NOT TARGET Python3::Python)
|
||||
message(SEND_ERROR "Python2::Python not found")
|
||||
message(SEND_ERROR "Python3::Python not found")
|
||||
endif()
|
||||
if(NOT TARGET Python3::Module)
|
||||
message(SEND_ERROR "Python2::Module not found")
|
||||
message(SEND_ERROR "Python3::Module not found")
|
||||
endif()
|
||||
|
||||
Python3_add_library (spam3 MODULE ../spam.c)
|
||||
|
||||
Reference in New Issue
Block a user