This is an automated email from the ASF dual-hosted git repository.

cmcfarlen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new ad1f7c29b1 cmake: improve installing config files (#10136)
ad1f7c29b1 is described below

commit ad1f7c29b1b9c88d89ba36808ceb8fd6e687b149
Author: Chris McFarlen <ch...@mcfarlen.us>
AuthorDate: Fri Aug 4 09:45:02 2023 -0500

    cmake: improve installing config files (#10136)
    
    * cmake: improve installing config files
    
    * PR Cleanup
    
    * improve comments to try to be more clear what is going on installing 
config files
    
    ---------
    
    Co-authored-by: Chris McFarlen <cmcfar...@apple.com>
---
 cmake/install_configs.cmake | 34 ++++++++++++++++++++++++++++++++++
 configs/CMakeLists.txt      | 35 ++++++++++++++++-------------------
 2 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/cmake/install_configs.cmake b/cmake/install_configs.cmake
new file mode 100644
index 0000000000..f53ef6b984
--- /dev/null
+++ b/cmake/install_configs.cmake
@@ -0,0 +1,34 @@
+#######################
+#
+#  Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+#  agreements.  See the NOTICE file distributed with this work for additional 
information regarding
+#  copyright ownership.  The ASF licenses this file to you under the Apache 
License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with the 
License.  You may obtain
+#  a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software 
distributed under the License
+#  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+#  or implied. See the License for the specific language governing permissions 
and limitations under
+#  the License.
+#
+#######################
+
+# This is a script intended to be passed to install(SCRIPT ...)
+# This copies default config files to the destination without overwriting 
existing files.
+# If the config file doesn't exist, the source config file is copied  without 
the '.default' extension
+# If the config file already exists, the source config file is copied with the 
'.default' extension
+
+file(GLOB CONFIG_FILES ${CONFIG_SOURCE_GLOBS})
+file(MAKE_DIRECTORY ${CONFIG_DEST_PATH})
+foreach(CONFIG_FILE ${CONFIG_FILES})
+  # remove the '.default' extension from the path
+  cmake_path(GET CONFIG_FILE STEM LAST_ONLY CONFIG_FILE_NAME)
+  set(DEST_FILE "${CONFIG_DEST_PATH}/${CONFIG_FILE_NAME}")
+  if (EXISTS ${DEST_FILE})
+    set(DEST_FILE "${DEST_FILE}.default")
+  endif()
+  message(STATUS "Installing config: ${DEST_FILE}")
+  file(COPY_FILE ${CONFIG_FILE} ${DEST_FILE})
+endforeach()
diff --git a/configs/CMakeLists.txt b/configs/CMakeLists.txt
index 56bf5b4ae3..438d2372be 100644
--- a/configs/CMakeLists.txt
+++ b/configs/CMakeLists.txt
@@ -1,28 +1,25 @@
-# Makefile.am for config
+#######################
 #
-#  Licensed to the Apache Software Foundation (ASF) under one
-#  or more contributor license agreements.  See the NOTICE file
-#  distributed with this work for additional information
-#  regarding copyright ownership.  The ASF licenses this file
-#  to you under the Apache License, Version 2.0 (the
-#  "License"); you may not use this file except in compliance
-#  with the License.  You may obtain a copy of the License at
+#  Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+#  agreements.  See the NOTICE file distributed with this work for additional 
information regarding
+#  copyright ownership.  The ASF licenses this file to you under the Apache 
License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with the 
License.  You may obtain
+#  a copy of the License at
 #
 #      http://www.apache.org/licenses/LICENSE-2.0
 #
-#  Unless required by applicable law or agreed to in writing, software
-#  distributed under the License is distributed on an "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#  See the License for the specific language governing permissions and
-#  limitations under the License.
-
-file(GLOB CONFIG_FILES *.default ${CMAKE_BINARY_DIR}/configs/*.default)
+#  Unless required by applicable law or agreed to in writing, software 
distributed under the License
+#  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+#  or implied. See the License for the specific language governing permissions 
and limitations under
+#  the License.
+#
+#######################
 
-foreach(CONFIG_FILE ${CONFIG_FILES})
-  cmake_path(GET CONFIG_FILE STEM LAST_ONLY CONFIG_FILE_NAME)
-  install(FILES ${CONFIG_FILE} DESTINATION etc/trafficserver RENAME 
${CONFIG_FILE_NAME})
-endforeach()
+# This is odd but seems to be the idiomatic way to pass arguments to install 
scripts
+install(CODE "set(CONFIG_SOURCE_GLOBS 
\"${CMAKE_BINARY_DIR}/configs/*.default\" 
\"${CMAKE_SOURCE_DIR}/configs/*.default\")")
+install(CODE "set(CONFIG_DEST_PATH 
\"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/etc/trafficserver\")")
 
+install(SCRIPT ${CMAKE_SOURCE_DIR}/cmake/install_configs.cmake)
 
 file(GLOB BODY_FACTORY_FILES body_factory/default/*)
 list(FILTER BODY_FACTORY_FILES EXCLUDE REGEX Makefile.*)

Reply via email to