This repository was archived by the owner on Apr 17, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +67
-33
lines changed Expand file tree Collapse file tree 5 files changed +67
-33
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ include(ListUtils)
1414include (StringUtils)
1515include (PropertyUtils)
1616include (PlatformLibraryUtils)
17+ include (CMakeArgumentsUtils)
1718
1819include (BoardManager)
1920include (RecipeParser)
Original file line number Diff line number Diff line change 55#=============================================================================#
66function (set_compiler_target_flags _target_name _board_id)
77
8- set (option_args PRIVATE PUBLIC INTERFACE )
9- set (single_args LANGUAGE )
10- cmake_parse_arguments (compiler "${option_args} " "${single_args} " "" ${ARGN} )
11-
12- if (compiler_LANGUAGE)
13- if (compiler_PRIVATE)
14- set (scope PRIVATE )
15- elseif (compiler_INTERFACE)
16- set (scope INTERFACE )
17- else ()
18- set (scope PUBLIC )
19- endif ()
8+ cmake_parse_arguments (parsed_args "" "LANGUAGE" "" ${ARGN} )
9+ parse_scope_argument("${ARGN} " scope
10+ DEFAULT_SCOPE PUBLIC )
11+
12+ if (parsed_args_LANGUAGE)
13+
2014 parse_compiler_recipe_flags("${_board_id} " compiler_recipe_flags
21- LANGUAGE "${compiler_LANGUAGE} " )
15+ LANGUAGE "${parsed_args_LANGUAGE} " )
16+
2217 target_compile_options (${_target_name} ${scope}
23- $<$<COMPILE_LANGUAGE:${compiler_LANGUAGE} >:${compiler_recipe_flags} >)
18+ $<$<COMPILE_LANGUAGE:${parsed_args_LANGUAGE} >:${compiler_recipe_flags} >)
19+
2420 else ()
21+
2522 parse_compiler_recipe_flags("${_board_id} " compiler_recipe_flags)
26- target_compile_options (${_target_name} PUBLIC ${compiler_recipe_flags} )
23+
24+ target_compile_options (${_target_name} ${scope} ${compiler_recipe_flags} )
25+
2726 endif ()
2827
2928endfunction ()
@@ -36,7 +35,9 @@ endfunction()
3635function (set_linker_flags _target_name _board_id)
3736
3837 parse_linker_recpie_pattern("${_board_id} " linker_recipe_flags)
38+
3939 string (REPLACE ";" " " cmake_compliant_linker_flags "${linker_recipe_flags} " )
40+
4041 set (CMAKE_EXE_LINKER_FLAGS "${cmake_compliant_linker_flags} " CACHE STRING "" FORCE)
4142
4243endfunction ()
Original file line number Diff line number Diff line change @@ -47,21 +47,12 @@ function(_link_arduino_cmake_library _target_name _library_name)
4747 message (FATAL_ERROR "Target doesn't exist - It must be created first!" )
4848 endif ()
4949
50- set (scope_options "PRIVATE" "PUBLIC" "INTERFACE" )
51- cmake_parse_arguments (link_library "${scope_options} " "BOARD_CORE_TARGET" "" ${ARGN} )
52-
53- # Now, link library to executable
54- if (link_library_PRIVATE)
55- set (scope PRIVATE )
56- elseif (link_library_INTERFACE)
57- set (scope INTERFACE )
58- else ()
59- set (scope PUBLIC )
60- endif ()
50+ cmake_parse_arguments (parsed_args "" "BOARD_CORE_TARGET" "" ${ARGN} )
51+ parse_scope_argument("${ARGN} " scope)
6152
6253 # Resolve Core-Lib's target
63- if (link_library_BOARD_CORE_TARGET )
64- set (core_target ${link_library_BOARD_CORE_TARGET } )
54+ if (parsed_args_BOARD_CORE_TARGET )
55+ set (core_target ${parsed_args_BOARD_CORE_TARGET } )
6556 else ()
6657 set (core_target ${${_target_name} _CORE_LIB_TARGET})
6758 endif ()
@@ -73,7 +64,7 @@ function(_link_arduino_cmake_library _target_name _library_name)
7364 target_link_libraries (${_library_name} ${scope} ${core_target} )
7465
7566 # Link library target to linked-to target
76- if (link_library_PRIVATE )
67+ if (parsed_args_PRIVATE )
7768 target_link_libraries (${_target_name} PRIVATE ${_library_name} )
7869 else ()
7970 # Link 'INTERFACE' targets publicly, otherwise code won't compile
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ function(find_dependent_platform_libraries _sources _return_var)
1717 endif ()
1818
1919 get_platform_libraries_from_names("${included_headers_names} " dependent_libs)
20+
2021 set (${_return_var} ${dependent_libs} PARENT_SCOPE)
2122
2223endfunction ()
@@ -32,8 +33,7 @@ function(_add_platform_library _library_name _board_id)
3233 find_source_files("${ARDUINO_CMAKE_PLATFORM_LIBRARIES_PATH} /${_library_name} /src" lib_source_files)
3334 set (lib_sources ${lib_headers} ${lib_source_files} )
3435
35- _add_arduino_cmake_library(${_library_name} ${_board_id} "${lib_sources} "
36- ARCH ${ARDUINO_CMAKE_PLATFORM_ARCHITECTURE} )
36+ _add_arduino_cmake_library(${_library_name} ${_board_id} "${lib_sources} " )
3737
3838endfunction ()
3939
@@ -49,14 +49,20 @@ function(link_platform_library _target_name _library_name _board_id)
4949 message (FATAL_ERROR "Target ${_target_name} doesn't exist - It must be created first!" )
5050 endif ()
5151
52+ parse_scope_argument("${ARGN} " scope
53+ DEFAULT_SCOPE PUBLIC )
54+
5255 if (NOT TARGET ${_library_name} )
56+
5357 _add_platform_library(${_library_name} ${_board_id} )
58+
5459 get_core_lib_target_name(${_board_id} core_lib_target)
5560 _link_arduino_cmake_library(${_target_name} ${_library_name}
56- PUBLIC
61+ ${scope}
5762 BOARD_CORE_TARGET ${core_lib_target} )
63+
5864 else ()
59- target_link_libraries (${_target_name} PUBLIC ${_library_name} )
65+ target_link_libraries (${_target_name} ${scope} ${_library_name} )
6066 endif ()
6167
6268endfunction ()
Original file line number Diff line number Diff line change 1+ #=============================================================================#
2+ # Parses the given arguments for scope-controlling arguments, which are PUBLIC|INTERFACE|PRIVATE.
3+ # If none is found, CMake generates an error, unless - The DEFAULT_SCOPE argument is passed.
4+ # _cmake_args - Arguments to parse. Usually function's unparsed arguments - ${ARGN}.
5+ # [DEFAULT_SCOPE] - Optional default scope to return in case none is found in arguments.
6+ # _return_var - Name of a CMake variable that will hold the extraction result.
7+ # Returns - Parsed scope if one is found or the DEFAULT_SCOPE if set, otherwise an error.
8+ #=============================================================================#
9+ function (parse_scope_argument _cmake_args _return_var)
10+
11+ cmake_parse_arguments (parsed_args "" "DEFAULT_SCOPE" "" ${ARGN} )
12+
13+ set (scope_options "PRIVATE" "PUBLIC" "INTERFACE" )
14+ cmake_parse_arguments (scope_args "${scope_options} " "" "" ${_cmake_args} )
15+
16+ # Now, link library to executable
17+ if (scope_args_PRIVATE)
18+ set (scope PRIVATE )
19+ elseif (scope_args_INTERFACE)
20+ set (scope INTERFACE )
21+ elseif (scope_args_PUBLIC)
22+ set (scope PUBLIC )
23+ else ()
24+
25+ if (parsed_args_DEFAULT_SCOPE) # Use default scope if none are given
26+ set (scope ${parsed_args_DEFAULT_SCOPE} )
27+ else ()
28+ message (SEND_ERROR "Can't parse scope arguments - None are given, or invalid!" )
29+ endif ()
30+
31+ endif ()
32+
33+ set (${_return_var} ${scope} PARENT_SCOPE)
34+
35+ endfunction ()
You can’t perform that action at this time.
0 commit comments