I have some project which supposed to support Win32
and x64
platform. Some code is generated by python script. This script uses python3
features.
In CMakeLists.txt
I have something like this:
find_package(PythonInterp REQUIRED)
if (CMAKE_CL_64)
set(MY_APP_PLATFORM "x64")
else()
set(MY_APP_PLATFORM "Win32")
endif()
add_custom_command(TARGET MyApp
PRE_BUILD
COMMAND ${PYTHON_EXECUTABLE} ${MyApp_ROOT}/generator.py -p ${MY_APP_PLATFORM }
WORKING_DIRECTORY ${PATH_GENERATED_SRC}
COMMENT "Generating code..."
VERBATIM
)
Quite simple.
Now when project for x64
is used everything works like a charm, but when building for Win32
(cmake have to generate separate project) cmake
finds python 2.7.2
.
Changing CMakeLists.txt
this way:
find_package(PythonInterp 3.7 REQUIRED)
Leads to cmake failure.
Is there way to fix it, or do I have to correct pythons script to be python2
compatible?
Or do I have to install python3
for 32 and 64 bits to cover both platforms?
The CMake Module is FindPython3.cmake
in your cmake distribution.
This should work:
find_package(Python3 COMPONENTS Interpreter)
add_custom_command(TARGET MyApp
PRE_BUILD
COMMAND ${PYTHON3_EXECUTABLE} ${MyApp_ROOT}/generator.py -p ${MY_APP_PLATFORM}
WORKING_DIRECTORY ${PATH_GENERATED_SRC}
COMMENT "Generating code..."
VERBATIM
)
It is available since cmake 3.12
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.