FindPython: cmake-3.16.0-rc2 fails in some case
When running cmake 3.15.4 and cmake 3.16.0-rc2 with following CMakeLists.txt, output variable behavior is different.
A cache variable Python_EXECUTABLE
is defined in 3.15.4 but it becomes normal variable in 3.16.0-rc2.
sample project
Here is a sample project that run well in 3.15 but fails in 3.16.
CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(findpythone LANGUAGES C)
add_subdirectory(src)
add_subdirectory(tests)
src/CMakeLists.txt
set(Python_FIND_STRATEGY LOCATION)
find_package(Python COMPONENTS Interpreter Development)
# making python binding...
tests/CMakeLists.txt
# test python binding
message("Python_EXECUTABLE: ${Python_EXECUTABLE}")
set(PYTHON_RUN_ENV "PYTHONPATH=/tmp")
add_custom_target(test COMMAND ${CMAKE_COMMAND} -E env ${PYTHON_RUN_ENV} ${Python_EXECUTABLE} -m pytest)
when run make test
on cmake 3.16, it fails with cmake -E env don't have a -m option because of Python_EXECUTABLE
is not defined in subdir tests
.
cmake -LA results
3.16.0-rc2
miurahr@miurahr-note:~/projects/cmake-findpython-case/build-3.16.0 (master)$ cmake --version
cmake version 3.16.0-rc2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
miurahr@miurahr-note:~/projects/cmake-findpython-case/build-3.16.0 (master)$ cmake -LA ..|grep -i python
-- Found Python: /usr/bin/python3.8 (found version "3.8.0") found components: Interpreter Development
OK
-- Build files have been written to: /home/miurahr/projects/cmake-findpython-case/build-3.16.0
Python_LIBRARY_DEBUG:FILEPATH=
Python_LIBRARY_RELEASE:FILEPATH=/usr/lib/x86_64-linux-gnu/libpython3.8.so
_Python_EXECUTABLE:FILEPATH=/usr/bin/python3.8
_Python_INCLUDE_DIR:PATH=/usr/include/python3.8
_Python_LIBRARY_RELEASE:FILEPATH=/usr/lib/x86_64-linux-gnu/libpython3.8.so
3.15.4
miurahr@miurahr-note:~/projects/cmake-findpython-case/build-3.15.4 (master)$ cmake -LA .. | grep -i python
-- Found Python: /usr/bin/python3.8 (found version "3.8.0") found components: Interpreter Development
OK
-- Build files have been written to: /home/miurahr/projects/cmake-findpython-case/build-3.15.4
Python_EXECUTABLE:FILEPATH=/usr/bin/python3.8
Python_INCLUDE_DIR:PATH=/usr/include/python3.8
Python_LIBRARY_DEBUG:FILEPATH=Python_LIBRARY_DEBUG-NOTFOUND
Python_LIBRARY_RELEASE:FILEPATH=/usr/lib/x86_64-linux-gnu/libpython3.8.so
Edited by Hiroshi Miura