1# Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2# file Copyright.txt or https://cmake.org/licensing for details. 3 4#[=======================================================================[.rst: 5CPackIFWConfigureFile 6--------------------- 7 8.. versionadded:: 3.8 9 10The module defines :command:`configure_file` similar command to 11configure file templates prepared in QtIFW/SDK/Creator style. 12 13 14Commands 15^^^^^^^^ 16 17The module defines the following commands: 18 19.. command:: cpack_ifw_configure_file 20 21 Copy a file to another location and modify its contents. 22 23 :: 24 25 cpack_ifw_configure_file(<input> <output>) 26 27 Copies an ``<input>`` file to an ``<output>`` file and substitutes variable 28 values referenced as ``%{VAR}`` or ``%VAR%`` in the input file content. 29 Each variable reference will be replaced with the current value of the 30 variable, or the empty string if the variable is not defined. 31 32#]=======================================================================] 33 34# NOTE: This file used to himself packaging via CPack IFW generator and 35# should be compatible with minimal CMake version defined in 36# ../CMakeLists.txt file. 37 38if(NOT DEFINED CPackIFWConfigureFile_CMake_INCLUDED) 39set(CPackIFWConfigureFile_CMake_INCLUDED 1) 40 41macro(cpack_ifw_configure_file INPUT OUTPUT) 42 file(READ "${INPUT}" _tmp) 43 foreach(_tmp_regex "%{([^%}]+)}" "%([^%]+)%") 44 string(REGEX MATCHALL "${_tmp_regex}" _tmp_vars "${_tmp}") 45 while(_tmp_vars) 46 foreach(_tmp_var ${_tmp_vars}) 47 string(REGEX REPLACE "${_tmp_regex}" "\\1" 48 _tmp_var_name "${_tmp_var}") 49 if(DEFINED ${_tmp_var_name}) 50 set(_tmp_var_value "${${_tmp_var_name}}") 51 elseif(NOT "$ENV{${_tmp_var_name}}" STREQUAL "") 52 set(_tmp_var_value "$ENV{${_tmp_var_name}}") 53 else() 54 set(_tmp_var_value "") 55 endif() 56 string(REPLACE "${_tmp_var}" "${_tmp_var_value}" _tmp "${_tmp}") 57 endforeach() 58 string(REGEX MATCHALL "${_tmp_regex}" _tmp_vars "${_tmp}") 59 endwhile() 60 endforeach() 61 if(IS_ABSOLUTE "${OUTPUT}") 62 file(WRITE "${OUTPUT}" "${_tmp}") 63 else() 64 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT}" "${_tmp}") 65 endif() 66endmacro() 67 68endif() # NOT DEFINED CPackIFWConfigureFile_CMake_INCLUDED 69