diff --git a/README.md b/README.md index 737499c5..190edb5a 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,6 @@ to the installation directory: ```bash export INSTALL_BASEDIR="${HOME}/dev/deliveries" export STDAIR_VER="1.00.17" -if [ -d /usr/lib64 ]; then LIBSUFFIX="64"; fi -export LIBSUFFIX_4_CMAKE="-DLIB_SUFFIX=$LIBSUFFIX" ``` Then, as usual: @@ -73,7 +71,7 @@ Then, as usual: $ mkdir build && cd build $ cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_BASEDIR}/stdair-$STDAIR_VER \ -DCMAKE_BUILD_TYPE:STRING=Debug -DENABLE_TEST:BOOL=ON \ - -DINSTALL_DOC:BOOL=ON -DRUN_GCOV:BOOL=OFF ${LIBSUFFIX_4_CMAKE} .. + -DINSTALL_DOC:BOOL=ON -DRUN_GCOV:BOOL=OFF .. ``` * With a specific version of Boost, say Boost 1.69 installed in a parallel way (for instance, as an optional module): diff --git a/autogen.sh b/autogen.sh index 18be60f9..f9798bce 100755 --- a/autogen.sh +++ b/autogen.sh @@ -172,18 +172,11 @@ cat >> configure << _EOF fi done -# -LIB_OPTION="" -if [ -d /usr/lib64 ] -then - LIB_OPTION="-DLIB_SUFFIX=64" -fi - # BUILD_OPTION="-DCMAKE_BUILD_TYPE:STRING=Debug" # -CMAKE_CMD="cmake \${PREFIX_OPTION} \${STDAIR_OPTION} \${LIB_OPTION} \${BUILD_OPTION} \${DOC_OPTION} \${SOURCE_DIR}" +CMAKE_CMD="cmake \${PREFIX_OPTION} \${STDAIR_OPTION} \${BUILD_OPTION} \${DOC_OPTION} \${SOURCE_DIR}" # Trace on set -x diff --git a/config/devhelpers.cmake b/config/devhelpers.cmake index e3035209..8d867027 100644 --- a/config/devhelpers.cmake +++ b/config/devhelpers.cmake @@ -4,15 +4,15 @@ # Configure helper (e.g., to easily retrieve the version and compilation flags) set (CFG_SCRIPT ${PROJECT_NAME}-config) -set (CFG_SCRIPT_PATH bin) +set (CFG_SCRIPT_PATH ${INSTALL_BIN_DIR}) # (Debian) Packaging helper set (PKGCFG_SCRIPT ${PROJECT_NAME}.pc) -set (PKGCFG_SCRIPT_PATH ${LIBDIR}/pkgconfig) +set (PKGCFG_SCRIPT_PATH ${CMAKE_INSTALL_LIBDIR}/pkgconfig) # GNU Autotools helper (M4 macro file) set (M4_MACROFILE ${PROJECT_NAME}.m4) -set (M4_MACROFILE_PATH share/aclocal) +set (M4_MACROFILE_PATH ${CMAKE_INSTALL_DATADIR}/aclocal) # Convert the developer script utilities (basically, just replace # the @@ variables) diff --git a/config/project_config_embeddable.cmake b/config/project_config_embeddable.cmake index cd42c47e..d8df1849 100644 --- a/config/project_config_embeddable.cmake +++ b/config/project_config_embeddable.cmake @@ -5,7 +5,6 @@ ## Date: July 2011 ####################################################################### - ################################################################### ## Project Configuration ## ################################################################### @@ -93,6 +92,8 @@ macro (set_project_options _build_doc _enable_tests _run_gcov) set (CMAKE_INSTALL_PREFIX "/usr") endif() + include(GNUInstallDirs) + # Unit tests (thanks to CMake/CTest) option (ENABLE_TEST "Set to OFF to skip build/check unit tests" ${_enable_tests}) @@ -110,34 +111,22 @@ macro (set_project_options _build_doc _enable_tests _run_gcov) set (MAN_ALL_TARGETS) set (NEED_PYTHON OFF) - # Set the library installation directory (either 32 or 64 bits) - set (LIBDIR "lib${LIB_SUFFIX}" CACHE PATH - "Library directory name, either lib or lib64") - # Offer the user the choice of overriding the installation directories - set (INSTALL_LIB_DIR ${LIBDIR} CACHE PATH + set (INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Installation directory for libraries") - set (INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables") - set (INSTALL_LIBEXEC_DIR CACHE PATH + set (INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Installation directory for executables") + set (INSTALL_LIBEXEC_DIR ${CMAKE_INSTALL_LIBEXECDIR} CACHE PATH "Installation directory for internal executables") - set (INSTALL_INCLUDE_DIR include CACHE PATH + set (INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Installation directory for header files") - set (INSTALL_DATA_DIR share CACHE PATH "Installation directory for data files") - set (INSTALL_SAMPLE_DIR share/${PROJECT_NAME}/samples CACHE PATH + set (INSTALL_DATA_DIR ${CMAKE_INSTALL_DATADIR} CACHE PATH "Installation directory for data files") + set (INSTALL_SAMPLE_DIR ${INSTALL_DATA_DIR}/${PROJECT_NAME}/samples CACHE PATH "Installation directory for (CSV) sample files") - set (INSTALL_ETC_DIR etc CACHE PATH "Installation directory for Config files") + set (INSTALL_ETC_DIR ${CMAKE_INSTALL_SYSCONFDIR} CACHE PATH "Installation directory for Config files") # GCOV option (RUN_GCOV "Set to OFF to skip code coverage" ${_run_gcov}) - # Make relative paths absolute (needed later on) - foreach (_path_type LIB PY_LIB BIN LIBEXEC INCLUDE DATA SAMPLE) - set (var INSTALL_${_path_type}_DIR) - if (NOT IS_ABSOLUTE "${${var}}") - set (${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") - endif () - endforeach (_path_type) - # When the install directory is not the canonical one (i.e., /usr), # the run-path/rpath must be set in all the (executable and library) # binaries, so that the dynamic loader can find the dependencies @@ -891,7 +880,7 @@ macro (get_xapian) # The first check is to get Xapian installation details if (${CMAKE_VERSION} VERSION_LESS 2.8.0) - set (Xapian_DIR /usr/${LIBDIR}/cmake/xapian) + set (Xapian_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/xapian) endif (${CMAKE_VERSION} VERSION_LESS 2.8.0) find_package (Xapian) @@ -1581,18 +1570,40 @@ endmacro (init_build) macro (set_install_directories) set (prefix ${CMAKE_INSTALL_PREFIX}) set (exec_prefix ${prefix}) - set (bindir ${exec_prefix}/bin) - set (libdir ${exec_prefix}/${LIBDIR}) - set (pylibdir ${libdir}/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages/py${PACKAGE}) - set (libexecdir ${exec_prefix}/libexec) - set (sbindir ${exec_prefix}/sbin) - set (sysconfdir ${prefix}/etc) - set (includedir ${prefix}/include) - set (datarootdir ${prefix}/share) - set (datadir ${datarootdir}) - set (pkgdatadir ${datarootdir}/${PACKAGE}) - set (sampledir ${STDAIR_SAMPLE_DIR}) - set (docdir ${datarootdir}/doc/${PACKAGE}-${PACKAGE_VERSION}) + if(CMAKE_VERSION VERSION_LESS 3.20) + set(dir BINDIR) + endif() + GNUInstallDirs_get_absolute_install_dir(bindir INSTALL_BIN_DIR BINDIR) + if(CMAKE_VERSION VERSION_LESS 3.20) + set(dir LIBDIR) + endif() + GNUInstallDirs_get_absolute_install_dir(libdir INSTALL_LIB_DIR LIBDIR) + set(pylibdir ${INSTALL_LIB_DIR}/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages/py${PACKAGE}) + GNUInstallDirs_get_absolute_install_dir(pylibdir pylibdir LIBDIR) + if(CMAKE_VERSION VERSION_LESS 3.20) + set(dir LIBEXECDIR) + endif() + GNUInstallDirs_get_absolute_install_dir(libexecdir INSTALL_LIBEXEC_DIR LIBEXECDIR) + if(CMAKE_VERSION VERSION_LESS 3.20) + set(dir SBINDIR) + endif() + GNUInstallDirs_get_absolute_install_dir(sbindir CMAKE_INSTALL_SBINDIR SBINDIR) + if(CMAKE_VERSION VERSION_LESS 3.20) + set(dir SYSCONFDIR) + endif() + GNUInstallDirs_get_absolute_install_dir(sysconfdir INSTALL_ETC_DIR SYSCONFDIR) + if(CMAKE_VERSION VERSION_LESS 3.20) + set(dir INCLUDEDIR) + endif() + GNUInstallDirs_get_absolute_install_dir(includedir INSTALL_INCLUDE_DIR INCLUDEDIR) + if(CMAKE_VERSION VERSION_LESS 3.20) + set(dir DATADIR) + endif() + GNUInstallDirs_get_absolute_install_dir(datadir INSTALL_DATA_DIR DATADIR) + set (datarootdir ${datadir}) + set (pkgdatadir ${datadir}/${PACKAGE}) + GNUInstallDirs_get_absolute_install_dir(sampledir STDAIR_SAMPLE_DIR DATADIR) + set (docdir ${datadir}/doc/${PACKAGE}-${PACKAGE_VERSION}) set (htmldir ${docdir}/html) set (pdfdir ${htmldir}) set (mandir ${datarootdir}/man) @@ -1630,7 +1641,7 @@ macro (add_modules) set (_embedded_components ${ARGV}) set (LIB_DEPENDENCY_EXPORT ${PROJECT_NAME}-library-depends) set (PY_LIB_DEPENDENCY_EXPORT ${PROJECT_NAME}-python-library-depends) - set (LIB_DEPENDENCY_EXPORT_PATH "${INSTALL_DATA_DIR}/${PROJECT_NAME}/CMake") + set (LIB_DEPENDENCY_EXPORT_PATH "${INSTALL_LIB_DIR}/cmake/${PROJECT_NAME}") # foreach (_embedded_comp ${_embedded_components}) # @@ -1832,6 +1843,11 @@ macro (module_library_add_specific # Register the (CMake) target for the library add_library (${_lib_target} SHARED ${_lib_sources}) + # Add the include directory for the consumer + # TODO: Private and Public header files are not distinguished + target_include_directories(${_lib_target} PUBLIC + $ + ) # For each module, given as parameter of that macro, add the corresponding # library target to a dedicated list @@ -2160,11 +2176,11 @@ endmacro (module_script_add) # can refer to it (for libraries, header files and binaries) macro (module_export_install) install (EXPORT ${LIB_DEPENDENCY_EXPORT} - DESTINATION "${INSTALL_DATA_DIR}/${PACKAGE}/CMake" COMPONENT devel) + DESTINATION "${INSTALL_LIB_DIR}/cmake/${PACKAGE}" COMPONENT devel) if (NEED_PYTHON) install (EXPORT ${PY_LIB_DEPENDENCY_EXPORT} - DESTINATION "${INSTALL_DATA_DIR}/${PACKAGE}/CMake" COMPONENT python-devel) + DESTINATION "${INSTALL_LIB_DIR}/cmake/${PACKAGE}" COMPONENT python-devel) endif (NEED_PYTHON) endmacro (module_export_install) @@ -2636,6 +2652,7 @@ macro (install_dev_helper_files) # Create a ${PROJECT_NAME}-config.cmake file for the use from # the install tree and install it module_export_install() + include(CMakePackageConfigHelpers) set (${PACKAGE_NAME}_INCLUDE_DIRS "${INSTALL_INCLUDE_DIR}") set (${PACKAGE_NAME}_BIN_DIR "${INSTALL_BIN_DIR}") set (${PACKAGE_NAME}_LIB_DIR "${INSTALL_LIB_DIR}") @@ -2644,17 +2661,29 @@ macro (install_dev_helper_files) set (${PACKAGE_NAME}_CMAKE_DIR "${LIB_DEPENDENCY_EXPORT_PATH}") # When the project is OpenTREP, OPENTREP_SAMPLE_DIR has # already been defined before - if (NOT "${PROJECT_NAME}" STREQUAL "opentrep") + if (NOT PROJECT_NAME STREQUAL "opentrep") set (${PACKAGE_NAME}_SAMPLE_DIR "${INSTALL_SAMPLE_DIR}") - endif (NOT "${PROJECT_NAME}" STREQUAL "opentrep") - configure_file (${PROJECT_NAME}-config.cmake.in - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" @ONLY) + endif () + configure_package_config_file( + ${PROJECT_NAME}-config.cmake.in + ${PROJECT_NAME}-config.cmake + INSTALL_DESTINATION ${${PACKAGE_NAME}_CMAKE_DIR} + PATH_VARS + ${PACKAGE_NAME}_INCLUDE_DIRS + ${PACKAGE_NAME}_BIN_DIR + ${PACKAGE_NAME}_LIB_DIR + ${PACKAGE_NAME}_LIBEXEC_DIR + ${PACKAGE_NAME}_SAMPLE_DIR + ) + write_basic_package_version_file( + ${PROJECT_NAME}-config-version.cmake + VERSION ${PACKAGE_VERSION} + COMPATIBILITY AnyNewerVersion + ) if (NEED_PYTHON) configure_file (${PROJECT_NAME}-config-python.cmake.in "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-python.cmake" @ONLY) endif (NEED_PYTHON) - configure_file (${PROJECT_NAME}-config-version.cmake.in - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" @ONLY) install (FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" diff --git a/stdair-config-version.cmake.in b/stdair-config-version.cmake.in deleted file mode 100644 index 5f37a335..00000000 --- a/stdair-config-version.cmake.in +++ /dev/null @@ -1,13 +0,0 @@ -# -set(PACKAGE_VERSION "@PACKAGE_VERSION@") - -# Check whether the requested PACKAGE_FIND_VERSION is compatible -if ("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") - set (PACKAGE_VERSION_COMPATIBLE FALSE) - -else() - set (PACKAGE_VERSION_COMPATIBLE TRUE) - if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") - set (PACKAGE_VERSION_EXACT TRUE) - endif() -endif() diff --git a/stdair-config.cmake.in b/stdair-config.cmake.in index 10c418ca..160cb16a 100644 --- a/stdair-config.cmake.in +++ b/stdair-config.cmake.in @@ -1,3 +1,5 @@ +@PACKAGE_INIT@ + # # Config file for the StdAir package. It defines the following variables: # STDAIR_VERSION - version of StdAir @@ -10,13 +12,16 @@ # Tell the user project where to find the headers, libraries and sample files set (STDAIR_VERSION "@PACKAGE_VERSION@") -set (STDAIR_BINARY_DIRS "@STDAIR_BIN_DIR@") -set (STDAIR_INCLUDE_DIRS "@STDAIR_INCLUDE_DIRS@") -set (STDAIR_LIBRARY_DIRS "@STDAIR_LIB_DIR@") -set (STDAIR_SAMPLE_DIR "@STDAIR_SAMPLE_DIR@") +set (STDAIR_BINARY_DIRS "@PACKAGE_STDAIR_BIN_DIR@") +set (STDAIR_INCLUDE_DIRS "@PACKAGE_STDAIR_INCLUDE_DIRS@") +set (STDAIR_LIBRARY_DIRS "@PACKAGE_STDAIR_LIB_DIR@") +set (STDAIR_SAMPLE_DIR "@PACKAGE_STDAIR_SAMPLE_DIR@") + +include(CMakeFindDependencyMacro) +find_dependency(Boost COMPONENTS @BOOST_REQUIRED_COMPONENTS@) # Our library dependencies (contains definitions for IMPORTED targets) -include ("@STDAIR_CMAKE_DIR@/stdair-library-depends.cmake") +include ("${CMAKE_CURRENT_LIST_DIR}/stdair-library-depends.cmake") # These are IMPORTED targets created by stdair-library-depends.cmake set (STDAIR_LIBRARIES stdairlib stdairuicllib) diff --git a/stdair-config.in b/stdair-config.in index 2ab55280..1d14c36a 100644 --- a/stdair-config.in +++ b/stdair-config.in @@ -1,9 +1,13 @@ #!/bin/sh +# NOTE: This is not properly constructed to be relocatable +# e.g. `sysconfdir` does not relocate outside of ${prefix} according to the +# GNUInstallDirs rules. + prefix=@prefix@ exec_prefix=${prefix} bindir=${exec_prefix}/bin -libdir=${exec_prefix}/lib@LIB_SUFFIX@ +libdir=${exec_prefix}/@INSTALL_LIB_DIR@ libexecdir=${exec_prefix}/libexec sbindir=${exec_prefix}/sbin sysconfdir=${prefix}/etc diff --git a/stdair.pc.in b/stdair.pc.in index 933d42a5..e3266a31 100644 --- a/stdair.pc.in +++ b/stdair.pc.in @@ -1,7 +1,7 @@ prefix=@prefix@ exec_prefix=${prefix} bindir=${exec_prefix}/bin -libdir=${exec_prefix}/lib@LIB_SUFFIX@ +libdir=${exec_prefix}/@INSTALL_LIB_DIR@ libexecdir=${exec_prefix}/libexec sbindir=${exec_prefix}/sbin sysconfdir=${prefix}/etc