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
7 function(add_target_property _module _propname)
8 list(APPEND _list_properties COMPILE_DEFINITIONS INCLUDE_DIRECTORIES)
10 get_target_property(_oldvalue ${_module} ${_propname})
12 set(_newvalue ${_oldvalue})
14 list(FIND _list_properties ${_propname} _list_index)
15 if(NOT _list_index EQUAL -1)
17 list(APPEND _newvalue ${ARGN})
20 foreach(_flag ${ARGN})
21 set(_newvalue "${_newvalue} ${_flag}")
24 set_property(TARGET ${_module} PROPERTY ${_propname} ${_newvalue})
27 # Wrapper functions for the important properties, using add_target_property
29 # Note that the functions for string properties take a single string
30 # argument while those for list properties can take a variable number of
31 # arguments, all of which will be added to the list
34 # add_compile_flags("-pedantic -O5")
35 # add_target_link_flags(mymodule "-s --fatal-warnings")
36 # add_target_compile_flags(mymodule "-pedantic -O5")
37 # add_target_compile_definitions(mymodule WIN32 _WIN32 INLINE=inline)
38 # add_target_include_directories(mymodule include ../include)
39 # add_compile_flags_language("-std=gnu99" "C")
40 function(add_compile_flags _flags)
42 message(STATUS "Excess arguments to add_compile_flags! Args ${ARGN}")
44 # Adds the compiler flag to both CMAKE_C_FLAGS and CMAKE_CXX_FLAGS
45 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flags}" PARENT_SCOPE)
46 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flags}" PARENT_SCOPE)
47 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${_flags}" PARENT_SCOPE)
50 function(add_compile_flags_language _flags _lang)
51 if(NOT ${ARGC} EQUAL 2)
52 message(STATUS "Wrong arguments to add_compile_flags_language! Args ${ARGN}")
54 # Adds the compiler flag to both CMAKE_C_FLAGS and CMAKE_CXX_FLAGS
55 set(CMAKE_${_lang}_FLAGS "${CMAKE_${_lang}_FLAGS} ${_flags}" PARENT_SCOPE)
58 function(add_target_compile_flags _module _flags)
60 message(STATUS "Excess arguments to add_target_compile_flags! Module ${_module}, args ${ARGN}")
62 add_target_property(${_module} COMPILE_FLAGS ${_flags})
65 function(add_target_link_flags _module _flags)
67 message(STATUS "Excess arguments to add_target_link_flags! Module ${_module}, args ${ARGN}")
69 add_target_property(${_module} LINK_FLAGS ${_flags})
72 function(add_target_compile_definitions _module)
73 add_target_property(${_module} COMPILE_DEFINITIONS ${ARGN})
76 function(add_target_include_directories _module)
77 add_target_property(${_module} INCLUDE_DIRECTORIES ${ARGN})