Skip to content

Commit 5ada9cb

Browse files
authored
Merge pull request #2 from LecrisUT/GNUInstallDirs
Switch to using GNUInstallDirs as defaults
2 parents 5d2c579 + 36b0f4a commit 5ada9cb

File tree

8 files changed

+79
-74
lines changed

8 files changed

+79
-74
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ environment, you can alter the path to the installation directory:
8080
```bash
8181
export INSTALL_BASEDIR="${HOME}/dev/deliveries"
8282
export RMOL_VER="1.00.12"
83-
if [ -d /usr/lib64 ]; then LIBSUFFIX="64"; fi
84-
export LIBSUFFIX_4_CMAKE="-DLIB_SUFFIX=$LIBSUFFIX"
8583
```
8684

8785
Then, as usual:
@@ -92,8 +90,7 @@ Then, as usual:
9290
-DWITH_STDAIR_PREFIX=${INSTALL_BASEDIR}/stdair-stable \
9391
-DWITH_AIRRAC_PREFIX=${INSTALL_BASEDIR}/airrac-stable \
9492
-DCMAKE_BUILD_TYPE:STRING=Debug -DENABLE_TEST:BOOL=ON -DINSTALL_DOC:BOOL=ON \
95-
-DRUN_GCOV:BOOL=OFF ${LIBSUFFIX_4_CMAKE} ..
96-
${LIBSUFFIX_4_CMAKE} ..
93+
-DRUN_GCOV:BOOL=OFF ..
9794
```
9895
* To build the project, type:
9996
```bash

autogen.sh

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,11 @@ cat >> configure << _EOF
184184
fi
185185
done
186186
187-
#
188-
LIB_OPTION=""
189-
if [ -d /usr/lib64 ]
190-
then
191-
LIB_OPTION="-DLIB_SUFFIX=64"
192-
fi
193-
194187
#
195188
BUILD_OPTION="-DCMAKE_BUILD_TYPE:STRING=Debug"
196189
197190
#
198-
CMAKE_CMD="cmake \${PREFIX_OPTION} \${STDAIR_OPTION} \${AIRRAC_OPTION} \${LIB_OPTION} \${BUILD_OPTION} \${DOC_OPTION} \${SOURCE_DIR}"
191+
CMAKE_CMD="cmake \${PREFIX_OPTION} \${STDAIR_OPTION} \${AIRRAC_OPTION} \${BUILD_OPTION} \${DOC_OPTION} \${SOURCE_DIR}"
199192
200193
# Trace on
201194
set -x

config/devhelpers.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
# Configure helper (e.g., to easily retrieve the version and compilation flags)
66
set (CFG_SCRIPT ${PROJECT_NAME}-config)
7-
set (CFG_SCRIPT_PATH bin)
7+
set (CFG_SCRIPT_PATH ${INSTALL_BIN_DIR})
88

99
# (Debian) Packaging helper
1010
set (PKGCFG_SCRIPT ${PROJECT_NAME}.pc)
11-
set (PKGCFG_SCRIPT_PATH ${LIBDIR}/pkgconfig)
11+
set (PKGCFG_SCRIPT_PATH ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
1212

1313
# GNU Autotools helper (M4 macro file)
1414
set (M4_MACROFILE ${PROJECT_NAME}.m4)
15-
set (M4_MACROFILE_PATH share/aclocal)
15+
set (M4_MACROFILE_PATH ${CMAKE_INSTALL_DATADIR}/aclocal)
1616

1717
# Convert the developer script utilities (basically, just replace
1818
# the @<variable>@ variables)

config/project_config_embeddable.cmake

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
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)
15811570
macro (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)
21612172
macro (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)
21692180
endmacro (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"

rmol-config-version.cmake.in

Lines changed: 0 additions & 13 deletions
This file was deleted.

rmol-config.cmake.in

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@PACKAGE_INIT@
2+
13
#
24
# Config file for the RMOL package. It defines the following variables:
35
# RMOL_VERSION - version of RMOL
@@ -11,10 +13,10 @@
1113

1214
# Tell the user project where to find RMOL headers and libraries
1315
set (RMOL_VERSION "@PACKAGE_VERSION@")
14-
set (RMOL_BINARY_DIRS "@RMOL_BIN_DIR@")
15-
set (RMOL_INCLUDE_DIRS "@RMOL_INCLUDE_DIRS@")
16-
set (RMOL_LIBRARY_DIRS "@RMOL_LIB_DIR@")
17-
set (RMOL_LIBEXEC_DIR "@RMOL_LIBEXEC_DIR@")
16+
set (RMOL_BINARY_DIRS "@PACKAGE_RMOL_BIN_DIR@")
17+
set (RMOL_INCLUDE_DIRS "@PACKAGE_RMOL_INCLUDE_DIRS@")
18+
set (RMOL_LIBRARY_DIRS "@PACKAGE_RMOL_LIB_DIR@")
19+
set (RMOL_LIBEXEC_DIR "@PACKAGE_RMOL_LIBEXEC_DIR@")
1820

1921
# Library dependencies for RMOL (contains definitions for the RMOL IMPORTED
2022
# targets)

rmol-config.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/usr/bin/sh
22

3+
# NOTE: This is not properly constructed to be relocatable
4+
# e.g. `sysconfdir` does not relocate outside of ${prefix} according to the
5+
# GNUInstallDirs rules.
6+
37
prefix=@prefix@
48
exec_prefix=${prefix}
59
bindir=${exec_prefix}/bin
6-
libdir=${exec_prefix}/lib@LIB_SUFFIX@
10+
libdir=${exec_prefix}/@INSTALL_LIB_DIR@
711
libexecdir=${exec_prefix}/libexec
812
sbindir=${exec_prefix}/sbin
913
sysconfdir=${prefix}/etc

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
cmake_args = [
3939
'-DINSTALL_DOC:BOOL=OFF',
4040
'-DRUN_GCOV:BOOL=OFF',
41-
'-DLIB_SUFFIX=',
4241
f'-DWITH_STDAIR_PREFIX={install_dir}/stdair',
4342
f'-DWITH_AIRRAC_PREFIX={install_dir}/airrac'
4443
] + (

0 commit comments

Comments
 (0)