11#=============================================================================#
22# Sets compiler flags on the given target using the given board ID, compiler language and scope.
33# _target_name - Name of the target (Executable or Library) to set flags on.
4- # _board_id - Target's bounded board ID.
54# _language - Language for which flags are set (such as C/C++).
65# _scope - Flags' scope relative to outer targets (targets using the given target).
76#=============================================================================#
8- function (_set_target_language_flags _target_name _board_id _language _scope)
7+ function (_set_target_language_flags _target_name _language _scope)
98
10- parse_compiler_recipe_flags(${_board_id} compiler_recipe_flags
9+ # Infer target's type and act differently if it's an interface-library
10+ get_target_property (target_type ${_target_name} TYPE )
11+
12+ if ("${target_type} " STREQUAL "INTERFACE_LIBRARY" )
13+ get_target_property (board_id ${_target_name} INTERFACE_BOARD_ID)
14+ else ()
15+ get_target_property (board_id ${_target_name} BOARD_ID)
16+ endif ()
17+
18+ parse_compiler_recipe_flags(${board_id} compiler_recipe_flags
1119 LANGUAGE "${_language} " )
1220
1321 target_compile_options (${_target_name} ${_scope}
@@ -18,27 +26,26 @@ endfunction()
1826#=============================================================================#
1927# Sets compiler flags on the given target, according also to the given board ID.
2028# _target_name - Name of the target (Executable or Library) to set flags on.
21- # _board_id - Target's bounded board ID.
2229#=============================================================================#
23- function (set_compiler_target_flags _target_name _board_id )
30+ function (set_target_compile_flags _target_name)
2431
2532 cmake_parse_arguments (parsed_args "" "LANGUAGE" "" ${ARGN} )
2633 parse_scope_argument(scope "${ARGN} "
2734 DEFAULT_SCOPE PUBLIC )
2835
2936 if (parsed_args_LANGUAGE)
30- _set_target_language_flags(${_target_name} ${_board_id} ${ parsed_args_LANGUAGE} ${scope} )
37+ _set_target_language_flags(${_target_name} ${parsed_args_LANGUAGE} ${scope} )
3138
3239 else () # No specific language requested - Use all
3340
3441 get_cmake_compliant_language_name(asm lang)
35- _set_target_language_flags(${_target_name} ${_board_id} ${ lang} ${scope} )
42+ _set_target_language_flags(${_target_name} ${lang} ${scope} )
3643
3744 get_cmake_compliant_language_name(c lang)
38- _set_target_language_flags(${_target_name} ${_board_id} ${ lang} ${scope} )
45+ _set_target_language_flags(${_target_name} ${lang} ${scope} )
3946
4047 get_cmake_compliant_language_name(cpp lang)
41- _set_target_language_flags(${_target_name} ${_board_id} ${ lang} ${scope} )
48+ _set_target_language_flags(${_target_name} ${lang} ${scope} )
4249
4350 endif ()
4451
@@ -47,11 +54,19 @@ endfunction()
4754#=============================================================================#
4855# Sets linker flags on the given target, according also to the given board ID.
4956# _target_name - Name of the target (Executable or Library) to set flags on.
50- # _board_id - Target's bounded board ID.
5157#=============================================================================#
52- function (set_linker_flags _target_name _board_id)
58+ function (set_linker_flags _target_name)
59+
60+ # Infer target's type and act differently if it's an interface-library
61+ get_target_property (target_type ${_target_name} TYPE )
62+
63+ if ("${target_type} " STREQUAL "INTERFACE_LIBRARY" )
64+ get_target_property (board_id ${_target_name} INTERFACE_BOARD_ID)
65+ else ()
66+ get_target_property (board_id ${_target_name} BOARD_ID)
67+ endif ()
5368
54- parse_linker_recpie_pattern(" ${_board_id} " linker_recipe_flags)
69+ parse_linker_recpie_pattern(${board_id} linker_recipe_flags)
5570
5671 string (REPLACE ";" " " cmake_compliant_linker_flags "${linker_recipe_flags} " )
5772
@@ -63,12 +78,11 @@ endfunction()
6378# Sets compiler and linker flags on the given Executable target,
6479# according also to the given board ID.
6580# _target_name - Name of the target (Executable) to set flags on.
66- # _board_id - Target's bounded board ID.
6781#=============================================================================#
68- function (set_executable_target_flags _target_name _board_id )
82+ function (set_executable_target_flags _target_name)
6983
70- set_compiler_target_flags (${_target_name} " ${_board_id} " )
71- set_linker_flags(${_target_name} " ${_board_id} " )
84+ set_target_compile_flags (${_target_name} )
85+ set_linker_flags(${_target_name} )
7286
7387 target_link_libraries (${_target_name} PUBLIC m) # Add math library
7488
@@ -80,14 +94,13 @@ endfunction()
8094#=============================================================================#
8195# Sets upload/flash flags on the given target, according also to the given board ID.
8296# _target_name - Name of the target (Executable) to set flags on.
83- # _board_id - Target's bounded board ID.
8497#=============================================================================#
85- function (set_upload_target_flags _target_name _board_id _upload_port _return_var)
98+ function (set_upload_target_flags _target_name _upload_port _return_var)
8699
87- set (upload_flags "" )
100+ get_target_property (board_id ${_target_name} BOARD_ID )
88101
89102 # Parse and append recipe flags
90- parse_upload_recipe_pattern(" ${_board_id} " "${_upload_port} " upload_recipe_flags)
103+ parse_upload_recipe_pattern(${board_id} "${_upload_port} " upload_recipe_flags)
91104 list (APPEND upload_flags "${upload_recipe_flags} " )
92105
93106 set (target_binary_base_path "${CMAKE_CURRENT_BINARY_DIR} /${_target_name} " )
0 commit comments