@@ -93,9 +93,9 @@ if(WIN32)
9393 )
9494 set (VSTUDIO_EXPRESS ON )
9595 endif (FOUND_ATL )
96- else ()
97- set (CMAKE_INSTALL_PREFIX "usr" )
9896endif ()
97+ # On Linux/macOS CMAKE_INSTALL_PREFIX is honoured (GNU default /usr/local).
98+ # Distribution package builds pass -DCMAKE_INSTALL_PREFIX=/usr explicitly;
9999
100100set (BUILD_PYTHON_FOLDER "${CMAKE_SOURCE_DIR } /build/python" )
101101set (BUILD_CMAKE_FOLDER "${CMAKE_SOURCE_DIR } /build/cmake" )
@@ -123,6 +123,79 @@ set(BIN_TARGET_FOLDER usr/bin)
123123set (LOG_TARGET_FOLDER var/log)
124124set (ETC_TARGET_FOLDER etc)
125125
126+ # ##############################################################################
127+ #
128+ # Linux install layout (GNUInstallDirs)
129+ #
130+ # These NSCP_* variables are the single source of truth for where the daemon,
131+ # its private libraries, modules, data, config, state and logs are installed
132+ # AND for the runtime defaults baked into config.h, so the same value drives
133+ # both the install(...) rules and the path_manager runtime defaults.
134+ #
135+ # Everything derives from CMAKE_INSTALL_PREFIX via GNUInstallDirs, so the same
136+ # source tree honours --prefix=/usr, /usr/local, /opt/nsclient, ... without a
137+ # recompile. GNUInstallDirs handles the FHS quirk where --prefix=/usr redirects
138+ # SYSCONFDIR to /etc and LOCALSTATEDIR to /var.
139+ #
140+ # Windows keeps the existing exe-relative model and never sees these.
141+ #
142+ # ##############################################################################
143+ if (NOT WIN32 )
144+ include (GNUInstallDirs )
145+
146+ set (NSCP_SBINDIR "${CMAKE_INSTALL_FULL_SBINDIR} " )
147+ set (NSCP_BINDIR "${CMAKE_INSTALL_FULL_BINDIR} " )
148+
149+ # NSCP_LIBDIR is the base for NSCP_PKGLIBDIR only - nothing installs into it
150+ # directly. It deliberately uses a plain "<prefix>/lib" rather than
151+ # CMAKE_INSTALL_FULL_LIBDIR: on Debian/Ubuntu the latter expands to the
152+ # multiarch path (/usr/lib/<triplet>), and putting our private libraries +
153+ # modules there is exactly what makes dpkg/lintian treat them as public
154+ # (SONAME deps, shlibs/symbols, -dev split, ldconfig triggers). The project
155+ # ships no public ABI, so the libraries live in a package-private
156+ # "<prefix>/lib/nsclient" off the default loader path. See the RPATH set in
157+ # NSCP_MAKE_LIBRARY / NSCP_INSTALL_MODULE.
158+ set (NSCP_LIBDIR "${CMAKE_INSTALL_PREFIX } /lib" )
159+ set (NSCP_PKGLIBDIR "${NSCP_LIBDIR} /nsclient" )
160+
161+ set (NSCP_PKGDATADIR "${CMAKE_INSTALL_FULL_DATAROOTDIR} /nsclient" )
162+ set (NSCP_SYSCONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR} " )
163+ set (NSCP_PKGSYSCONFDIR "${NSCP_SYSCONFDIR} /nsclient" )
164+ set (NSCP_PKGSTATEDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR} /lib/nsclient" )
165+ set (NSCP_LOGDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR} /log/nsclient" )
166+
167+ # systemd system unit directory. Defaults to the historical
168+ # /lib/systemd/system; a packager who wants the pkg-config-reported
169+ # location passes
170+ # -DNSCP_SYSTEMD_UNITDIR=$(pkg-config systemd --variable=systemdsystemunitdir)
171+ if (NOT NSCP_SYSTEMD_UNITDIR)
172+ set (NSCP_SYSTEMD_UNITDIR "/lib/systemd/system" )
173+ endif ()
174+
175+ # Map the historical *_TARGET_FOLDER install-destination variables (defined
176+ # above as Windows/fallback defaults) onto the prefix-derived NSCP_* values.
177+ # These are absolute now, so they ignore CMAKE_INSTALL_PREFIX at install
178+ # time - which is correct, the prefix is already baked into NSCP_*.
179+ set (MODULE_TARGET_FOLDER "${NSCP_PKGLIBDIR} /modules" )
180+ set (LIB_TARGET_FOLDER "${NSCP_PKGLIBDIR} " ) # Phase 2b: private libs next to modules
181+ set (SYSTEMD_TARGET_FOLDER "${NSCP_SYSTEMD_UNITDIR} " )
182+ set (SBIN_TARGET_FOLDER "${NSCP_SBINDIR} " )
183+ set (BIN_TARGET_FOLDER "${NSCP_BINDIR} " )
184+ set (LOG_TARGET_FOLDER "${NSCP_LOGDIR} " )
185+ set (ETC_TARGET_FOLDER "${NSCP_SYSCONFDIR} " )
186+
187+ # $ORIGIN-relative RPATHs so the private libraries resolve regardless of
188+ # prefix. Executables derive theirs per-target in NSCP_MAKE_EXE (sbin and
189+ # bin are both one level under the prefix). Modules live in
190+ # NSCP_PKGLIBDIR/modules, so the libraries sit one dir up.
191+ set (NSCP_RPATH_MODULE "$ORIGIN/.." )
192+ # The private libraries are co-located in NSCP_PKGLIBDIR; their inter-deps
193+ # resolve via $ORIGIN. This is required because modern toolchains emit
194+ # DT_RUNPATH (not the deprecated, transitive DT_RPATH), so each object must
195+ # carry an RPATH covering its own direct dependencies.
196+ set (NSCP_RPATH_LIB "$ORIGIN" )
197+ endif ()
198+
126199set (NSCP_GLOBAL_DEFINES
127200 ${NSCP_GLOBAL_DEFINES}
128201 -DBOOST_PHOENIX_STL_TUPLE_H_
@@ -806,15 +879,24 @@ if(WIN32)
806879 "PAth for log file"
807880 )
808881else ()
809- set (INSTALL_FILES_BASE "usr/lib/nsclient/" )
810-
811- set (CONFIG_DEFAULT_CONFIG_FOLDER
812- "/etc/nsclient"
813- CACHE STRING
814- "Base location for ini files"
815- )
816-
817- set (CONFIG_BOOT_CONF_LOCATION "${CONFIG_DEFAULT_CONFIG_FOLDER} /boot.ini" )
882+ # Files installed via copy_single_file() land under the package-private
883+ # shared dir (NSCP_PKGLIBDIR, e.g. /usr/lib/nsclient). This is also what
884+ # ${shared-path} resolves to at runtime, so scripts/web/security stay where
885+ # the daemon looks for them.
886+ set (INSTALL_FILES_BASE "${NSCP_PKGLIBDIR} /" )
887+
888+ # Absolute, prefix-dependent values. These are intentionally NOT CACHE
889+ # variables: GNUInstallDirs already gives packagers the override knobs
890+ # (CMAKE_INSTALL_SYSCONFDIR, ...), and caching would pin a value from a
891+ # previous configure so it could no longer track CMAKE_INSTALL_PREFIX.
892+ set (CONFIG_DEFAULT_CONFIG_FOLDER "${NSCP_PKGSYSCONFDIR} " )
893+
894+ # boot.ini's location is now a path_manager token (${boot-conf}) so an
895+ # operator can relocate it with --path-override boot-conf=... . The token's
896+ # default (NSCP_PKGSYSCONFDIR/boot.ini) is registered in path_manager.
897+ # Escaped so configure_file(@ONLY) emits the literal token, not an empty
898+ # CMake expansion.
899+ set (CONFIG_BOOT_CONF_LOCATION "\$ {boot-conf}" )
818900 set (CONFIG_DEFAULT_CONF_LOCATION
819901 "ini"
820902 CACHE STRING
@@ -826,16 +908,9 @@ else()
826908 CACHE STRING
827909 "modules folder"
828910 )
829- set (UNIX_SHARED_PATH_FOLDER
830- "/usr/lib/nsclient"
831- CACHE STRING
832- "Shared files on linux"
833- )
834- set (UNIX_DATA_PATH_FOLDER
835- "/var/lib/nsclient"
836- CACHE STRING
837- "Data path on linux"
838- )
911+ set (UNIX_SHARED_PATH_FOLDER "${NSCP_PKGLIBDIR} " )
912+ set (UNIX_DATA_PATH_FOLDER "${NSCP_PKGSTATEDIR} " )
913+ set (CONFIG_ETC_FOLDER "${NSCP_SYSCONFDIR} " )
839914 set (CONFIG_WEB_FOLDER "\$ {shared-path}/web" CACHE STRING "web folder" )
840915 set (CONFIG_SCRIPTS_FOLDER
841916 "\$ {shared-path}/scripts"
@@ -1204,25 +1279,57 @@ else()
12041279 option (USE_SYSTEMD "Install systemd service files" ON )
12051280 option (USE_INITD "Install legacy init.d scripts" OFF )
12061281
1282+ # Install destinations are absolute (prefix-derived NSCP_* values), so the
1283+ # CPack staging prefix must be the filesystem root - it is only consulted
1284+ # for relative destinations, of which we now have none.
12071285 set (CPACK_PACKAGING_INSTALL_PREFIX "/" )
12081286
1287+ # The maintainer scripts and conffiles reference install paths, so they are
1288+ # templated through configure_file with the NSCP_* values rather than baked
1289+ # to /usr. (prerm touches no paths, so it ships verbatim.)
1290+ configure_file (
1291+ ${CMAKE_CURRENT_SOURCE_DIR } /files/deb/postinst.in
1292+ ${PROJECT_BINARY_DIR } /files/deb/postinst
1293+ @ONLY
1294+ )
1295+ configure_file (
1296+ ${CMAKE_CURRENT_SOURCE_DIR } /files/deb/postrm.in
1297+ ${PROJECT_BINARY_DIR } /files/deb/postrm
1298+ @ONLY
1299+ )
1300+ configure_file (
1301+ ${CMAKE_CURRENT_SOURCE_DIR } /files/deb/conffiles.in
1302+ ${PROJECT_BINARY_DIR } /files/deb/conffiles
1303+ @ONLY
1304+ )
1305+ configure_file (
1306+ ${CMAKE_CURRENT_SOURCE_DIR } /files/rpm/postinstall.sh.in
1307+ ${PROJECT_BINARY_DIR } /files/rpm/postinstall.sh
1308+ @ONLY
1309+ )
1310+ configure_file (
1311+ ${CMAKE_CURRENT_SOURCE_DIR } /files/rpm/preuninstall.sh.in
1312+ ${PROJECT_BINARY_DIR } /files/rpm/preuninstall.sh
1313+ @ONLY
1314+ )
1315+
12091316 set (CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
1210- "${CMAKE_CURRENT_SOURCE_DIR } /files/deb/postinst;${CMAKE_CURRENT_SOURCE_DIR } /files/deb/prerm;${CMAKE_CURRENT_SOURCE_DIR } /files/deb/postrm;${CMAKE_CURRENT_SOURCE_DIR } /files/deb/conffiles"
1317+ "${PROJECT_BINARY_DIR } /files/deb/postinst;${CMAKE_CURRENT_SOURCE_DIR } /files/deb/prerm;${PROJECT_BINARY_DIR } /files/deb/postrm;${PROJECT_BINARY_DIR } /files/deb/conffiles"
12111318 )
12121319 set (CPACK_RPM_POST_INSTALL_SCRIPT_FILE
1213- "${CMAKE_CURRENT_SOURCE_DIR } /files/rpm/postinstall.sh"
1320+ "${PROJECT_BINARY_DIR } /files/rpm/postinstall.sh"
12141321 )
12151322 set (CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE
1216- "${CMAKE_CURRENT_SOURCE_DIR } /files/rpm/preuninstall.sh"
1323+ "${PROJECT_BINARY_DIR } /files/rpm/preuninstall.sh"
12171324 )
12181325
12191326 set (CPACK_RPM_PACKAGE_CONFIG_FILES
1220- "/etc/nsclient /boot.ini"
1221- "/etc/nsclient /nsclient.ini"
1327+ "${NSCP_PKGSYSCONFDIR} /boot.ini"
1328+ "${NSCP_PKGSYSCONFDIR} /nsclient.ini"
12221329 )
12231330
12241331 # Ensure empty directories are included in the RPM
1225- set (CPACK_RPM_USER_FILELIST "%dir /var/log/nsclient " )
1332+ set (CPACK_RPM_USER_FILELIST "%dir ${NSCP_LOGDIR} " )
12261333
12271334 set (CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
12281335 "/bin"
0 commit comments