@@ -26,9 +26,8 @@ function(_add_arduino_cmake_library _target_name _board_id _sources)
2626
2727 set_library_flags(${_target_name} ${_board_id} ${scope} )
2828
29- string (TOUPPER ${ARDUINO_CMAKE_PLATFORM_ARCHITECTURE} upper_arch)
30- set (arch_definition "ARDUINO_ARCH_${upper_arch} " )
31- target_compile_definitions (${_target_name} ${scope} ${arch_definition} )
29+ set_target_architecture_definition(${_target_name} ${scope}
30+ ${ARDUINO_CMAKE_PLATFORM_ARCHITECTURE} )
3231
3332endfunction ()
3433
@@ -38,7 +37,7 @@ endfunction()
3837# then links it to the library.
3938# _target_name - Name of the target to link against.
4039# _library_name - Name of the library target to link.
41- # [PRIVATE|PUBLIC|INTERFACE] - Optional link scope.
40+ # [PRIVATE|PUBLIC|INTERFACE] - Optional link scope for the internally linked Core-Lib .
4241# [BOARD_CORE_TARGET] - Optional target name of the Core Lib to use.
4342# Use when the target is a library.
4443#=============================================================================#
@@ -52,25 +51,33 @@ function(_link_arduino_cmake_library _target_name _library_name)
5251 cmake_parse_arguments (link_library "${scope_options} " "BOARD_CORE_TARGET" "" ${ARGN} )
5352
5453 # Now, link library to executable
55- if (link_library_PUBLIC )
56- set (scope PUBLIC )
54+ if (link_library_PRIVATE )
55+ set (scope PRIVATE )
5756 elseif (link_library_INTERFACE)
5857 set (scope INTERFACE )
5958 else ()
60- set (scope PRIVATE )
59+ set (scope PUBLIC )
6160 endif ()
6261
63- # First, include core lib 's directories in library as well
62+ # Resolve Core-Lib 's target
6463 if (link_library_BOARD_CORE_TARGET)
6564 set (core_target ${link_library_BOARD_CORE_TARGET} )
6665 else ()
6766 set (core_target ${${_target_name} _CORE_LIB_TARGET})
6867 endif ()
6968
7069 get_target_property (core_lib_includes ${core_target} INCLUDE_DIRECTORIES )
70+
71+ # Include core lib's include directories in library target, then link to it
7172 target_include_directories (${_library_name} ${scope} "${core_lib_includes} " )
7273 target_link_libraries (${_library_name} ${scope} ${core_target} )
7374
74- target_link_libraries (${_target_name} PRIVATE ${_library_name} )
75+ # Link library target to linked-to target
76+ if (link_library_PRIVATE)
77+ target_link_libraries (${_target_name} PRIVATE ${_library_name} )
78+ else ()
79+ # Link 'INTERFACE' targets publicly, otherwise code won't compile
80+ target_link_libraries (${_target_name} PUBLIC ${_library_name} )
81+ endif ()
7582
7683endfunction ()
0 commit comments