summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorDonovan Baarda <abo@minkirri.apana.org.au>2020-05-19 00:23:41 +1000
committerDonovan Baarda <abo@minkirri.apana.org.au>2020-05-19 00:23:41 +1000
commit53dc379999a59cbf182b712ff277df6950828df7 (patch)
treebf1989b0a34ec15d06f485b9c5fa1a87ce7aa9d4 /cmake
parentb005057cad7a623dc246d341ab7a1e939296c10a (diff)
downloadlibrsync-53dc379999a59cbf182b712ff277df6950828df7.tar.gz
Fix cmake/FindPOPT.cmake use PkgConfig correctly.
This fixes the cmake popt detection on (at least) FreeBSD. It mostly worked by accident on other platforms like Debian because of standardized install locations aligning with our miss-used output vars. In CMakeLists.txt bump cmake_minimum_required to 3.6 for a working version of pkg_search_module() with IMPORTED_TARGET support. The version on our travis xenial test platform is 3.12.4, so 3.6 is rather old. Fix BZIP2 detection to use the correct BZIP2_INCLUDE_DIRS var. Add POPT status messages to match other find_package() handling. Remove redundant "Found..." messages from all find_package() handling. In cmake/FindPOPT.cmake use pkg_search_module() IMPORTED_TARGET support to create a PkgConfig::POPT target and use it, following instructions found here; https://stackoverflow.com/questions/29191855/what-is-the-proper-way-to-use-pkg-config-from-cmake Follow a pattern from official FindPackage modules of using cached vars POPT_LIBRARY_RELEASE/POPT_IMPORT_DIR to set uncached vars POPT_LIBRARIES/POPT_IMPORT_DIRS. This makes it behave almost exactly like offical FindPackage modules. In cmake/Findlibb2.cmake update it to also use the more standard cached/uncached vars pattern.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/FindPOPT.cmake105
-rw-r--r--cmake/Findlibb2.cmake18
2 files changed, 57 insertions, 66 deletions
diff --git a/cmake/FindPOPT.cmake b/cmake/FindPOPT.cmake
index a37a907..3373344 100644
--- a/cmake/FindPOPT.cmake
+++ b/cmake/FindPOPT.cmake
@@ -1,4 +1,3 @@
-
#--------------------------------------------------------------------------------
# Copyright (C) 2012-2013, Lars Baehren <lbaehren@gmail.com>
# Copyright (C) 2015 Adam Schubert <adam.schubert@sg1-game.net>
@@ -27,72 +26,54 @@
# - Check for the presence of POPT
#
+# The following vars can be set to change behaviour;
+# POPT_ROOT_DIR - path hint for finding popt.
+# POPT_INCLUDE_DIR - cached override for POPT_INCLUDE_DIRS.
+# POPT_LIBRARY_RELEASE - cached override for POPT_LIBRARIES.
+#
# The following variables are set when POPT is found:
# POPT_FOUND = Set to true, if all components of POPT have been found.
-# POPT_INCLUDE_DIRS = Include path for the header files of POPT
-# POPT_LIBRARIES = Link these to use POPT
-# POPT_LFLAGS = Linker flags (optional)
+# POPT_INCLUDE_DIRS = Include path for the header files of POPT.
+# POPT_LIBRARIES = Link these to use POPT.
+# Check with PkgConfig (to retrieve static dependencies such as iconv)
+find_package(PkgConfig)
+if (PKG_CONFIG_FOUND)
+ pkg_search_module (POPT QUIET IMPORTED_TARGET poptd)
+ if (POPT_FOUND)
+ # PkgConfig found it, set cached vars to use the imported target it created.
+ set(POPT_INCLUDE_DIR "" CACHE PATH "Path to headers for popt.")
+ set(POPT_LIBRARY_RELEASE PkgConfig::POPT CACHE FILEPATH "Path to library for popt.")
+ endif (POPT_FOUND)
+endif (PKG_CONFIG_FOUND)
-INCLUDE(FindPackageHandleStandardArgs)
+# Fallback to searching for path and library if PkgConfig didn't work.
if (NOT POPT_FOUND)
+ find_path (POPT_INCLUDE_DIR popt.h
+ HINTS ${POPT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX} $ENV{programfiles}\\GnuWin32 $ENV{programfiles32}\\GnuWin32
+ PATH_SUFFIXES include)
+ find_library (POPT_LIBRARY_RELEASE popt
+ HINTS ${POPT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX} $ENV{programfiles}\\GnuWin32 $ENV{programfiles32}\\GnuWin32
+ PATH_SUFFIXES lib)
+endif (NOT POPT_FOUND)
- if (NOT POPT_ROOT_DIR)
- set (POPT_ROOT_DIR ${CMAKE_INSTALL_PREFIX})
- endif (NOT POPT_ROOT_DIR)
-
- ##_____________________________________________________________________________
- ## Check with PkgConfig (to retrieve static dependencies such as iconv)
- find_package(PkgConfig QUIET)
- if (PKG_CONFIG_FOUND)
- pkg_search_module (POPT QUIET popt)
- endif (PKG_CONFIG_FOUND)
-
- ##_____________________________________________________________________________
- ## Fallback to searching if PkgConfig didn't work.
- if (NOT POPT_FOUND)
-
- ##_____________________________________________________________________________
- ## Check for the header files
- find_path (POPT_INCLUDE_DIRS popt.h
- HINTS ${POPT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX} $ENV{programfiles}\\GnuWin32 $ENV{programfiles32}\\GnuWin32
- PATH_SUFFIXES include
- )
-
- ##_____________________________________________________________________________
- ## Check for the library
- find_library (POPT_LIBRARIES popt
- HINTS ${POPT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX} $ENV{programfiles}\\GnuWin32 $ENV{programfiles32}\\GnuWin32
- PATH_SUFFIXES lib
- )
-
- ##_____________________________________________________________________________
- ## Check the libraries and include dirs and set POPT_FOUND.
- FIND_PACKAGE_HANDLE_STANDARD_ARGS (POPT DEFAULT_MSG POPT_LIBRARIES POPT_INCLUDE_DIRS)
-
- endif (NOT POPT_FOUND)
-
- ##_____________________________________________________________________________
- ## Actions taken when all components have been found
- if (POPT_FOUND)
- if (NOT POPT_FIND_QUIETLY)
- message (STATUS "Found components for POPT")
- message (STATUS "POPT_ROOT_DIR = ${POPT_ROOT_DIR}")
- message (STATUS "POPT_INCLUDE_DIRS = ${POPT_INCLUDE_DIRS}")
- message (STATUS "POPT_LIBRARIES = ${POPT_LIBRARIES}")
- endif (NOT POPT_FIND_QUIETLY)
- else (POPT_FOUND)
- if (POPT_FIND_REQUIRED)
- message (FATAL_ERROR "Could not find POPT!")
- endif (POPT_FIND_REQUIRED)
- endif (POPT_FOUND)
+# Check library and paths and set POPT_FOUND appropriately.
+INCLUDE(FindPackageHandleStandardArgs)
+if (TARGET "${POPT_LIBRARY_RELEASE}")
+ # The library is a taget created by PkgConfig.
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(POPT
+ REQUIRED_VARS POPT_LIBRARY_RELEASE
+ VERSION_VAR POPT_VERSION)
+else ()
+ # The library is a library file and header include path.
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(POPT DEFAULT_MSG POPT_LIBRARY_RELEASE POPT_INCLUDE_DIR)
+endif ()
- ##_____________________________________________________________________________
- ## Mark advanced variables
- mark_as_advanced (
- POPT_ROOT_DIR
- POPT_INCLUDE_DIRS
- POPT_LIBRARIES
- )
+# Set output vars from auto-detected/cached vars.
+if (POPT_FOUND)
+ set(POPT_INCLUDE_DIRS "${POPT_INCLUDE_DIR}")
+ set(POPT_LIBRARIES "${POPT_LIBRARY_RELEASE}")
+endif (POPT_FOUND)
-endif (NOT POPT_FOUND)
+# Mark cache vars as advanced.
+mark_as_advanced (POPT_INCLUDE_DIR POPT_LIBRARY_RELEASE)
diff --git a/cmake/Findlibb2.cmake b/cmake/Findlibb2.cmake
index ee2e1d6..8e3644d 100644
--- a/cmake/Findlibb2.cmake
+++ b/cmake/Findlibb2.cmake
@@ -1,14 +1,24 @@
# - Check for the presence of libb2
#
+# The following vars can be set to change behaviour;
+# LIBB2_INCLUDE_DIR - cached override for LIBB2_INCLUDE_DIRS.
+# LIBB2_LIBRARY_RELEASE - cached override for LIBB2_LIBRARIES.
+#
# The following variables are set when libb2 is found:
# LIBB2_FOUND = Set to true, if all components of libb2 have been found.
# LIBB2_INCLUDE_DIRS = Include path for the header files of libb2.
# LIBB2_LIBRARIES = Link these to use libb2.
-find_path (LIBB2_INCLUDE_DIRS blake2.h)
-find_library (LIBB2_LIBRARIES b2)
+find_path (LIBB2_INCLUDE_DIR blake2.h)
+find_library (LIBB2_LIBRARY_RELEASE b2)
INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS (LIBB2 DEFAULT_MSG LIBB2_LIBRARIES LIBB2_INCLUDE_DIRS)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS (LIBB2 DEFAULT_MSG LIBB2_LIBRARY_RELEASE LIBB2_INCLUDE_DIR)
+
+# Set output vars from auto-detected/cached vars.
+if (LIBB2_FOUND)
+ set(LIBB2_INCLUDE_DIRS "${LIBB2_INCLUDE_DIR}")
+ set(LIBB2_LIBRARIES "${LIBB2_LIBRARY_RELEASE}")
+endif (LIBB2_FOUND)
-mark_as_advanced (LIBB2_INCLUDE_DIRS LIBB2_LIBRARIES)
+mark_as_advanced (LIBB2_INCLUDE_DIR LIBB2_LIBRARY_RELEASE)