5
5
## Date: July 2011
6
6
#######################################################################
7
7
8
-
9
8
###################################################################
10
9
## Project Configuration ##
11
10
###################################################################
@@ -93,6 +92,8 @@ macro (set_project_options _build_doc _enable_tests _run_gcov)
93
92
set (CMAKE_INSTALL_PREFIX "/usr" )
94
93
endif ()
95
94
95
+ include (GNUInstallDirs)
96
+
96
97
# Unit tests (thanks to CMake/CTest)
97
98
option (ENABLE_TEST "Set to OFF to skip build/check unit tests"
98
99
${_enable_tests} )
@@ -110,34 +111,22 @@ macro (set_project_options _build_doc _enable_tests _run_gcov)
110
111
set (MAN_ALL_TARGETS)
111
112
set (NEED_PYTHON OFF )
112
113
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
-
117
114
# 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
119
116
"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
122
119
"Installation directory for internal executables" )
123
- set (INSTALL_INCLUDE_DIR include CACHE PATH
120
+ set (INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH
124
121
"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
127
124
"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" )
129
126
130
127
# GCOV
131
128
option (RUN_GCOV "Set to OFF to skip code coverage" ${_run_gcov} )
132
129
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
-
141
130
# When the install directory is not the canonical one (i.e., /usr),
142
131
# the run-path/rpath must be set in all the (executable and library)
143
132
# binaries, so that the dynamic loader can find the dependencies
@@ -891,7 +880,7 @@ macro (get_xapian)
891
880
892
881
# The first check is to get Xapian installation details
893
882
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)
895
884
endif (${CMAKE_VERSION} VERSION_LESS 2.8.0)
896
885
find_package (Xapian)
897
886
@@ -1581,18 +1570,40 @@ endmacro (init_build)
1581
1570
macro (set_install_directories)
1582
1571
set (prefix ${CMAKE_INSTALL_PREFIX} )
1583
1572
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} )
1596
1607
set (htmldir ${docdir} /html)
1597
1608
set (pdfdir ${htmldir} )
1598
1609
set (mandir ${datarootdir} /man)
@@ -1630,7 +1641,7 @@ macro (add_modules)
1630
1641
set (_embedded_components ${ARGV} )
1631
1642
set (LIB_DEPENDENCY_EXPORT ${PROJECT_NAME} -library-depends )
1632
1643
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} " )
1634
1645
#
1635
1646
foreach (_embedded_comp ${_embedded_components} )
1636
1647
#
@@ -2160,11 +2171,11 @@ endmacro (module_script_add)
2160
2171
# can refer to it (for libraries, header files and binaries)
2161
2172
macro (module_export_install)
2162
2173
install (EXPORT ${LIB_DEPENDENCY_EXPORT}
2163
- DESTINATION "${INSTALL_DATA_DIR} / ${PACKAGE} /CMake " COMPONENT devel)
2174
+ DESTINATION "${INSTALL_LIB_DIR} /cmake/ ${PACKAGE} " COMPONENT devel)
2164
2175
2165
2176
if (NEED_PYTHON)
2166
2177
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)
2168
2179
endif (NEED_PYTHON)
2169
2180
endmacro (module_export_install)
2170
2181
@@ -2636,25 +2647,37 @@ macro (install_dev_helper_files)
2636
2647
# Create a ${PROJECT_NAME}-config.cmake file for the use from
2637
2648
# the install tree and install it
2638
2649
module_export_install()
2650
+ include (CMakePackageConfigHelpers)
2639
2651
set (${PACKAGE_NAME} _INCLUDE_DIRS "${INSTALL_INCLUDE_DIR} " )
2640
2652
set (${PACKAGE_NAME} _BIN_DIR "${INSTALL_BIN_DIR} " )
2641
2653
set (${PACKAGE_NAME} _LIB_DIR "${INSTALL_LIB_DIR} " )
2642
2654
set (${PACKAGE_NAME} _LIBEXEC_DIR "${INSTALL_LIBEXEC_DIR} " )
2643
2655
set (${PACKAGE_NAME} _PY_LIB_DIR "${INSTALL_PY_LIB_DIR} " )
2644
2656
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
+ )
2645
2672
# When the project is OpenTREP, OPENTREP_SAMPLE_DIR has
2646
2673
# already been defined before
2647
2674
if (NOT "${PROJECT_NAME} " STREQUAL "opentrep" )
2648
2675
set (${PACKAGE_NAME} _SAMPLE_DIR "${INSTALL_SAMPLE_DIR} " )
2649
2676
endif (NOT "${PROJECT_NAME} " STREQUAL "opentrep" )
2650
- configure_file (${PROJECT_NAME} -config.cmake.in
2651
- "${PROJECT_BINARY_DIR} /${PROJECT_NAME} -config.cmake" @ONLY)
2652
2677
if (NEED_PYTHON)
2653
2678
configure_file (${PROJECT_NAME} -config-python.cmake.in
2654
2679
"${PROJECT_BINARY_DIR} /${PROJECT_NAME} -config-python.cmake" @ONLY)
2655
2680
endif (NEED_PYTHON)
2656
- configure_file (${PROJECT_NAME} -config-version .cmake.in
2657
- "${PROJECT_BINARY_DIR} /${PROJECT_NAME} -config-version.cmake" @ONLY)
2658
2681
install (FILES
2659
2682
"${PROJECT_BINARY_DIR} /${PROJECT_NAME} -config.cmake"
2660
2683
"${PROJECT_BINARY_DIR} /${PROJECT_NAME} -config-version.cmake"
0 commit comments