Skip to content

Commit 5dadbee

Browse files
committed
CMake: added support for parsing install directories defined as parameters
RPM build tools pass specifications of installation directories to CMake that must be used to properly install binary and configuration files. Manual processing is necessary because CMake module GNUInstallDirs ingores these parameters and provides different directories on old systems.
1 parent b8c2505 commit 5dadbee

File tree

11 files changed

+66
-23
lines changed

11 files changed

+66
-23
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ set(IPFIXCOL_VERSION
2121

2222
# Include modules
2323
include(CMakeModules/git_info.cmake)
24+
include(CMakeModules/install_dirs.cmake)
2425
include(CheckCCompilerFlag)
2526
include(CheckCXXCompilerFlag)
26-
include(GNUInstallDirs)
2727

2828
# Include custom FindXXX modules
2929
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules")

CMakeModules/install_dirs.cmake

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# The purpose of this file is to automatically determine install directories
2+
#
3+
# If no directories are defined, use GNU install directories by default.
4+
# However, in case of RPM build, install directories are typically passed
5+
# to CMake as definitions that overwrites the default paths.
6+
#
7+
8+
include(GNUInstallDirs)
9+
10+
# Binary directories
11+
set(INSTALL_DIR_BIN ${CMAKE_INSTALL_FULL_BINDIR})
12+
13+
# Library directories
14+
if (DEFINED LIB_INSTALL_DIR)
15+
set(INSTALL_DIR_LIB ${LIB_INSTALL_DIR})
16+
else()
17+
set(INSTALL_DIR_LIB ${CMAKE_INSTALL_FULL_LIBDIR})
18+
endif()
19+
20+
# Include directories
21+
if (DEFINED INCLUDE_INSTALL_DIR)
22+
set(INSTALL_DIR_INCLUDE ${INCLUDE_INSTALL_DIR})
23+
else()
24+
set(INSTALL_DIR_INCLUDE ${CMAKE_INSTALL_FULL_INCLUDEDIR})
25+
endif()
26+
27+
# System configuration
28+
if (DEFINED SYSCONF_INSTALL_DIR)
29+
set(INSTALL_DIR_SYSCONF ${SYSCONF_INSTALL_DIR})
30+
else()
31+
set(INSTALL_DIR_SYSCONF ${CMAKE_INSTALL_FULL_SYSCONFDIR})
32+
endif()
33+
34+
# Share files (architecture independend data)
35+
if (DEFINED SHARE_INSTALL_PREFIX)
36+
set(INSTALL_DIR_SHARE ${SHARE_INSTALL_PREFIX})
37+
else()
38+
set(INSTALL_DIR_SHARE ${CMAKE_INSTALL_FULL_DATAROOTDIR})
39+
endif()
40+
41+
set(INSTALL_DIR_INFO "${INSTALL_DIR_SHARE}/info/")
42+
set(INSTALL_DIR_MAN "${INSTALL_DIR_SHARE}/man/")
43+
set(INSTALL_DIR_DOC "${INSTALL_DIR_SHARE}/doc/${CMAKE_PROJECT_NAME}/")
44+

pkg/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ if (PKG_CONFIG_FOUND)
6767
@ONLY)
6868
install(
6969
FILES "${CMAKE_CURRENT_BINARY_DIR}/ipfixcol2.pc"
70-
DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig/")
70+
DESTINATION "${INSTALL_DIR_LIB}/pkgconfig/")
7171
endif()
7272

7373
# Package builders

pkg/ipfixcol2.pc.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
prefix=@CMAKE_INSTALL_PREFIX@
2-
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
1+
includedir=@INSTALL_DIR_INCLUDE@
32

43
Name: @PROJECT_NAME@
54
Description: @IPFIXCOL_DESCRIPTION@

src/build_config.h.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@
6868

6969
/** \brief Path to the directory with configuration */
7070
#define IPX_DEFAULT_CONFIG_DIR \
71-
"@CMAKE_INSTALL_FULL_SYSCONFDIR@/ipfixcol2/"
71+
"@INSTALL_DIR_SYSCONF@/ipfixcol2/"
7272
/** \brief Path to default (if not specified) user configuration file */
7373
#define IPX_DEFAULT_STARTUP_CONFIG \
7474
IPX_DEFAULT_CONFIG_DIR "startup.xml"
7575
/** \brief Path to the directory with plugins */
7676
#define IPX_DEFAULT_PLUGINS_DIR \
77-
"@CMAKE_INSTALL_FULL_LIBDIR@/ipfixcol2/"
77+
"@INSTALL_DIR_LIB@/ipfixcol2/"
7878

7979
/** \brief Compiler name and version */
8080
#define IPX_BUILD_COMPILER \

src/plugins/input/dummy/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ add_library(dummy-input MODULE
77

88
install(
99
TARGETS dummy-input
10-
LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/ipfixcol2/"
11-
)
10+
LIBRARY DESTINATION "${INSTALL_DIR_LIB}/ipfixcol2/"
11+
)

src/plugins/input/tcp/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_library(tcp-input MODULE
77

88
install(
99
TARGETS tcp-input
10-
LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/ipfixcol2/"
10+
LIBRARY DESTINATION "${INSTALL_DIR_LIB}/ipfixcol2/"
1111
)
1212

1313
if (ENABLE_DOC_MANPAGE)
@@ -23,6 +23,6 @@ if (ENABLE_DOC_MANPAGE)
2323

2424
install(
2525
FILES "${DST_FILE}"
26-
DESTINATION "${CMAKE_INSTALL_FULL_MANDIR}/man7"
26+
DESTINATION "${INSTALL_DIR_MAN}/man7"
2727
)
28-
endif()
28+
endif()

src/plugins/input/udp/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_library(udp-input MODULE
77

88
install(
99
TARGETS udp-input
10-
LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/ipfixcol2/"
10+
LIBRARY DESTINATION "${INSTALL_DIR_LIB}/ipfixcol2/"
1111
)
1212

1313
if (ENABLE_DOC_MANPAGE)
@@ -23,6 +23,6 @@ if (ENABLE_DOC_MANPAGE)
2323

2424
install(
2525
FILES "${DST_FILE}"
26-
DESTINATION "${CMAKE_INSTALL_FULL_MANDIR}/man7"
26+
DESTINATION "${INSTALL_DIR_MAN}/man7"
2727
)
28-
endif()
28+
endif()

src/plugins/intermediate/anonymization/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ add_library(anonymization-intermediate MODULE
1111

1212
install(
1313
TARGETS anonymization-intermediate
14-
LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/ipfixcol2/"
14+
LIBRARY DESTINATION "${INSTALL_DIR_LIB}/ipfixcol2/"
1515
)
1616

1717
if (ENABLE_DOC_MANPAGE)
@@ -27,6 +27,6 @@ if (ENABLE_DOC_MANPAGE)
2727

2828
install(
2929
FILES "${DST_FILE}"
30-
DESTINATION "${CMAKE_INSTALL_FULL_MANDIR}/man7"
30+
DESTINATION "${INSTALL_DIR_MAN}/man7"
3131
)
32-
endif()
32+
endif()

src/plugins/output/dummy/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_library(dummy-output MODULE
77

88
install(
99
TARGETS dummy-output
10-
LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/ipfixcol2/"
10+
LIBRARY DESTINATION "${INSTALL_DIR_LIB}/ipfixcol2/"
1111
)
1212

1313
if (ENABLE_DOC_MANPAGE)
@@ -23,6 +23,6 @@ if (ENABLE_DOC_MANPAGE)
2323

2424
install(
2525
FILES "${DST_FILE}"
26-
DESTINATION "${CMAKE_INSTALL_FULL_MANDIR}/man7"
26+
DESTINATION "${INSTALL_DIR_MAN}/man7"
2727
)
28-
endif()
28+
endif()

0 commit comments

Comments
 (0)