1 2# add_target_property 3# Adds one or more values to the specified property of the specified target. 4# Note that there are properties which require (semicolon-separated) lists, 5# while others require space-separated strings. The function has a list of 6# properties of the former variety and handles the values accordingly 7function(add_target_property _module _propname) 8 list(APPEND _list_properties COMPILE_DEFINITIONS INCLUDE_DIRECTORIES LINK_DEPENDS) 9 set(_newvalue "") 10 get_target_property(_oldvalue ${_module} ${_propname}) 11 if(_oldvalue) 12 set(_newvalue ${_oldvalue}) 13 endif() 14 list(FIND _list_properties ${_propname} _list_index) 15 if(NOT _list_index EQUAL -1) 16 # list property 17 list(APPEND _newvalue ${ARGN}) 18 else() 19 # string property 20 foreach(_flag ${ARGN}) 21 set(_newvalue "${_newvalue} ${_flag}") 22 endforeach() 23 endif() 24 set_property(TARGET ${_module} PROPERTY ${_propname} ${_newvalue}) 25endfunction() 26 27# remove_target_compile_options 28# Remove one option from the target COMPILE_OPTIONS property, 29# previously added through add_compile_options 30function(remove_target_compile_option _module _option) 31 get_target_property(_options ${_module} COMPILE_OPTIONS) 32 list(REMOVE_ITEM _options ${_option}) 33 set_target_properties(${_module} PROPERTIES COMPILE_OPTIONS "${_options}") 34endfunction() 35 36# Wrapper functions for the important properties, using add_target_property 37# where appropriate. 38# Note that the functions for string properties take a single string 39# argument while those for list properties can take a variable number of 40# arguments, all of which will be added to the list 41# 42# Examples: 43# add_target_link_flags(mymodule "-s --fatal-warnings") 44 45function(add_target_link_flags _module _flags) 46 if(${ARGC} GREATER 2) 47 message(FATAL_ERROR "Excess arguments to add_target_link_flags! Module ${_module}, args ${ARGN}") 48 endif() 49 add_target_property(${_module} LINK_FLAGS ${_flags}) 50endfunction() 51