@@ -768,14 +768,37 @@ function(_add_internal_arduino_core target)
768768
769769 # get_headers_parent_directories("${core_headers};${variant_headers}" include_dirs)
770770
771- # Add the library and set the include directories
772- add_library ("${target} " STATIC ${core_headers} ${core_sources}
773- ${variant_headers} ${variant_sources} )
774- # target_include_directories(${target} PUBLIC ${include_dirs})
775- target_include_directories (${target} PUBLIC
776- "${ARDUINO_BOARD_BUILD_CORE_PATH} "
777- "${ARDUINO_BOARD_BUILD_VARIANT_PATH} " )
771+ # variant source
772+ if (NOT ${variant_sources} STREQUAL "" AND TRUE )
773+ add_library ("${target} _vsources_" OBJECT
774+ ${variant_headers}
775+ ${variant_sources} )
776+ target_include_directories ("${target} _vsources_" PUBLIC
777+ "${ARDUINO_BOARD_BUILD_VARIANT_PATH} "
778+ "${ARDUINO_BOARD_BUILD_CORE_PATH} " )
779+ # Add the library and set the include directories
780+ add_library ("${target} " STATIC ${variant_headers}
781+ ${core_headers} ${core_sources} )
782+ # target_include_directories(${target} PUBLIC ${include_dirs})
783+ target_include_directories (${target} PUBLIC
784+ "${ARDUINO_BOARD_BUILD_VARIANT_PATH} "
785+ "${ARDUINO_BOARD_BUILD_CORE_PATH} " )
786+ # Add the object library to the sources of the linking targets
787+ # Should work above CMake 3.1, but GENERATED property does not seem
788+ # to be working well causing the portable_app example (transitive
789+ # linking o core) to not to link with this in the first run.
790+ set_target_properties (${target} PROPERTIES
791+ INTERFACE_SOURCES "$<TARGET_OBJECTS:${target} _vsources_>" )
792+ else ()
793+ # Add the library and set the include directories
794+ add_library ("${target} " STATIC ${variant_headers}
795+ ${core_headers} ${core_sources} )
796+ # target_include_directories(${target} PUBLIC ${include_dirs})
797+ target_include_directories (${target} PUBLIC
798+ "${ARDUINO_BOARD_BUILD_VARIANT_PATH} "
799+ "${ARDUINO_BOARD_BUILD_CORE_PATH} " )
778800
801+ endif ()
779802 # Add the prebuild and postbuild command hooks for the core
780803 _set_arduino_target_hooks("${target} " "core.prebuild" PRE_BUILD )
781804 _set_arduino_target_hooks("${target} " "core.postbuild" POST_BUILD)
0 commit comments