Module: kamailio
Branch: master
Commit: abb4a6a195995901294bae105355a3414edaf05c
URL: 
https://github.com/kamailio/kamailio/commit/abb4a6a195995901294bae105355a3414edaf05c

Author: Xenofon Karamanos <x...@gilawa.com>
Committer: Xenofon Karamanos <x...@gilawa.com>
Date: 2025-01-10T14:38:24Z

cmake/tls: Add targets for installing cfg and cert

---

Modified: src/modules/tls/CMakeLists.txt

---

Diff:  
https://github.com/kamailio/kamailio/commit/abb4a6a195995901294bae105355a3414edaf05c.diff
Patch: 
https://github.com/kamailio/kamailio/commit/abb4a6a195995901294bae105355a3414edaf05c.patch

---

diff --git a/src/modules/tls/CMakeLists.txt b/src/modules/tls/CMakeLists.txt
index 84c1110d9eb..b9c6d1dd0f2 100644
--- a/src/modules/tls/CMakeLists.txt
+++ b/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})

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to