BASIS  version 1.2.3 (revision 2104)
GenerateConfig.cmake
Go to the documentation of this file.
00001 ##############################################################################
00002 # @file  GenerateConfig.cmake
00003 # @brief Generates package configuration files.
00004 #
00005 # This CMake script configures the \<package\>Config.cmake et al. files,
00006 # once for the build tree and once for the install tree. Variables with a
00007 # _CONFIG suffix are replaced in the default template file by either the
00008 # value for the build or the install tree, respectively.
00009 #
00010 # If present, this script includes the @c PROJECT_CONFIG_DIR/ConfigBuild.cmake
00011 # and/or @c PROJECT_CONFIG_DIR/ConfigInstall.cmake file before configuring the
00012 # Config.cmake.in template. If a file @c PROJECT_CONFIG_DIR/Config.cmake.in
00013 # exists, it is used as template. Otherwise, the default template file is used.
00014 #
00015 # Similarly, if the file @c PROJECT_CONFIG_DIR/ConfigVersion.cmake.in exists,
00016 # it is used as template for the \<package\>ConfigVersion.cmake file. The same
00017 # applies to ConfigUse.cmake.in.
00018 #
00019 # Copyright (c) 2011, 2012 University of Pennsylvania. All rights reserved.<br />
00020 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.
00021 #
00022 # Contact: SBIA Group <sbia-software at uphs.upenn.edu>
00023 #
00024 # @ingroup CMakeTools
00025 ##############################################################################
00026 
00027 # ============================================================================
00028 # names of output files
00029 # ============================================================================
00030 
00031 # Attention: This has to be done before configuring any files such that these
00032 #            variables can be used by the template files.
00033 
00034 ## @addtogroup CMakeUtilities
00035 #  @{
00036 
00037 
00038 ## @brief Package name.
00039 set (CONFIG_PREFIX "${PROJECT_NAME}")
00040 ## @brief Name of the CMake package configuration file.
00041 set (CONFIG_FILE "${CONFIG_PREFIX}Config.cmake")
00042 ## @brief Name of the CMake package version file.
00043 set (VERSION_FILE "${CONFIG_PREFIX}ConfigVersion.cmake")
00044 ## @brief Name of the CMake package use file.
00045 set (USE_FILE "${CONFIG_PREFIX}Use.cmake")
00046 ## @brief Name of the CMake target exports file.
00047 set (EXPORTS_FILE "${CONFIG_PREFIX}Exports.cmake")
00048 ## @brief Name of the CMake target exports file for custom targets.
00049 set (CUSTOM_EXPORTS_FILE "${CONFIG_PREFIX}CustomExports.cmake")
00050 
00051 
00052 ## @}
00053 # end of Doxygen group
00054 
00055 # ============================================================================
00056 # export build targets
00057 # ============================================================================
00058 
00059 basis_export_targets (
00060   FILE        "${EXPORTS_FILE}"
00061   CUSTOM_FILE "${CUSTOM_EXPORTS_FILE}"
00062 )
00063 
00064 # ============================================================================
00065 # namespace
00066 # ============================================================================
00067 
00068 # code used at top of packing configuration and use files to set package
00069 # namespace prefix used for configuration variables
00070 set (BASIS_NS
00071 "# prefix used for variable names
00072 set (NS \"${CONFIG_PREFIX}_\")
00073 
00074 # allow caller to change namespace - used by projects with modules
00075 if (\${NS}CONFIG_PREFIX)
00076   set (NS \"\${\${NS}CONFIG_PREFIX}\")
00077 endif ()"
00078 )
00079 
00080 # ============================================================================
00081 # project configuration file
00082 # ============================================================================
00083 
00084 # ----------------------------------------------------------------------------
00085 # choose template
00086 
00087 if (EXISTS "${PROJECT_CONFIG_DIR}/Config.cmake.in")
00088   set (TEMPLATE "${PROJECT_CONFIG_DIR}/Config.cmake.in")
00089 else ()
00090   set (TEMPLATE "${CMAKE_CURRENT_LIST_DIR}/Config.cmake.in")
00091 endif ()
00092 
00093 # ----------------------------------------------------------------------------
00094 # provide code of BASIS config file as variable
00095 if (NOT "${TEMPLATE}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}/Config.cmake.in")
00096   file (READ "${CMAKE_CURRENT_LIST_DIR}/Config.cmake.in" BASIS_TEMPLATE)
00097   # remove file header
00098   string (REGEX REPLACE "^########.*########" "" BASIS_TEMPLATE "${BASIS_TEMPLATE}")
00099   string (STRIP "${BASIS_TEMPLATE}" BASIS_TEMPLATE)
00100 else ()
00101   set (BASIS_TEMPLATE "")
00102 endif ()
00103 
00104 # ----------------------------------------------------------------------------
00105 # build tree related configuration
00106 
00107 set (BUILD_CONFIG_SETTINGS 1)
00108 include ("${CMAKE_CURRENT_LIST_DIR}/BasisConfigSettings.cmake")
00109 include ("${PROJECT_CONFIG_DIR}/ConfigSettings.cmake" OPTIONAL)
00110 
00111 # ----------------------------------------------------------------------------
00112 # configure project configuration file for build tree
00113 
00114 string (CONFIGURE "${BASIS_TEMPLATE}" BASIS_CONFIG @ONLY)
00115 configure_file ("${TEMPLATE}" "${PROJECT_BINARY_DIR}/${CONFIG_FILE}" @ONLY)
00116 
00117 # ----------------------------------------------------------------------------
00118 # install tree related configuration
00119 
00120 set (BUILD_CONFIG_SETTINGS 0)
00121 include ("${CMAKE_CURRENT_LIST_DIR}/BasisConfigSettings.cmake")
00122 include ("${PROJECT_CONFIG_DIR}/ConfigSettings.cmake" OPTIONAL)
00123 
00124 # ----------------------------------------------------------------------------
00125 # configure project configuration file for install tree
00126 
00127 string (CONFIGURE "${BASIS_TEMPLATE}" BASIS_CONFIG @ONLY)
00128 configure_file ("${TEMPLATE}" "${BINARY_CONFIG_DIR}/${CONFIG_FILE}" @ONLY)
00129 
00130 # ----------------------------------------------------------------------------
00131 # install project configuration file
00132 
00133 install (
00134   FILES       "${BINARY_CONFIG_DIR}/${CONFIG_FILE}"
00135   DESTINATION "${INSTALL_CONFIG_DIR}"
00136 )
00137 
00138 # ============================================================================
00139 # project version file
00140 # ============================================================================
00141 
00142 # ----------------------------------------------------------------------------
00143 # choose template
00144 
00145 if (EXISTS "${PROJECT_CONFIG_DIR}/ConfigVersion.cmake.in")
00146   set (TEMPLATE "${PROJECT_CONFIG_DIR}/ConfigVersion.cmake.in")
00147 else ()
00148   set (TEMPLATE "${CMAKE_CURRENT_LIST_DIR}/ConfigVersion.cmake.in")
00149 endif ()
00150 
00151 # ----------------------------------------------------------------------------
00152 # configure project configuration version file
00153 
00154 configure_file ("${TEMPLATE}" "${PROJECT_BINARY_DIR}/${VERSION_FILE}" @ONLY)
00155 
00156 # ----------------------------------------------------------------------------
00157 # install project configuration version file
00158 
00159 install (
00160   FILES       "${PROJECT_BINARY_DIR}/${VERSION_FILE}"
00161   DESTINATION "${INSTALL_CONFIG_DIR}"
00162 )
00163 
00164 # ============================================================================
00165 # project use file
00166 # ============================================================================
00167 
00168 # ----------------------------------------------------------------------------
00169 # choose template
00170 
00171 if (EXISTS "${PROJECT_CONFIG_DIR}/ConfigUse.cmake.in")
00172   set (TEMPLATE "${PROJECT_CONFIG_DIR}/ConfigUse.cmake.in")
00173 elseif (EXISTS "${PROJECT_CONFIG_DIR}/Use.cmake.in")
00174   # backwards compatibility to version <= 0.1.8 of BASIS
00175   set (TEMPLATE "${PROJECT_CONFIG_DIR}/Use.cmake.in")
00176 else ()
00177   set (TEMPLATE "${CMAKE_CURRENT_LIST_DIR}/ConfigUse.cmake.in")
00178 endif ()
00179 
00180 # ----------------------------------------------------------------------------
00181 # provide code of BASIS use file as variable
00182 if (NOT "${TEMPLATE}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}/ConfigUse.cmake.in")
00183   file (READ "${CMAKE_CURRENT_LIST_DIR}/ConfigUse.cmake.in" BASIS_USE)
00184   # remove file header
00185   string (REGEX REPLACE "^########.*########" "" BASIS_USE "${BASIS_USE}")
00186   string (STRIP "${BASIS_USE}" BASIS_USE)
00187 else ()
00188   set (BASIS_USE "")
00189 endif ()
00190 
00191 # ----------------------------------------------------------------------------
00192 # configure project use file
00193 
00194 string (CONFIGURE "${BASIS_USE}" BASIS_USE @ONLY)
00195 configure_file ("${TEMPLATE}" "${PROJECT_BINARY_DIR}/${USE_FILE}" @ONLY)
00196 
00197 # ----------------------------------------------------------------------------
00198 # install project use file
00199 
00200 install (
00201   FILES       "${PROJECT_BINARY_DIR}/${USE_FILE}"
00202   DESTINATION "${INSTALL_CONFIG_DIR}"
00203 )
00204 
00205 unset (BASIS_NS)
00206 unset (BASIS_TEMPLATE)
00207 unset (BASIS_CONFIG)
00208 unset (BASIS_USE)