FindPython: Add possibility to control scope of artifacts.

Fixes: #20362
This commit is contained in:
Marc Chevrier
2020-03-02 17:45:25 +01:00
parent 07a7bc0e3f
commit e5b4c74238
8 changed files with 138 additions and 16 deletions

View File

@@ -0,0 +1,6 @@
FindPython-artifacts-interactive
--------------------------------
* The :module:`FindPython3`, :module:`FindPython2` and :module:`FindPython`
modules gained the possibility to create artifacts cache variables for
interactive edition.

View File

@@ -288,6 +288,22 @@ setting the following variables:
If more than one artifact is specified, it is the user's responsability to
ensure the consistency of the various artifacts.
By default, this module supports multiple calls in different directories of a
project with different version/component requirements while providing correct
and consistent results for each call. To support this behavior, ``CMake`` cache
is not used in the traditional way which can be problematic for interactive
specification. So, to enable also interactive specification, module behavior
can be controled with the following variable:
``Python_ARTIFACTS_INTERACTIVE``
Selects the behavior of the module. This is a boolean variable:
* If set to ``TRUE``: Create CMake cache entries for the above artifact
specification variables so that users can edit them interactively.
This disables support for multiple version/component requirements.
* If set to ``FALSE`` or undefined: Enable multiple version/component
requirements.
Commands
^^^^^^^^

View File

@@ -75,22 +75,20 @@ macro (_PYTHON_SELECT_LIBRARY_CONFIGURATIONS _PYTHON_BASENAME)
(_PYTHON_isMultiConfig OR CMAKE_BUILD_TYPE))
# if the generator is multi-config or if CMAKE_BUILD_TYPE is set for
# single-config generators, set optimized and debug libraries
set (${_PYTHON_BASENAME}_LIBRARY "")
foreach (_PYTHON_libname IN LISTS ${_PYTHON_BASENAME}_LIBRARY_RELEASE )
list( APPEND ${_PYTHON_BASENAME}_LIBRARY optimized "${_PYTHON_libname}" )
set (${_PYTHON_BASENAME}_LIBRARIES "")
foreach (_PYTHON_libname IN LISTS ${_PYTHON_BASENAME}_LIBRARY_RELEASE)
list( APPEND ${_PYTHON_BASENAME}_LIBRARIES optimized "${_PYTHON_libname}")
endforeach()
foreach (_PYTHON_libname IN LISTS ${_PYTHON_BASENAME}_LIBRARY_DEBUG )
list( APPEND ${_PYTHON_BASENAME}_LIBRARY debug "${_PYTHON_libname}" )
foreach (_PYTHON_libname IN LISTS ${_PYTHON_BASENAME}_LIBRARY_DEBUG)
list( APPEND ${_PYTHON_BASENAME}_LIBRARIES debug "${_PYTHON_libname}")
endforeach()
elseif (${_PYTHON_BASENAME}_LIBRARY_RELEASE)
set (${_PYTHON_BASENAME}_LIBRARY "${${_PYTHON_BASENAME}_LIBRARY_RELEASE}")
set (${_PYTHON_BASENAME}_LIBRARIES "${${_PYTHON_BASENAME}_LIBRARY_RELEASE}")
elseif (${_PYTHON_BASENAME}_LIBRARY_DEBUG)
set (${_PYTHON_BASENAME}_LIBRARY "${${_PYTHON_BASENAME}_LIBRARY_DEBUG}")
set (${_PYTHON_BASENAME}_LIBRARIES "${${_PYTHON_BASENAME}_LIBRARY_DEBUG}")
else()
set (${_PYTHON_BASENAME}_LIBRARY "${_PYTHON_BASENAME}_LIBRARY-NOTFOUND")
set (${_PYTHON_BASENAME}_LIBRARIES "${_PYTHON_BASENAME}_LIBRARY-NOTFOUND")
endif()
set (${_PYTHON_BASENAME}_LIBRARIES "${${_PYTHON_BASENAME}_LIBRARY}")
endmacro()
@@ -1412,6 +1410,10 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
endif()
endif()
if (${_PYTHON_PREFIX}_ARTIFACTS_INTERACTIVE)
set (${_PYTHON_PREFIX}_EXECUTABLE "${_${_PYTHON_PREFIX}_EXECUTABLE}" CACHE FILEPATH "${_PYTHON_PREFIX} Interpreter")
endif()
_python_mark_as_internal (_${_PYTHON_PREFIX}_EXECUTABLE
_${_PYTHON_PREFIX}_INTERPRETER_PROPERTIES
_${_PYTHON_PREFIX}_INTERPRETER_SIGNATURE)
@@ -1607,6 +1609,10 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS)
unset (${_PYTHON_PREFIX}_COMPILER_ID)
endif()
if (${_PYTHON_PREFIX}_ARTIFACTS_INTERACTIVE)
set (${_PYTHON_PREFIX}_COMPILER "${_${_PYTHON_PREFIX}_COMPILER}" CACHE FILEPATH "${_PYTHON_PREFIX} Compiler")
endif()
_python_mark_as_internal (_${_PYTHON_PREFIX}_COMPILER
_${_PYTHON_PREFIX}_COMPILER_SIGNATURE)
endif()
@@ -2298,6 +2304,11 @@ if ("Development" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
set (CMAKE_FIND_LIBRARY_SUFFIXES ${_${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
if (${_PYTHON_PREFIX}_ARTIFACTS_INTERACTIVE)
set (${_PYTHON_PREFIX}_LIBRARY "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" CACHE FILEPATH "${_PYTHON_PREFIX} Library")
set (${_PYTHON_PREFIX}_INCLUDE_DIR "${_${_PYTHON_PREFIX}_INCLUDE_DIR}" CACHE FILEPATH "${_PYTHON_PREFIX} Include Directory")
endif()
_python_mark_as_internal (_${_PYTHON_PREFIX}_LIBRARY_RELEASE
_${_PYTHON_PREFIX}_LIBRARY_DEBUG
_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE
@@ -2376,6 +2387,10 @@ if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS AND ${_PYTHON_PREFIX}_Inte
unset (_${_PYTHON_PREFIX}_NUMPY_SIGNATURE CACHE)
endif()
if (${_PYTHON_PREFIX}_ARTIFACTS_INTERACTIVE)
set (${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR "${_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR}" CACHE FILEPATH "${_PYTHON_PREFIX} NumPy Include Directory")
endif()
_python_mark_as_internal (_${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR
_${_PYTHON_PREFIX}_NUMPY_SIGNATURE)
endif()
@@ -2451,8 +2466,8 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT")
else()
set_target_properties (${__name}
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_IMPLIB "${${_PYTHON_PREFIX}_LIBRARY}"
IMPORTED_LOCATION "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY}")
IMPORTED_IMPLIB "${${_PYTHON_PREFIX}_LIBRARIES}"
IMPORTED_LOCATION "${${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE}")
endif()
else()
if (${_PYTHON_PREFIX}_LIBRARY_RELEASE AND ${_PYTHON_PREFIX}_LIBRARY_DEBUG)
@@ -2466,7 +2481,7 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT")
else()
set_target_properties (${__name}
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${${_PYTHON_PREFIX}_LIBRARY}")
IMPORTED_LOCATION "${${_PYTHON_PREFIX}_LIBRARY_RELEASE}")
endif()
endif()

View File

@@ -237,6 +237,22 @@ setting the following variables:
If more than one artifact is specified, it is the user's responsability to
ensure the consistency of the various artifacts.
By default, this module supports multiple calls in different directories of a
project with different version/component requirements while providing correct
and consistent results for each call. To support this behavior, ``CMake`` cache
is not used in the traditional way which can be problematic for interactive
specification. So, to enable also interactive specification, module behavior
can be controled with the following variable:
``Python2_ARTIFACTS_INTERACTIVE``
Selects the behavior of the module. This is a boolean variable:
* If set to ``TRUE``: Create CMake cache entries for the above artifact
specification variables so that users can edit them interactively.
This disables support for multiple version/component requirements.
* If set to ``FALSE`` or undefined: Enable multiple version/component
requirements.
Commands
^^^^^^^^

View File

@@ -285,6 +285,22 @@ setting the following variables:
If more than one artifact is specified, it is the user's responsability to
ensure the consistency of the various artifacts.
By default, this module supports multiple calls in different directories of a
project with different version/component requirements while providing correct
and consistent results for each call. To support this behavior, ``CMake`` cache
is not used in the traditional way which can be problematic for interactive
specification. So, to enable also interactive specification, module behavior
can be controled with the following variable:
``Python3_ARTIFACTS_INTERACTIVE``
Selects the behavior of the module. This is a boolean variable:
* If set to ``TRUE``: Create CMake cache entries for the above artifact
specification variables so that users can edit them interactively.
This disables support for multiple version/component requirements.
* If set to ``FALSE`` or undefined: Enable multiple version/component
requirements.
Commands
^^^^^^^^

View File

@@ -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()

View File

@@ -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

View File

@@ -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)