i have the problem that i’ve build cpython on my own in /home/stuv/build/cpython and i set CMAKE_PREFIX_PATH to this path but when i try
find_package(
Python3
REQUIRED VERSION 3.13
COMPONENTS Development
)
he tells me he can only find the version 3.11 which is the system installed one. is there a way i can tell cmake which version i wold prefer or why he doesn’t he find my version from the build dir ?
i’ve done so now with --prefix and put the builded version into /home/user/build/python3.13 and my code looks like:
cmake_minimum_required(VERSION 3.5)
project(TestPython)
i now get the output:
CMake Error at /usr/local/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Python3 (missing: PATH /home/stuv/build/python3.13) (found
suitable version “3.13.0”, minimum required is “3.13.0”)
Call Stack (most recent call first):
/usr/local/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
/usr/local/share/cmake-3.28/Modules/FindPython/Support.cmake:3867 (find_package_handle_standard_args)
/usr/local/share/cmake-3.28/Modules/FindPython3.cmake:545 (include)
CMakeLists.txt:56 (find_package)
so it looks like he can find the version but has some othe trouble, i set Python_DIR to /home/user/build/python3.13
CMake functions establish a variable scope. When you modify CMAKE_PREFIX_PATH inside a function, the modification will not propagate outside the function. See Introduction to list() command for details and possible solutions.
And nothing in the docs suggests that it should. Quoting the docs I linked:
To propagate the results of these operations upwards, use set() with PARENT_SCOPE, set() with CACHE INTERNAL, or some other means of value propagation.
Indeed. block() introduces its own scope, as does the function. So your code propagates the variables out of the block into the enclosing scope, which is the function. You need to do the modifications such that they propagate outside of the function.
PARENT_SCOPE is weird[1]. For a function like that, I would recommend removing PARENT_SCOPE and just using a macro instead.
[1] The detail that you’re missing (and it’s a silly behavior, but it’s what we have) is that the local variable of the same name is pulled from the parent scope. So you set your variable there, but here the value is still “undefined”, so when you try to set up CMAKE_PREFIX_PATH, the element variables you’re using are empty.