1 # ============================================================================ 2 # Copyright (c) 2011-2012 University of Pennsylvania 3 # Copyright (c) 2013-2016 Andreas Schuh 6 # See COPYING file for license information or visit 7 # https://cmake-basis.github.io/download.html#license 8 # ============================================================================ 10 ############################################################################## 11 # @file ImportTools.cmake 12 # @brief Functions and macros for the import of targets. 15 ############################################################################## 24 ## @addtogroup CMakeUtilities 27 # ---------------------------------------------------------------------------- 28 ## @brief Set target property. 30 # This function is overwritten by BASIS in order to update the information 31 # about imported build targets. 33 # @note Do not use this function in your CMakeLists.txt configuration files. 34 # Use basis_set_target_properties() instead. 36 # @note Due to a bug in CMake (http://www.cmake.org/Bug/view.php?id=12303), 37 # except of the first property given directly after the @c PROPERTIES keyword, 38 # only properties listed in @c BASIS_PROPERTIES_ON_TARGETS can be set. 40 # @param [in] ARGN List of arguments for 41 # <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_target_properties"> 42 # set_target_properties()</a>. 44 # @sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_target_properties 47 list (FIND ARGN
"PROPERTIES" IDX)
49 message (FATAL_ERROR
"Missing PROPERTIES argument!")
51 message (FATAL_ERROR "No targets specified!")
56 list (APPEND INDICES ${I})
57 math (EXPR I
"${I} + 1")
59 list (GET ARGN ${INDICES} TARGETS)
60 # remaining arguments are property value pairs
61 list (REMOVE_AT ARGN ${INDICES} ${IDX})
62 #
set target properties
64 # Note: By iterating over the properties, the empty property values
65 # are correctly passed on to CMake
's set_target_properties() 67 # _set_target_properties(${TARGET_UIDS} PROPERTIES ${ARGN}) 68 # (erroneously) discards the empty elements in ARGN. 70 message ("** set_target_properties:") 71 message ("** Target(s): ${TARGETS}") 72 message ("** Properties: [${ARGN}]") 76 list (GET ARGN 0 PROPERTY) 77 list (GET ARGN 1 VALUE) 78 list (REMOVE_AT ARGN 0 1) 80 # The following loop is only required b/c CMake's ARGV and ARGN
81 # lists
do not support arguments
which are themselves lists.
82 # Therefore, we need a way to decide when the list of values
for a
83 # property
is terminated. Hence, we only allow known properties
84 # to be
set, except
for the first property where the name follows
85 # directly after the PROPERTIES keyword.
88 if (ARG MATCHES
"${BASIS_PROPERTIES_ON_TARGETS_RE}")
91 list (APPEND
VALUE "${ARG}")
92 list (REMOVE_AT ARGN 0)
96 message (
"** -> ${PROPERTY} = [${VALUE}]")
99 if (PROPERTY MATCHES
"^$")
100 message (FATAL_ERROR
"Empty property name given!")
101 # if property is related to the location of an imported target, 102 # update corresponding project properties 103 elseif (PROPERTY MATCHES
"^IMPORTED_LOCATION")
104 list (GET TARGETS 0 TARGET)
106 #
if property
is related to the type of an imported target,
107 # update corresponding project properties
108 elseif (PROPERTY MATCHES
"^BASIS_TYPE$")
109 list (GET TARGETS 0 TARGET)
112 # set target property 113 _set_target_properties (${TARGETS} PROPERTIES ${PROPERTY}
"${VALUE}")
115 # make sure that every property had a corresponding value 117 message (FATAL_ERROR
"No value given for target property ${ARGN}")
121 # ---------------------------------------------------------------------------- 122 ## @brief Add imported target. 124 # Imported targets are only valid in the scope where they were imported. 125 # In order to be able to add the information of the imported executable targets 126 # to the ExecutableTargetInfo modules of the BASIS utilities which are configured 127 # during the finalization of the (top-level) project, the information of 128 # imported targets has to be stored in the global scope. Therefore, internal 129 # cache variables prefixed by the name of the project are used 130 # (see basis_set_project_property()): 134 # @tp @b IMPORTED_TARGETS @endtp 135 # <td>List of imported targets.</td> 138 # @tp @b IMPORTED_TYPES @endtp 139 # <td>Types of imported targets.</td> 142 # @tp @b IMPORTED_LOCATIONS @endtp 143 # <td>Locations of imported target files.</td> 146 # @tp @b IMPORTED_RANKS @endtp 147 # <td>Rank of current imported locations. This rank value is used to decide 148 # whether the current location takes precedence over another imported 149 # location. For example, IMPORTED_LOCATION_<a>, may be preferred 150 # over IMPORTED_LOCATION_<b>. 154 # @param [in] TARGET Name (UID) of the imported target. 155 # @param [in] TYPE Type of the imported target. 157 # @sa basis_update_imported_location() 160 message (
"** basis_add_imported_target:")
161 message (
"** Target: ${TARGET}")
162 message (
"** Type: ${TYPE}")
163 message (
"** Bundled: ${BUNDLE_PROJECT}")
165 if (NOT TYPE STREQUAL
"INTERFACE")
167 _set_target_properties (${TARGET} PROPERTIES BUNDLED TRUE)
169 _set_target_properties (${TARGET} PROPERTIES BUNDLED FALSE)
172 # if target was added before 175 list (FIND TARGETS
"${TARGET}" IDX)
176 if (NOT IDX EQUAL -1)
181 # otherwise, add it to the project properties 188 # ---------------------------------------------------------------------------- 189 ## @brief Update location of imported target. 191 # @param [in] TARGET Name (UID) of the imported target. 192 # @param [in] PROPERTY Target location property. Either IMPORTED_LOCATION 193 # or IMPORTED_LOCATION_<config>, where <config> 194 # is one of the imported build configurations. 195 # This argument is used to decide whether to keep 196 # the current target information or to replace it 198 # @param [in] LOCATION Location of imported target. 201 message (
"** basis_update_imported_location:")
202 message (
"** Target: ${TARGET}")
203 message (
"** Location: ${LOCATION}")
205 # get index of imported target 207 list (FIND TARGETS
"${TARGET}" IDX)
209 # imported targets have to be added via basis_add_imported_target() first 210 # otherwise, ignore target here and do not update the non-existent information 213 # get current information of target 217 list (GET TYPES ${IDX} TYPE)
218 list (GET RANKS ${IDX} CURRENT_RANK)
219 # decide whether current information shall be overwritten
221 string (TOUPPER
"${CMAKE_BUILD_TYPE}" C)
228 "IMPORTED_LOCATION_${C}" # 0) prefer location corresponding to current configuration
229 "IMPORTED_LOCATION" # 1) then use non-configuration specific location
230 "IMPORTED_LOCATION_RELEASE" # 2) otherwise use
RELEASE version
if available
231 # 3) last pick, use first imported executable
233 list (FIND RANKING
"${PROPERTY}" RANK)
237 # bail out if current information shall be kept 238 if (NOT
"${RANK}" LESS
"${CURRENT_RANK}")
241 # remove current information 242 list (REMOVE_AT TYPES ${IDX})
243 list (REMOVE_AT LOCATIONS ${IDX})
244 list (REMOVE_AT RANKS ${IDX})
245 # add imported information
246 list (LENGTH TYPES N)
248 list (INSERT TYPES ${IDX}
"${TYPE}")
249 list (INSERT LOCATIONS ${IDX}
"${LOCATION}")
250 list (INSERT RANKS ${IDX}
"${RANK}")
252 list (APPEND TYPES
"${TYPE}")
253 list (APPEND LOCATIONS
"${LOCATION}")
254 list (APPEND RANKS
"${RANK}")
256 # update project properties 262 # ---------------------------------------------------------------------------- 263 ## @brief Update type of imported target. 265 # This function is in particular called in basis_set_target_properties() 266 # if the BASIS_TYPE property of custom BASIS targets is set after the 267 # imported target was added with the initial type UNKNOWN. 269 # @param [in] TARGET Name (UID) of the imported target. 270 # @param [in] TYPE Type of imported target. 272 #
get index of imported target
274 list (FIND TARGETS
"${TARGET}" IDX)
276 # imported targets have to be added via basis_add_imported_target() first 277 # otherwise, ignore target here and do not update the non-existent information 280 # get current type of imported target 282 list (GET TYPES ${IDX} CURRENT_TYPE)
283 # bail out
if current type shall be kept
284 if (NOT CURRENT_TYPE MATCHES
"^UNKNOWN$")
287 # replace current type 288 list (REMOVE_AT TYPES ${IDX})
289 list (LENGTH TYPES N)
291 list (INSERT TYPES ${IDX} ${TYPE})
293 list (APPEND TYPES ${TYPE})
295 # update project property 301 # end of Doxygen group function set_target_properties(in ARGN)
Set target property.
function is(in result, in expected, in name)
Test whether a given result is equal to the expected result.
def which(command, path=None, verbose=0, exts=None)
function basis_get_project_property(out VARIABLE, in ARGN)
Get project-global property value.
function basis_set_project_property()
Set project-global property.
function basis_update_imported_type(in TARGET, in TYPE)
Update type of imported target.
function basis_update_imported_location(in TARGET, in PROPERTY, in LOCATION)
Update location of imported target.
string RELEASE
Project release.
option BASIS_DEBUG
Request debugging messages from BASIS functions.
option BASIS_VERBOSE
Default Sphinx theme options.
function basis_add_imported_target(in TARGET, in TYPE)
Add imported target.