diff --git a/CMakeLists.txt b/CMakeLists.txt index 63da430d..551c11b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,9 +172,42 @@ if(WANT_PERL) endif() if (WANT_PYTHON) find_package(Perl 5.10 REQUIRED) - pkg_check_modules(PYTHON "${WANT_PYTHON_VERSION}-embed") - if (NOT PYTHON_FOUND) - pkg_check_modules(PYTHON "${WANT_PYTHON_VERSION}" REQUIRED) + # VERSION_GREATER_EQUAL is available only since 3.7 + if (CMAKE_VERSION VERSION_LESS 3.12) + else() + # Even if FindPython3 is available (since CMake 3.12) we still use + # pkg-config, because FindPython has a hardcoded list of python + # versions, which may become outdated when new pythons are released, + # but when cmake in the distro is old. + # + # Why FindPython3 is useful at all? Because sometimes there is no + # python3.pc, but only python-3.5.pc and python-3.6.pc; which would + # force user to provide the version explicitly via + # WANT_PYTHON_VERSION. This is the case on Gentoo when NOT building + # via emerge. + if (WANT_PYTHON_VERSION STREQUAL "python3") + find_package(Python3 COMPONENTS Development) + else() + # We used to pass value like "python-3.5" to the variable. + if (WANT_PYTHON_VERSION MATCHES "^(python-)?(.*)$") + find_package(Python3 COMPONENTS Development + EXACT "${CMAKE_MATCH_2}") + else() + message(FATAL_ERROR "Invalid value of WANT_PYTHON_VERSION") + endif() + endif() + # Compatibility with pkg-config variables + set(Python3_LDFLAGS "${Python3_LIBRARIES}") + endif() + if (NOT Python3_FOUND AND WANT_PYTHON_VERSION MATCHES "^python") + # Since python 3.8, -embed is required for embedding. + pkg_check_modules(Python3 "${WANT_PYTHON_VERSION}-embed >= 3.0") + if (NOT Python3_FOUND) + pkg_check_modules(Python3 "${WANT_PYTHON_VERSION} >= 3.0") + endif() + endif() + if (NOT Python3_FOUND) + message(FATAL_ERROR "Python 3 is not found. Try disabling it.") endif() endif() @@ -361,7 +394,7 @@ summary_line("SSL " "${OPENSSL_FOUND}") summary_line("IPv6 " "${WANT_IPV6}") summary_line("Async DNS" "${HAVE_THREADED_DNS}") summary_line("Perl " "${PERLLIBS_FOUND}") -summary_line("Python " "${PYTHON_FOUND}") +summary_line("Python " "${Python3_FOUND}") summary_line("Tcl " "${TCL_FOUND}") summary_line("Cyrus " "${CYRUS_FOUND}") summary_line("Charset " "${ICU_FOUND}") diff --git a/cmake/use_homebrew.cmake b/cmake/use_homebrew.cmake index f58c1542..bb59317b 100644 --- a/cmake/use_homebrew.cmake +++ b/cmake/use_homebrew.cmake @@ -50,7 +50,7 @@ execute_process(COMMAND "${brew}" --prefix python3 if(brew_python_f EQUAL 0) find_package_message(brew_python "Python via Homebrew: ${brew_python}" "${brew_python}") - list(APPEND Python_FRAMEWORKS_ADDITIONAL + list(APPEND Python3_FRAMEWORKS_ADDITIONAL "${brew_python}/Frameworks/Python.framework") endif() diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 50921c7b..7f4d6b57 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -66,7 +66,7 @@ else() set(moddisable_modperl true) endif() -if(PYTHON_FOUND) +if(Python3_FOUND) add_subdirectory(modpython) else() set(moddisable_modpython true) diff --git a/modules/modpython/CMakeLists.txt b/modules/modpython/CMakeLists.txt index 3a59ed75..ed715eda 100644 --- a/modules/modpython/CMakeLists.txt +++ b/modules/modpython/CMakeLists.txt @@ -17,9 +17,9 @@ # TODO: consider switching to swig_add_library() after bumping CMake # requirements to 3.8, when that command started using IMPLICIT_DEPENDS -set(modinclude_modpython PUBLIC ${PYTHON_INCLUDE_DIRS} +set(modinclude_modpython PUBLIC ${Python3_INCLUDE_DIRS} "${CMAKE_CURRENT_BINARY_DIR}/.." PARENT_SCOPE) -set(modlink_modpython PUBLIC ${PYTHON_LDFLAGS} PARENT_SCOPE) +set(modlink_modpython PUBLIC ${Python3_LDFLAGS} PARENT_SCOPE) set(moddef_modpython PUBLIC "SWIG_TYPE_TABLE=znc" PARENT_SCOPE) set(moddepend_modpython modpython_functions modpython_swigruntime PARENT_SCOPE) @@ -75,8 +75,8 @@ target_include_directories(modpython_lib PRIVATE "${PROJECT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/.." "${CMAKE_CURRENT_SOURCE_DIR}/.." - ${PYTHON_INCLUDE_DIRS}) -target_link_libraries(modpython_lib ${znc_link} ${PYTHON_LDFLAGS}) + ${Python3_INCLUDE_DIRS}) +target_link_libraries(modpython_lib ${znc_link} ${Python3_LDFLAGS}) set_target_properties(modpython_lib PROPERTIES PREFIX "_" OUTPUT_NAME "znc_core"