BASIS  r3148
ConfigureIncludeFiles.cmake
Go to the documentation of this file.
00001 ##############################################################################
00002 # @file  ConfigureIncludeFiles.cmake
00003 # @brief CMake script used to configure and copy the public header files.
00004 #
00005 # Besides configuring the files, this script optionally copies the header
00006 # files to the build tree using the final relative path as used for the
00007 # installation. This could be done directly during the configure step of
00008 # CMake by code executed as part of the CMakeLists.txt files, but then
00009 # whenever a header file is modified, CMake reconfigures the build system.
00010 # Instead, this script is executed using execute_process() during the
00011 # configure step of CMake and a custom build target is added which rebuilds
00012 # whenever a header file was modified. Thus, only this script is re-executed,
00013 # but not the entire build system re-configured.
00014 #
00015 # The relative path of each configured input header file in the source tree
00016 # is appended to the output log file. This file can be used to determine
00017 # whether a new header was added to the source tree and thus this script has
00018 # to be re-executed.
00019 #
00020 # Copyright (c) 2011, 2012 University of Pennsylvania. All rights reserved.<br />
00021 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.
00022 #
00023 # Contact: SBIA Group <sbia-software at uphs.upenn.edu>
00024 #
00025 # @ingroup CMakeUtilities
00026 ##############################################################################
00027 
00028 # ----------------------------------------------------------------------------
00029 # requires bug fixed get_filename_component() of BASIS tools
00030 include ("${CMAKE_CURRENT_LIST_DIR}/CommonTools.cmake")
00031 
00032 # ----------------------------------------------------------------------------
00033 # check arguments
00034 if (NOT PROJECT_INCLUDE_DIRS)
00035   message (FATAL_ERROR "Missing argument PROJECT_INCLUDE_DIR!")
00036 endif ()
00037 
00038 if (NOT BINARY_INCLUDE_DIR)
00039   message (FATAL_ERROR "Missing argument BINARY_INCLUDE_DIR!")
00040 endif ()
00041 
00042 if (NOT EXTENSIONS)
00043   message (FATAL_ERROR "Missing argument EXTENSIONS!")
00044 endif ()
00045 
00046 if (NOT VARIABLE_NAME)
00047   set (VARIABLE_NAME "PUBLIC_HEADERS")
00048 endif ()
00049 
00050 # ----------------------------------------------------------------------------
00051 # include file which defines CMake variables for use in .h.in files
00052 if (CACHE_FILE)
00053   include ("${CACHE_FILE}")
00054 endif ()
00055 
00056 # ----------------------------------------------------------------------------
00057 # configure header files
00058 set (CONFIGURED_HEADERS)
00059 foreach (INCLUDE_DIR IN LISTS PROJECT_INCLUDE_DIRS)
00060   set (PATTERN)
00061   foreach (E IN LISTS EXTENSIONS)
00062     list (APPEND PATTERN "${INCLUDE_DIR}/*${E}.in")
00063   endforeach ()
00064   foreach (E IN LISTS EXTENSIONS)
00065     list (APPEND PATTERN "${INCLUDE_DIR}/*${E}")
00066   endforeach ()
00067   file (GLOB_RECURSE FILES RELATIVE "${INCLUDE_DIR}" ${PATTERN})
00068   foreach (HEADER IN LISTS FILES)
00069     get_filename_component (SOURCE "${INCLUDE_DIR}/${HEADER}" ABSOLUTE)
00070     if (NOT PREVIEW AND HEADER MATCHES "\\.in$")
00071       string (REGEX REPLACE "\\.in$" "" HEADER "${HEADER}")
00072       configure_file ("${SOURCE}" "${BINARY_INCLUDE_DIR}/${HEADER}" @ONLY)
00073     endif ()
00074     list (APPEND CONFIGURED_HEADERS "${SOURCE}")
00075   endforeach ()
00076 endforeach ()
00077 
00078 # ----------------------------------------------------------------------------
00079 # write CMake script with list of public header files
00080 if (CMAKE_FILE)
00081   if (_CONFIGURED_HEADERS)
00082     list (SORT _CONFIGURED_HEADERS) # deterministic order
00083   endif ()
00084   file (WRITE "${CMAKE_FILE}" "# Automatically generated by BASIS. DO NOT edit this file!\nset (${VARIABLE_NAME}\n")
00085   foreach (HEADER IN LISTS CONFIGURED_HEADERS)
00086     file (APPEND "${CMAKE_FILE}" "  \"${HEADER}\"\n")
00087   endforeach ()
00088   file (APPEND "${CMAKE_FILE}" ")\n")
00089 endif ()