ConfigureIncludeFiles.cmake
Go to the documentation of this file.
1 # ============================================================================
2 # Copyright (c) 2011-2012 University of Pennsylvania
3 # Copyright (c) 2013-2016 Andreas Schuh
4 # All rights reserved.
5 #
6 # See COPYING file for license information or visit
7 # https://cmake-basis.github.io/download.html#license
8 # ============================================================================
9 
10 ##############################################################################
11 # @file ConfigureIncludeFiles.cmake
12 # @brief CMake script used to configure and copy the public header files.
13 #
14 # Besides configuring the files, this script optionally copies the header
15 # files to the build tree using the final relative path as used for the
16 # installation. This could be done directly during the configure step of
17 # CMake by code executed as part of the CMakeLists.txt files, but then
18 # whenever a header file is modified, CMake reconfigures the build system.
19 # Instead, this script is executed using execute_process() during the
20 # configure step of CMake and a custom build target is added which rebuilds
21 # whenever a header file was modified. Thus, only this script is re-executed,
22 # but not the entire build system re-configured.
23 #
24 # The relative path of each configured input header file in the source tree
25 # is appended to the output log file. This file can be used to determine
26 # whether a new header was added to the source tree and thus this script has
27 # to be re-executed.
28 #
29 # @ingroup CMakeUtilities
30 ##############################################################################
31 
32 # ----------------------------------------------------------------------------
33 # requires bug fixed get_filename_component() of BASIS tools
34 include ("${CMAKE_CURRENT_LIST_DIR}/CommonTools.cmake")
35 
36 # ----------------------------------------------------------------------------
37 # check arguments
38 if (NOT PROJECT_INCLUDE_DIRS)
39  message (FATAL_ERROR "Missing argument PROJECT_INCLUDE_DIRS!")
40 endif ()
41 
43  message (FATAL_ERROR "Missing argument BINARY_INCLUDE_DIR!")
44 endif ()
45 
46 if (NOT EXTENSIONS)
47  message (FATAL_ERROR "Missing argument EXTENSIONS!")
48 endif ()
49 
50 if (NOT VARIABLE_NAME)
51  set (VARIABLE_NAME "PUBLIC_HEADERS")
52 endif ()
53 
54 if (NOT COPY_MODE)
55  set (COPY_MODE COPYONLY)
56 endif ()
57 
58 # ----------------------------------------------------------------------------
59 # include file which defines CMake variables for use in .h.in files
60 if (CACHE_FILE)
61  include ("${CACHE_FILE}")
62 endif ()
63 
64 # ----------------------------------------------------------------------------
65 # configure header files
66 foreach (INCLUDE_DIR IN LISTS PROJECT_INCLUDE_DIRS)
67  foreach (E IN LISTS EXTENSIONS)
68  list (APPEND PATTERN "${INCLUDE_DIR}/*${E}")
69  endforeach ()
70  file (GLOB_RECURSE FILES RELATIVE "${INCLUDE_DIR}" ${PATTERN})
71  foreach (HEADER IN LISTS FILES)
72  get_filename_component (SOURCE "${INCLUDE_DIR}/${HEADER}" ABSOLUTE)
73  if (NOT PREVIEW AND HEADER MATCHES "\\.in$")
74  string (REGEX REPLACE "\\.in$" "" HEADER "${HEADER}")
75  configure_file ("${SOURCE}" "${BINARY_INCLUDE_DIR}/${HEADER}" ${COPY_MODE})
76  endif ()
77  list (APPEND CONFIGURED_HEADERS "${SOURCE}")
78  endforeach ()
79 endforeach ()
80 
81 # ----------------------------------------------------------------------------
82 # write CMake script with list of public header files
83 if (CMAKE_FILE)
84  if (_CONFIGURED_HEADERS)
85  list (SORT _CONFIGURED_HEADERS) # deterministic order
86  endif ()
87  file (WRITE "${CMAKE_FILE}" "# Automatically generated by BASIS. DO NOT edit this file!\nset (${VARIABLE_NAME}\n")
88  foreach (HEADER IN LISTS CONFIGURED_HEADERS)
89  file (APPEND "${CMAKE_FILE}" " \"${HEADER}\"\n")
90  endforeach ()
91  file (APPEND "${CMAKE_FILE}" ")\n")
92 endif ()
cmake COPY_MODE
cmake PROJECT_INCLUDE_DIRS
Absolute paths to directories of public header files in source tree.
cmake BINARY_INCLUDE_DIR
Absolute path to output directory for configured public header files.
cmake VARIABLE_NAME
if(oldcoutbuf)