Skip to content

Commit

Permalink
Use FindPython3 CMake module instead of deprecated FindPythonLibs and…
Browse files Browse the repository at this point in the history
… FindPythonInterp
  • Loading branch information
o01eg committed Jan 3, 2024
1 parent ed72fa1 commit 85dca2c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
mkdir build
pushd build
FO_SDK=$(realpath ../..)
cmake -DANDROID_ABI=${{ matrix.arch }} -DANDROID_PLATFORM=24 -DANDROID_NDK=${{ steps.setup-ndk.outputs.ndk-path }} -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_TOOLCHAIN_FILE=${{ steps.setup-ndk.outputs.ndk-path }}/build/cmake/android.toolchain.cmake -DCMAKE_CXX_FLAGS=-std=c++14 -DANDROID_ALLOW_UNDEFINED_SYMBOLS=Off -DBUILD_SERVER=OFF -DBUILD_AI=OFF -DBUILD_CLIENT_GG=OFF -DBoost_INCLUDE_DIR=${FO_SDK}/include/ -DBoost_USE_STATIC_LIBS=On -DBoost_LIBRARY_DIR=${FO_SDK}/lib/ -DBUILD_CLIENT_GODOT=On -DICUI18N_LIBRARY=${FO_SDK}/lib/libicui18n.a -DICUUC_LIBRARY=${FO_SDK}/lib/libicuuc.a -DICUDATA_LIBRARY=${FO_SDK}/lib/libicudata.a -DICONV_LIBRARY=${FO_SDK}/lib/libiconv.so -DPYTHON_LIBRARY=${FO_SDK}/lib/libpython3.9.a -DPYTHON_INCLUDE_DIR=${FO_SDK}/include/python3.9/ -DGODOT_CUSTOM_API_FILE=${GODOT_API_JSON} ..
cmake -DANDROID_ABI=${{ matrix.arch }} -DANDROID_PLATFORM=24 -DANDROID_NDK=${{ steps.setup-ndk.outputs.ndk-path }} -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_TOOLCHAIN_FILE=${{ steps.setup-ndk.outputs.ndk-path }}/build/cmake/android.toolchain.cmake -DCMAKE_CXX_FLAGS=-std=c++14 -DANDROID_ALLOW_UNDEFINED_SYMBOLS=Off -DBUILD_SERVER=OFF -DBUILD_AI=OFF -DBUILD_CLIENT_GG=OFF -DBoost_INCLUDE_DIR=${FO_SDK}/include/ -DBoost_USE_STATIC_LIBS=On -DBoost_LIBRARY_DIR=${FO_SDK}/lib/ -DBUILD_CLIENT_GODOT=On -DICUI18N_LIBRARY=${FO_SDK}/lib/libicui18n.a -DICUUC_LIBRARY=${FO_SDK}/lib/libicuuc.a -DICUDATA_LIBRARY=${FO_SDK}/lib/libicudata.a -DICONV_LIBRARY=${FO_SDK}/lib/libiconv.so -DPython3_LIBRARY=${FO_SDK}/lib/libpython3.9.a -DPython3_INCLUDE_DIR=${FO_SDK}/include/python3.9/ -DGODOT_CUSTOM_API_FILE=${GODOT_API_JSON} ..
- name: Build
run: |
pushd build
Expand Down
34 changes: 20 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ message(STATUS "Build type CMAKE_BUILD_TYPE set to ${CMAKE_BUILD_TYPE}")
include(UseCompilerCache)
find_compiler_cache(PROGRAM ccache)

list(APPEND GODOT_CPP_CMAKE_VARS "CMAKE_BUILD_TYPE;CMAKE_CONFIGURATION_TYPES;CMAKE_TOOLCHAIN_FILE;PYTHON_EXECUTABLE")
list(APPEND GODOT_CPP_CMAKE_VARS "CMAKE_BUILD_TYPE;CMAKE_CONFIGURATION_TYPES;CMAKE_TOOLCHAIN_FILE;PYTHON_EXECUTABLE;Python3_EXECUTABLE")
get_cmake_property(vars CACHE_VARIABLES)
foreach(var ${vars})
get_property(currentHelpString CACHE "${var}" PROPERTY HELPSTRING)
Expand Down Expand Up @@ -124,8 +124,10 @@ if(APPLE)
set(CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/dep/")
set(CMAKE_FRAMEWORK_PATH "${CMAKE_BINARY_DIR}/dep/Frameworks")
set(CMAKE_PROGRAM_PATH "${CMAKE_FRAMEWORK_PATH}/Python.framework/Versions/3.7/bin")
set(CMAKE_FIND_FRAMEWORK "FIRST")
set(BOOST_ROOT "${CMAKE_BINARY_DIR}/dep/")
set(Boost_NO_SYSTEM_PATHS ON)
set(Python3_FIND_STRATEGY "LOCATION")
endif()

if(UNIX)
Expand Down Expand Up @@ -261,10 +263,14 @@ set(MINIMUM_PYTHON_VERSION 3.7)
set(MINIMUM_BOOST_VERSION 1.69.0)

find_package(Threads)
find_package(PythonInterp ${MINIMUM_PYTHON_VERSION} REQUIRED)
find_package(PythonLibs ${MINIMUM_PYTHON_VERSION} REQUIRED)
message(STATUS "Python library version detected ${PYTHONLIBS_VERSION_STRING}")
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\..*" "\\1\\2" Boost_PYTHON_SUFFIX "${PYTHONLIBS_VERSION_STRING}")
if(ANDROID)
find_package(Python3 ${MINIMUM_PYTHON_VERSION} COMPONENTS Interpreter REQUIRED)
find_package(Python3 ${MINIMUM_PYTHON_VERSION} COMPONENTS Development REQUIRED)
else()
find_package(Python3 ${MINIMUM_PYTHON_VERSION} COMPONENTS Interpreter Development REQUIRED)
endif()
message(STATUS "Python library version detected ${Python3_VERSION}")
set(Boost_PYTHON_SUFFIX "${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}")
message(STATUS "Boost python version ${Boost_PYTHON_SUFFIX}")
find_package(Boost ${MINIMUM_BOOST_VERSION}
COMPONENTS
Expand Down Expand Up @@ -359,7 +365,7 @@ set_property(DIRECTORY APPEND
# execution to a separate target and the existing python command
execute_process(
COMMAND
"${PYTHON_EXECUTABLE}"
"${Python3_EXECUTABLE}"
"${CMAKE_SOURCE_DIR}/cmake/make_versioncpp.py"
"${CMAKE_SOURCE_DIR}"
"CMake"
Expand Down Expand Up @@ -422,7 +428,7 @@ target_compile_definitions(freeorioncommon

target_include_directories(freeorioncommon SYSTEM
PUBLIC
${PYTHON_INCLUDE_PATH}
${Python3_INCLUDE_DIRS}
)

target_link_libraries(freeorioncommon
Expand All @@ -439,7 +445,7 @@ target_link_libraries(freeorioncommon
Boost::python${Boost_PYTHON_SUFFIX}
Boost::thread
Boost::serialization
${PYTHON_LIBRARIES}
${Python3_LIBRARIES}
ZLIB::ZLIB
${ICUI18N_LIBRARY}
${ICUUC_LIBRARY}
Expand Down Expand Up @@ -474,7 +480,7 @@ target_compile_definitions(freeorionparseobj
target_include_directories(freeorionparseobj
PUBLIC
$<TARGET_PROPERTY:Boost::boost,INTERFACE_INCLUDE_DIRECTORIES>
${PYTHON_INCLUDE_PATH}
${Python3_INCLUDE_DIRS}
)

set_property(TARGET freeorionparseobj
Expand Down Expand Up @@ -644,7 +650,7 @@ if(BUILD_CLIENT_GG)
# at configuration time.
execute_process(
COMMAND
"${PYTHON_EXECUTABLE}"
"${Python3_EXECUTABLE}"
"${CMAKE_SOURCE_DIR}/cmake/make_versioncpp.py"
"${CMAKE_SOURCE_DIR}"
"CMake"
Expand Down Expand Up @@ -715,8 +721,8 @@ if(BUILD_CLIENT_GODOT)
-D CMAKE_BUILD_TYPE=${GODOT_CPP_BUILD_TYPE}
-D CMAKE_CONFIGURATION_TYPES=${GODOT_CPP_BUILD_TYPE}
-D CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-D PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
-D Python3_EXECUTABLE=${PYTHON_EXECUTABLE}
-D PYTHON_EXECUTABLE=${Python3_EXECUTABLE}
-D Python3_EXECUTABLE=${Python3_EXECUTABLE}
${CL_ARGS}
INSTALL_COMMAND ""
)
Expand Down Expand Up @@ -786,9 +792,9 @@ endif()
if(WIN32 AND BUILD_CLIENT_GG)
add_custom_command(TARGET freeorion POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy_if_different "${CMAKE_PREFIX_PATH}/bin/python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}.dll" "$<TARGET_FILE_DIR:freeorion>"
${CMAKE_COMMAND} -E copy_if_different "${CMAKE_PREFIX_PATH}/bin/python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}.dll" "$<TARGET_FILE_DIR:freeorion>"
COMMAND
${CMAKE_COMMAND} -E copy_if_different "${CMAKE_PREFIX_PATH}/bin/python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}.zip" "$<TARGET_FILE_DIR:freeorion>"
${CMAKE_COMMAND} -E copy_if_different "${CMAKE_PREFIX_PATH}/bin/python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}.zip" "$<TARGET_FILE_DIR:freeorion>"
)
endif()

Expand Down

0 comments on commit 85dca2c

Please sign in to comment.