55## Date: July 2011
66#######################################################################
77
8-
98###################################################################
109## Project Configuration ##
1110###################################################################
@@ -93,6 +92,8 @@ macro (set_project_options _build_doc _enable_tests _run_gcov)
9392 set (CMAKE_INSTALL_PREFIX "/usr" )
9493 endif ()
9594
95+ include (GNUInstallDirs)
96+
9697 # Unit tests (thanks to CMake/CTest)
9798 option (ENABLE_TEST "Set to OFF to skip build/check unit tests"
9899 ${_enable_tests} )
@@ -110,34 +111,22 @@ macro (set_project_options _build_doc _enable_tests _run_gcov)
110111 set (MAN_ALL_TARGETS)
111112 set (NEED_PYTHON OFF )
112113
113- # Set the library installation directory (either 32 or 64 bits)
114- set (LIBDIR "lib${LIB_SUFFIX} " CACHE PATH
115- "Library directory name, either lib or lib64" )
116-
117114 # Offer the user the choice of overriding the installation directories
118- set (INSTALL_LIB_DIR ${LIBDIR } CACHE PATH
115+ set (INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR } CACHE PATH
119116 "Installation directory for libraries" )
120- set (INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables" )
121- set (INSTALL_LIBEXEC_DIR CACHE PATH
117+ set (INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Installation directory for executables" )
118+ set (INSTALL_LIBEXEC_DIR ${CMAKE_INSTALL_LIBEXECDIR} CACHE PATH
122119 "Installation directory for internal executables" )
123- set (INSTALL_INCLUDE_DIR include CACHE PATH
120+ set (INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH
124121 "Installation directory for header files" )
125- set (INSTALL_DATA_DIR share CACHE PATH "Installation directory for data files" )
126- set (INSTALL_SAMPLE_DIR share /${PROJECT_NAME} /samples CACHE PATH
122+ set (INSTALL_DATA_DIR ${CMAKE_INSTALL_DATADIR} CACHE PATH "Installation directory for data files" )
123+ set (INSTALL_SAMPLE_DIR ${INSTALL_DATA_DIR} /${PROJECT_NAME} /samples CACHE PATH
127124 "Installation directory for (CSV) sample files" )
128- set (INSTALL_ETC_DIR etc CACHE PATH "Installation directory for Config files" )
125+ set (INSTALL_ETC_DIR ${CMAKE_INSTALL_SYSCONFDIR} CACHE PATH "Installation directory for Config files" )
129126
130127 # GCOV
131128 option (RUN_GCOV "Set to OFF to skip code coverage" ${_run_gcov} )
132129
133- # Make relative paths absolute (needed later on)
134- foreach (_path_type LIB PY_LIB BIN LIBEXEC INCLUDE DATA SAMPLE)
135- set (var INSTALL_${_path_type} _DIR)
136- if (NOT IS_ABSOLUTE "${${var} }" )
137- set (${var} "${CMAKE_INSTALL_PREFIX} /${${var} }" )
138- endif ()
139- endforeach (_path_type)
140-
141130 # When the install directory is not the canonical one (i.e., /usr),
142131 # the run-path/rpath must be set in all the (executable and library)
143132 # binaries, so that the dynamic loader can find the dependencies
@@ -891,7 +880,7 @@ macro (get_xapian)
891880
892881 # The first check is to get Xapian installation details
893882 if (${CMAKE_VERSION} VERSION_LESS 2.8.0)
894- set (Xapian_DIR /usr/ ${LIBDIR } /cmake/xapian)
883+ set (Xapian_DIR ${CMAKE_INSTALL_LIBDIR } /cmake/xapian)
895884 endif (${CMAKE_VERSION} VERSION_LESS 2.8.0)
896885 find_package (Xapian)
897886
@@ -1581,18 +1570,40 @@ endmacro (init_build)
15811570macro (set_install_directories)
15821571 set (prefix ${CMAKE_INSTALL_PREFIX} )
15831572 set (exec_prefix ${prefix} )
1584- set (bindir ${exec_prefix} /bin)
1585- set (libdir ${exec_prefix} /${LIBDIR} )
1586- set (pylibdir ${libdir} /python${Python3_VERSION_MAJOR} .${Python3_VERSION_MINOR} /site-packages/py${PACKAGE} )
1587- set (libexecdir ${exec_prefix} /libexec)
1588- set (sbindir ${exec_prefix} /sbin)
1589- set (sysconfdir ${prefix} /etc)
1590- set (includedir ${prefix} /include )
1591- set (datarootdir ${prefix} /share)
1592- set (datadir ${datarootdir} )
1593- set (pkgdatadir ${datarootdir} /${PACKAGE} )
1594- set (sampledir ${STDAIR_SAMPLE_DIR} )
1595- set (docdir ${datarootdir} /doc /${PACKAGE} -${PACKAGE_VERSION} )
1573+ if (CMAKE_VERSION VERSION_LESS 3.20)
1574+ set (dir BINDIR)
1575+ endif ()
1576+ GNUInstallDirs_get_absolute_install_dir(bindir INSTALL_BIN_DIR BINDIR)
1577+ if (CMAKE_VERSION VERSION_LESS 3.20)
1578+ set (dir LIBDIR)
1579+ endif ()
1580+ GNUInstallDirs_get_absolute_install_dir(libdir INSTALL_LIB_DIR LIBDIR)
1581+ set (pylibdir ${INSTALL_LIB_DIR} /python${Python3_VERSION_MAJOR} .${Python3_VERSION_MINOR} /site-packages/py${PACKAGE} )
1582+ GNUInstallDirs_get_absolute_install_dir(pylibdir pylibdir LIBDIR)
1583+ if (CMAKE_VERSION VERSION_LESS 3.20)
1584+ set (dir LIBEXECDIR)
1585+ endif ()
1586+ GNUInstallDirs_get_absolute_install_dir(libexecdir INSTALL_LIBEXEC_DIR LIBEXECDIR)
1587+ if (CMAKE_VERSION VERSION_LESS 3.20)
1588+ set (dir SBINDIR)
1589+ endif ()
1590+ GNUInstallDirs_get_absolute_install_dir(sbindir CMAKE_INSTALL_SBINDIR SBINDIR)
1591+ if (CMAKE_VERSION VERSION_LESS 3.20)
1592+ set (dir SYSCONFDIR)
1593+ endif ()
1594+ GNUInstallDirs_get_absolute_install_dir(sysconfdir INSTALL_ETC_DIR SYSCONFDIR)
1595+ if (CMAKE_VERSION VERSION_LESS 3.20)
1596+ set (dir INCLUDEDIR)
1597+ endif ()
1598+ GNUInstallDirs_get_absolute_install_dir(includedir INSTALL_INCLUDE_DIR INCLUDEDIR)
1599+ if (CMAKE_VERSION VERSION_LESS 3.20)
1600+ set (dir DATADIR)
1601+ endif ()
1602+ GNUInstallDirs_get_absolute_install_dir(datadir INSTALL_DATA_DIR DATADIR)
1603+ set (datarootdir ${datadir} )
1604+ set (pkgdatadir ${datadir} /${PACKAGE} )
1605+ GNUInstallDirs_get_absolute_install_dir(sampledir STDAIR_SAMPLE_DIR DATADIR)
1606+ set (docdir ${datadir} /doc /${PACKAGE} -${PACKAGE_VERSION} )
15961607 set (htmldir ${docdir} /html)
15971608 set (pdfdir ${htmldir} )
15981609 set (mandir ${datarootdir} /man)
@@ -1630,7 +1641,7 @@ macro (add_modules)
16301641 set (_embedded_components ${ARGV} )
16311642 set (LIB_DEPENDENCY_EXPORT ${PROJECT_NAME} -library-depends )
16321643 set (PY_LIB_DEPENDENCY_EXPORT ${PROJECT_NAME} -python-library-depends )
1633- set (LIB_DEPENDENCY_EXPORT_PATH "${INSTALL_DATA_DIR} / ${PROJECT_NAME} /CMake " )
1644+ set (LIB_DEPENDENCY_EXPORT_PATH "${INSTALL_LIB_DIR} /cmake/ ${PROJECT_NAME} " )
16341645 #
16351646 foreach (_embedded_comp ${_embedded_components} )
16361647 #
@@ -2160,11 +2171,11 @@ endmacro (module_script_add)
21602171# can refer to it (for libraries, header files and binaries)
21612172macro (module_export_install)
21622173 install (EXPORT ${LIB_DEPENDENCY_EXPORT}
2163- DESTINATION "${INSTALL_DATA_DIR} / ${PACKAGE} /CMake " COMPONENT devel)
2174+ DESTINATION "${INSTALL_LIB_DIR} /cmake/ ${PACKAGE} " COMPONENT devel)
21642175
21652176 if (NEED_PYTHON)
21662177 install (EXPORT ${PY_LIB_DEPENDENCY_EXPORT}
2167- DESTINATION "${INSTALL_DATA_DIR} / ${PACKAGE} /CMake " COMPONENT python-devel)
2178+ DESTINATION "${INSTALL_LIB_DIR} /cmake/ ${PACKAGE} " COMPONENT python-devel)
21682179 endif (NEED_PYTHON)
21692180endmacro (module_export_install)
21702181
@@ -2636,25 +2647,37 @@ macro (install_dev_helper_files)
26362647 # Create a ${PROJECT_NAME}-config.cmake file for the use from
26372648 # the install tree and install it
26382649 module_export_install()
2650+ include (CMakePackageConfigHelpers)
26392651 set (${PACKAGE_NAME} _INCLUDE_DIRS "${INSTALL_INCLUDE_DIR} " )
26402652 set (${PACKAGE_NAME} _BIN_DIR "${INSTALL_BIN_DIR} " )
26412653 set (${PACKAGE_NAME} _LIB_DIR "${INSTALL_LIB_DIR} " )
26422654 set (${PACKAGE_NAME} _LIBEXEC_DIR "${INSTALL_LIBEXEC_DIR} " )
26432655 set (${PACKAGE_NAME} _PY_LIB_DIR "${INSTALL_PY_LIB_DIR} " )
26442656 set (${PACKAGE_NAME} _CMAKE_DIR "${LIB_DEPENDENCY_EXPORT_PATH} " )
2657+ configure_package_config_file(
2658+ ${PROJECT_NAME} -config.cmake.in
2659+ ${PROJECT_NAME} -config.cmake
2660+ INSTALL_DESTINATION ${${PACKAGE_NAME} _CMAKE_DIR}
2661+ PATH_VARS
2662+ ${PACKAGE_NAME} _INCLUDE_DIRS
2663+ ${PACKAGE_NAME} _BIN_DIR
2664+ ${PACKAGE_NAME} _LIB_DIR
2665+ ${PACKAGE_NAME} _LIBEXEC_DIR
2666+ )
2667+ write_basic_package_version_file(
2668+ ${PROJECT_NAME} -config-version .cmake
2669+ VERSION ${PACKAGE_VERSION}
2670+ COMPATIBILITY AnyNewerVersion
2671+ )
26452672 # When the project is OpenTREP, OPENTREP_SAMPLE_DIR has
26462673 # already been defined before
26472674 if (NOT "${PROJECT_NAME} " STREQUAL "opentrep" )
26482675 set (${PACKAGE_NAME} _SAMPLE_DIR "${INSTALL_SAMPLE_DIR} " )
26492676 endif (NOT "${PROJECT_NAME} " STREQUAL "opentrep" )
2650- configure_file (${PROJECT_NAME} -config.cmake.in
2651- "${PROJECT_BINARY_DIR} /${PROJECT_NAME} -config.cmake" @ONLY)
26522677 if (NEED_PYTHON)
26532678 configure_file (${PROJECT_NAME} -config-python.cmake.in
26542679 "${PROJECT_BINARY_DIR} /${PROJECT_NAME} -config-python.cmake" @ONLY)
26552680 endif (NEED_PYTHON)
2656- configure_file (${PROJECT_NAME} -config-version .cmake.in
2657- "${PROJECT_BINARY_DIR} /${PROJECT_NAME} -config-version.cmake" @ONLY)
26582681 install (FILES
26592682 "${PROJECT_BINARY_DIR} /${PROJECT_NAME} -config.cmake"
26602683 "${PROJECT_BINARY_DIR} /${PROJECT_NAME} -config-version.cmake"
0 commit comments