Răsfoiți Sursa

cmake/tls: Add targets for installing cfg and cert

Xenofon Karamanos 8 luni în urmă
părinte
comite
abb4a6a195
1 a modificat fișierele cu 46 adăugiri și 2 ștergeri
  1. 46 2
      src/modules/tls/CMakeLists.txt

+ 46 - 2
src/modules/tls/CMakeLists.txt

@@ -38,6 +38,50 @@ else()
                                                ZLIB::ZLIB Threads::Threads)
 endif()
 
-# target_link_libraries(${module_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
+# 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 \"tls.cfg\")
+    if(EXISTS \"\${dir}/\${file}\")
+        message(STATUS \"\${file} already exists in \${dir}/\${file}.
+          Installing as \${file}.sample\")
+        file(INSTALL \"${CMAKE_CURRENT_SOURCE_DIR}/\${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}/\${file}\"
+            DESTINATION \"${CMAKE_INSTALL_FULL_SYSCONFDIR}/${MAIN_NAME}\"
+            PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
+    endif()
+"
+  COMPONENT tls-cfg)
 
-# TODO: Install files such as cfg and modify it with sed and certs
+add_custom_command(
+  OUTPUT tls.cfg.sample
+  COMMAND
+    sed -e "s#\/usr/local/etc/kamailio/#${CMAKE_INSTALL_FULL_SYSCONFDIR}#g" -e
+    "s#kamailio-selfsigned#${MAIN_NAME}-selfsigned#g" < tls.cfg >
+    ${CMAKE_CURRENT_BINARY_DIR}/tls.cfg.sample
+  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+
+# Always build/generate tls.cfg.sample in the build directory
+# This is needed for the default install target to pick it up
+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}
+  COMMENT "Installing tls.cfg.sample to ${MAIN_NAME} config directory")
+add_dependencies(tls-install-cfg tls_cfg_sample)
+
+# Add tls-cert target
+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})