From fa79f69be921cc884d75149bc060a7555acdaa24 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sat, 27 May 2017 23:41:09 +0100 Subject: [PATCH] CMake: use pkg-config to find python. Makes it easier to override its path. --- CMakeLists.txt | 11 ++++------- configure.sh | 4 +--- modules/CMakeLists.txt | 2 +- modules/modpython/CMakeLists.txt | 4 ++-- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 94fa8b2f..079b2335 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,7 +129,8 @@ set(HAVE_ICU "${ICU_FOUND}") set(WANT_PERL false CACHE BOOL "Support Perl modules") set(WANT_PYTHON false CACHE BOOL "Support Python modules") -set(WANT_PYTHON_VERSION "" CACHE STRING "Python version to use, or empty") +set(WANT_PYTHON_VERSION "python3" CACHE STRING + "Python version to use, e.g. python-3.5, this name is passed to pkg-config") if(WANT_PYTHON AND NOT ICU_FOUND) message(FATAL_ERROR "Modpython requires ZNC to be compiled with charset " "support, but ICU library not found") @@ -171,11 +172,7 @@ if(WANT_PERL) endif() if (WANT_PYTHON) find_package(Perl 5.10 REQUIRED) - if(WANT_PYTHON_VERSION) - find_package(PythonLibs "${WANT_PYTHON_VERSION}" EXACT REQUIRED) - else() - find_package(PythonLibs 3 REQUIRED) - endif() + pkg_check_modules(PYTHON "${WANT_PYTHON_VERSION}" REQUIRED) endif() set(WANT_TCL false CACHE BOOL "Support Tcl modules") @@ -345,7 +342,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 " "${PYTHONLIBS_FOUND}") +summary_line("Python " "${PYTHON_FOUND}") summary_line("Tcl " "${TCL_FOUND}") summary_line("Cyrus " "${CYRUS_FOUND}") summary_line("Charset " "${ICU_FOUND}") diff --git a/configure.sh b/configure.sh index 5ee169be..097c0597 100755 --- a/configure.sh +++ b/configure.sh @@ -88,9 +88,7 @@ class HandlePython(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): extra_args.append('-DWANT_PYTHON=YES') if values is not None: - x = re.search(r'\d.*', values) - if x: - extra_args.append('-DWANT_PYTHON_VERSION=' + x.group(0)) + extra_args.append('-DWANT_PYTHON_VERSION=' + values) group = parser.add_mutually_exclusive_group() group.add_argument('--enable-python', action=HandlePython, nargs='?', diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index ef7a860e..5307c5e4 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -67,7 +67,7 @@ else() set(moddisable_modperl true) endif() -if(PYTHONLIBS_FOUND) +if(PYTHON_FOUND) add_subdirectory(modpython) else() set(moddisable_modpython true) diff --git a/modules/modpython/CMakeLists.txt b/modules/modpython/CMakeLists.txt index 9e066d2e..f0e2c31c 100644 --- a/modules/modpython/CMakeLists.txt +++ b/modules/modpython/CMakeLists.txt @@ -19,7 +19,7 @@ set(modinclude_modpython PUBLIC ${PYTHON_INCLUDE_DIRS} "${CMAKE_CURRENT_BINARY_DIR}/.." PARENT_SCOPE) -set(modlink_modpython PUBLIC ${PYTHON_LIBRARIES} PARENT_SCOPE) +set(modlink_modpython PUBLIC ${PYTHON_LDFLAGS} PARENT_SCOPE) set(moddef_modpython PUBLIC "SWIG_TYPE_TABLE=znc" PARENT_SCOPE) set(moddepend_modpython modpython_functions modpython_swigruntime PARENT_SCOPE) @@ -76,7 +76,7 @@ target_include_directories(modpython_lib PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/.." "${CMAKE_CURRENT_SOURCE_DIR}/.." ${PYTHON_INCLUDE_DIRS}) -target_link_libraries(modpython_lib ${znc_link} ${PYTHON_LIBRARIES}) +target_link_libraries(modpython_lib ${znc_link} ${PYTHON_LDFLAGS}) set_target_properties(modpython_lib PROPERTIES PREFIX "_" OUTPUT_NAME "znc_core"