From 29b7a9099d2ccf3ba483ef018712e0613f3eb24f Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Thu, 17 Aug 2023 18:23:33 +0200 Subject: [PATCH] Fix cmake warnings while searching for python There is a new find module since cmake 3.12. Cmake 3.27 will start emitting warnings if the old modules are still in use. Current implementation supports both. As soon as we can bump our minimal cmake version to 3.12, the old support code can be dropped as well. --- CMakeLists.txt | 26 ++++++++++++++++++-------- bindings/python/CMakeLists.txt | 14 +++++++------- bindings/python/tests/CMakeLists.txt | 2 +- common/test-core/CMakeLists.txt | 4 ++-- gnucash/python/CMakeLists.txt | 2 +- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2aa7e94641..edf26cd620 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -497,19 +497,29 @@ endif() if (WITH_PYTHON) set (PYTHON_MIN_VERSION 3.6.0) - find_package(PythonInterp ${PYTHON_MIN_VERSION}) - if (NOT PYTHONINTERP_FOUND) - message(SEND_ERROR "Python support enabled, but Python interpreter not found.") - endif() + if (CMAKE_VERSION GREATER_EQUAL 3.12.0) + find_package (Python3 ${PYTHON_MIN_VERSION} COMPONENTS Interpreter Development) + if (NOT Python3_FOUND) + message(SEND_ERROR "Python support enabled, but Python3 interpreter and/or libaries not found.") + endif() + else() + find_package(PythonInterp ${PYTHON_MIN_VERSION}) + if (NOT PYTHONINTERP_FOUND) + message(SEND_ERROR "Python support enabled, but Python interpreter not found.") + endif() - find_package(PythonLibs ${PYTHON_MIN_VERSION}) - if (NOT PYTHONLIBS_FOUND) - message(SEND_ERROR "Python support enabled, but Python libraries not found.") + find_package(PythonLibs ${PYTHON_MIN_VERSION}) + if (NOT PYTHONLIBS_FOUND) + message(SEND_ERROR "Python support enabled, but Python libraries not found.") + endif() + set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE}) + set(Python3_LIBRARIES ${PYTHON_LIBRARIES}) + set(Python3_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) endif() # Determine where to install the python libraries. execute_process( - COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(prefix='${CMAKE_INSTALL_PREFIX}', plat_specific=True))" + COMMAND ${Python3_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(prefix='${CMAKE_INSTALL_PREFIX}', plat_specific=True))" RESULT_VARIABLE PYTHON_SYSCONFIG_RESULT OUTPUT_VARIABLE PYTHON_SYSCONFIG_OUTPUT ERROR_VARIABLE PYTHON_SYSCONFIG_ERROR diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index 345ba5aeed..24a103a437 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -73,13 +73,13 @@ if(WITH_PYTHON) ${CMAKE_SOURCE_DIR}/libgnucash/app-utils ${CMAKE_SOURCE_DIR}/gnucash/gnome ${CMAKE_SOURCE_DIR}/libgnucash/core-utils - ${PYTHON_INCLUDE_DIRS} + ${Python3_INCLUDE_DIRS} ) add_library(gnucash_core_c MODULE ${SWIG_GNUCASH_CORE_C}) target_include_directories(gnucash_core_c PRIVATE ${gnucash_core_c_INCLUDE_DIRS}) - target_link_libraries(gnucash_core_c gnc-app-utils gnc-engine ${PYTHON_LIBRARIES}) + target_link_libraries(gnucash_core_c gnc-app-utils gnc-engine ${Python3_LIBRARIES}) set_target_properties(gnucash_core_c PROPERTIES PREFIX "_") target_compile_options(gnucash_core_c PRIVATE -Wno-implicit -Wno-missing-prototypes -Wno-declaration-after-statement -Wno-missing-declarations) if (HAVE_STRINGOP_TRUNCATION) @@ -87,7 +87,7 @@ if(WITH_PYTHON) endif() add_executable(sqlite3test EXCLUDE_FROM_ALL sqlite3test.c ${SWIG_GNUCASH_CORE_C}) - target_link_libraries(sqlite3test gnc-app-utils gnc-engine ${PYTHON_LIBRARIES}) + target_link_libraries(sqlite3test gnc-app-utils gnc-engine ${Python3_LIBRARIES}) target_include_directories(sqlite3test PRIVATE ${gnucash_core_c_INCLUDE_DIRS}) target_compile_options(sqlite3test PRIVATE -Wno-implicit -Wno-missing-prototypes -Wno-declaration-after-statement -Wno-missing-declarations) if (HAVE_STRINGOP_TRUNCATION) @@ -122,7 +122,7 @@ if(WITH_PYTHON) add_library (sw_core_utils MODULE ${SWIG_CORE_UTILS_PYTHON_C}) - target_link_libraries(sw_core_utils gnc-core-utils ${PYTHON_LIBRARIES}) + target_link_libraries(sw_core_utils gnc-core-utils ${Python3_LIBRARIES}) set_target_properties(sw_core_utils PROPERTIES PREFIX "_") if (HAVE_STRINGOP_TRUNCATION) @@ -131,7 +131,7 @@ if(WITH_PYTHON) target_include_directories (sw_core_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${PYTHON_INCLUDE_DIRS} + PRIVATE ${Python3_INCLUDE_DIRS} ) target_compile_definitions (sw_core_utils PRIVATE -DG_LOG_DOMAIN=\"gnc.core-utils\") @@ -156,7 +156,7 @@ if(WITH_PYTHON) set(PYEXEC_FILES sw_app_utils.py) add_library (sw_app_utils MODULE ${SWIG_APP_UTILS_PYTHON_C}) - target_link_libraries(sw_app_utils gnc-app-utils ${app_utils_ALL_LIBRARIES} ${PYTHON_LIBRARIES}) + target_link_libraries(sw_app_utils gnc-app-utils ${app_utils_ALL_LIBRARIES} ${Python3_LIBRARIES}) set_target_properties(sw_app_utils PROPERTIES PREFIX "_") if (HAVE_STRINGOP_TRUNCATION) target_compile_options(sw_app_utils PRIVATE -Wno-error=stringop-truncation) @@ -168,7 +168,7 @@ if(WITH_PYTHON) target_include_directories (sw_app_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${app_utils_ALL_INCLUDES} ${PYTHON_INCLUDE_DIRS} + PRIVATE ${app_utils_ALL_INCLUDES} ${Python3_INCLUDE_DIRS} ) target_compile_definitions (sw_app_utils PRIVATE -DG_LOG_DOMAIN=\"gnc.app-utils\") diff --git a/bindings/python/tests/CMakeLists.txt b/bindings/python/tests/CMakeLists.txt index ccf4d6a3e0..9ec9ca29a9 100644 --- a/bindings/python/tests/CMakeLists.txt +++ b/bindings/python/tests/CMakeLists.txt @@ -7,7 +7,7 @@ if (WITH_PYTHON) endif() add_custom_target(test-python-bindings ALL DEPENDS unittest_support gnucash-core-c-build gnucash-core-c-py sw-core-utils-build sw-core-utils-py sw-app-utils-build sw-app-utils-py) add_dependencies(check test-python-bindings) - add_test(python-bindings ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/runTests.py.in) + add_test(python-bindings ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/runTests.py.in) set_property(TEST python-bindings PROPERTY ENVIRONMENT GNC_BUILDDIR=${CMAKE_BINARY_DIR} PYTHONPATH=${PYTHON_SYSCONFIG_BUILD}:${LIBDIR_BUILD}/gnucash:${test_core_dir} diff --git a/common/test-core/CMakeLists.txt b/common/test-core/CMakeLists.txt index 7aabb95ea0..3ade6209e6 100644 --- a/common/test-core/CMakeLists.txt +++ b/common/test-core/CMakeLists.txt @@ -45,8 +45,8 @@ add_dependencies (test-core-guile swig-unittest-support-guile-c ) if (WITH_PYTHON) add_library(unittest_support MODULE ${SWIG_UNITTEST_SUPPORT_PYTHON_C}) - target_link_libraries(unittest_support test-core ${PYTHON_LIBRARIES}) - target_include_directories(unittest_support PRIVATE ${PYTHON_INCLUDE_DIRS}) + target_link_libraries(unittest_support test-core ${Python3_LIBRARIES}) + target_include_directories(unittest_support PRIVATE ${Python3_INCLUDE_DIRS}) set_target_properties(unittest_support PROPERTIES PREFIX "_") if (HAVE_STRINGOP_TRUNCATION) target_compile_options(unittest_support PRIVATE -Wno-error=stringop-truncation) diff --git a/gnucash/python/CMakeLists.txt b/gnucash/python/CMakeLists.txt index 5ca656c069..28de0658a9 100644 --- a/gnucash/python/CMakeLists.txt +++ b/gnucash/python/CMakeLists.txt @@ -15,7 +15,7 @@ if (WITH_PYTHON) add_library(gncmod-python ${gncmod_python_SOURCES}) # target_link_libraries(gncmod-python gnc-module gnc-core-utils-python gnc-app-utils-python target_link_libraries(gncmod-python gnc-module gnc-core-utils - ${PYTHON_LIBRARIES}) # ${PYTHON_EXTRA_LIBS} + ${Python3_LIBRARIES}) # ${PYTHON_EXTRA_LIBS} target_include_directories(gncmod-python PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/libgnucash/core-utils ${CMAKE_SOURCE_DIR}/gnc-module ${PYTHON_INCLUDE_DIR}) target_compile_options(gncmod-python PRIVATE -DG_LOG_DOMAIN=\"gnc.python\")