Browse Source

cmake: Add install targets for missing configuration files

- tls: Add comment and use the --install for the install target like the rest
- auth_radius: Add dictionary installation
- xhttp_pi: Add pi_framework.xml
Xenofon Karamanos 8 months ago
parent
commit
b5b40ef619

+ 28 - 0
src/modules/auth_radius/CMakeLists.txt

@@ -5,3 +5,31 @@ add_library(${module_name} SHARED ${MODULE_SOURCES})
 find_package(Radius REQUIRED)
 
 target_compile_definitions(${module_name} PRIVATE ${RADIUSCLIENT_LIB})
+
+# Install the configuration file (tls.cfg) using a CODE block to check
+# existence at install time instead of configure time
+install(
+  CODE "
+    set(dir \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_SYSCONFDIR}/${MAIN_NAME}\")
+    set(file \"dictionary.${CFG_NAME}\")
+    if(EXISTS \"\${dir}/\${file}\")
+        message(STATUS \"\${file} already exists in \${dir}/\${file}.
+          Installing as \${file}.sample\")
+        file(INSTALL \"${CMAKE_CURRENT_SOURCE_DIR}/cfg/\${file}\"
+          DESTINATION \"${CMAKE_INSTALL_FULL_SYSCONFDIR}/${MAIN_NAME}\"
+          RENAME \"\${file}.sample\"
+          PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+        )
+    else()
+        file(INSTALL \"${CMAKE_CURRENT_SOURCE_DIR}/cfg/\${file}\"
+            DESTINATION \"${CMAKE_INSTALL_FULL_SYSCONFDIR}/${MAIN_NAME}\"
+            PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
+    endif()
+"
+  COMPONENT ${module_name}-cfg)
+
+add_custom_target(
+  ${module_name}-install-cfg
+  COMMENT "Installing auth_radius dictionary.${CFG_NAME} configuration file"
+  COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --component
+          ${module_name}-cfg)

+ 3 - 3
src/modules/tls/CMakeLists.txt

@@ -74,8 +74,7 @@ add_custom_target(tls_cfg_sample ALL DEPENDS tls.cfg.sample)
 
 add_custom_target(
   tls-install-cfg
-  COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/tls.cfg.sample
-          ${CMAKE_INSTALL_FULL_SYSCONFDIR}/${MAIN_NAME}
+  COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --component tls-cfg
   COMMENT "Installing tls.cfg.sample to ${MAIN_NAME} config directory")
 add_dependencies(tls-install-cfg tls_cfg_sample)
 
@@ -84,4 +83,5 @@ add_custom_target(
   tls-install-cert
   COMMAND ${CMAKE_COMMAND} -E env MAIN_NAME=${MAIN_NAME} ./tls_cert.sh -d
           ${CMAKE_INSTALL_FULL_SYSCONFDIR}
-  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+  COMMENT "Generating self-signed certificates for ${MAIN_NAME}")

+ 28 - 0
src/modules/xhttp_pi/CMakeLists.txt

@@ -5,3 +5,31 @@ add_library(${module_name} SHARED ${MODULE_SOURCES})
 find_package(LibXml2 REQUIRED)
 
 target_link_libraries(${module_name} PRIVATE LibXml2::LibXml2)
+
+# Install the configuration file (tls.cfg) using a CODE block to check
+# existence at install time instead of configure time
+install(
+  CODE "
+    set(dir \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_SYSCONFDIR}/${MAIN_NAME}\")
+    set(file \"pi_framework.xml\")
+    if(EXISTS \"\${dir}/\${file}\")
+        message(STATUS \"\${file} already exists in \${dir}/\${file}.
+          Installing as \${file}.sample\")
+        file(INSTALL \"${CMAKE_SOURCE_DIR}/misc/examples/pi_framework/\${file}\"
+          DESTINATION \"${CMAKE_INSTALL_FULL_SYSCONFDIR}/${MAIN_NAME}\"
+          RENAME \"\${file}.sample\"
+          PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+        )
+    else()
+        file(INSTALL \"${CMAKE_SOURCE_DIR}/misc/examples/pi_framework/\${file}\"
+            DESTINATION \"${CMAKE_INSTALL_FULL_SYSCONFDIR}/${MAIN_NAME}\"
+            PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
+    endif()
+"
+  COMPONENT xhttp_pi-cfg)
+
+add_custom_target(
+  xhttp_pi-install-cfg
+  COMMENT "Installing pi_framework.xml"
+  COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --component
+          xhttp_pi-cfg)