在迁移到CMake 3.17.3(从3.13.3)时,我们偶然发现了Python的一个问题。在根目录CMakeLists.txt
中,我们现在有:
find_package(Python3 REQUIRED COMPONENTS Interpreter)
但是,这在以下情况下失败:
CMake Error at /home/abadura/cmake/cmake-3.17.3-Linux-x86_64/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
Could NOT find Python3 (missing: Python3_EXECUTABLE Interpreter)
Reason given by package:
Interpreter: Wrong major version for the interpreter "/build/ltesdkroot/Platforms/LINUX/MB_PS_LFS_REL_2020_07_0068/sdk/bld-tools/x86_64-pc-linux-gnu/bin/python"
Call Stack (most recent call first):
/home/abadura/cmake/cmake-3.17.3-Linux-x86_64/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
/home/abadura/cmake/cmake-3.17.3-Linux-x86_64/share/cmake-3.17/Modules/FindPython/Support.cmake:2437 (find_package_handle_standard_args)
/home/abadura/cmake/cmake-3.17.3-Linux-x86_64/share/cmake-3.17/Modules/FindPython3.cmake:309 (include)
CMakeLists.txt:20 (find_package)
而Python发现(/build/ltesdkroot/Platforms/LINUX/MB_PS_LFS_REL_2020_07_0068/sdk/bld-tools/x86_64-pc-linux-gnu/bin/python
)报告版本Python 2.7.15+
通过搜索和实验,我发现添加:
set(Python3_FIND_STRATEGY VERSION)
在find_package
帮助之前。通过此添加的Python,可以找到:
-- Found Python3: /opt/python/x86_64/3.6.0/bin-wrapped/python3.6 (found version "3.6.0") found components: Interpreter
现在,问题是FindPython3 documentation陈述了以下内容:
Python3_FIND_STRATEGY
This variable defines how lookup will be done. The
Python3_FIND_STRATEGY
variable can be set to one of the following:
因此,基于我对描述的理解,LOCATION
应该可以正常工作。它应该忽略/build/ltesdkroot/Platforms/LINUX/MB_PS_LFS_REL_2020_07_0068/sdk/bld-tools/x86_64-pc-linux-gnu/bin/python
,因为它不满足版本约束(它是python2而不是pytho3),并且应该继续查找满足约束的/opt/python/x86_64/3.6.0/bin-wrapped/python3.6
。(为了完整性,我尝试在find_package
中添加显式的3.6
版本,但它没有改变任何东西。)
另一个问题是我应该设置Python3_FIND_STRATEGY
还是直接使用CMP0094。{a2}文档有一个有点可怕的警告:
Note The
OLD
behavior of a policy is deprecated by definition and may be removed in a future version of CMake.
因此,我不确定哪种方法(为CMP0094设置Python3_FIND_STRATEGY
或激活OLD
)是理想的(稳定的)方法
目前没有回答
相关问题 更多 >
编程相关推荐