diff --git a/cmake/Platform/Arduino.cmake b/cmake/Platform/Arduino.cmake index 0fda351..5cec4ce 100644 --- a/cmake/Platform/Arduino.cmake +++ b/cmake/Platform/Arduino.cmake @@ -41,6 +41,7 @@ include(ArduinoSketchFactory) include(CoreLibraryFactory) include(ArduinoLibraryFactory) +include(BlacklistedLibrariesRemover) include(ArduinoExampleFactory) include(ArduinoLibraryExampleFactory) diff --git a/cmake/Platform/Core/BoardFlags/CompilerFlagsSetter.cmake b/cmake/Platform/Core/BoardFlags/CompilerFlagsSetter.cmake index 840a870..fd7c58a 100644 --- a/cmake/Platform/Core/BoardFlags/CompilerFlagsSetter.cmake +++ b/cmake/Platform/Core/BoardFlags/CompilerFlagsSetter.cmake @@ -1,12 +1,12 @@ # ToDo: Comment -function(set_board_compiler_flags COMPILER_FLAGS ARDUINO_DEFINED_VERSION BOARD_ID IS_MANUAL) +function(set_board_compiler_flags COMPILER_FLAGS NORMALIZED_SDK_VERSION BOARD_ID IS_MANUAL) _get_board_property(${BOARD_ID} build.f_cpu FCPU) _get_board_property(${BOARD_ID} build.mcu MCU) - set(COMPILE_FLAGS "-DF_CPU=${FCPU} -DARDUINO=${ARDUINO_DEFINED_VERSION} -mmcu=${MCU}") + set(COMPILE_FLAGS "-DF_CPU=${FCPU} -DARDUINO=${NORMALIZED_SDK_VERSION} -mmcu=${MCU}") - _get_board_property_if_exists(${BOARD_ID} build.vid VID) - _get_board_property_if_exists(${BOARD_ID} build.pid PID) + _try_get_board_property(${BOARD_ID} build.vid VID) + _try_get_board_property(${BOARD_ID} build.pid PID) if (VID) set(COMPILE_FLAGS "${COMPILE_FLAGS} -DUSB_VID=${VID}") endif () diff --git a/cmake/Platform/Core/BoardFlags/FlagsSetter.cmake b/cmake/Platform/Core/BoardFlags/FlagsSetter.cmake index 43ffeeb..df05924 100644 --- a/cmake/Platform/Core/BoardFlags/FlagsSetter.cmake +++ b/cmake/Platform/Core/BoardFlags/FlagsSetter.cmake @@ -2,29 +2,26 @@ include(CompilerFlagsSetter) include(LinkerFlagsSetter) #=============================================================================# -# get_arduino_flags +# set_board_flags # [PRIVATE/INTERNAL] # -# get_arduino_flags(COMPILE_FLAGS LINK_FLAGS BOARD_ID IS_MANUAL) +# set_board_flags(COMPILER_FLAGS LINKER_FLAGS BOARD_ID IS_MANUAL) # -# COMPILER_FLAGS -Variable holding compiler flags +# COMPILER_FLAGS - Variable holding compiler flags # LINKER_FLAGS - Variable holding linker flags # BOARD_ID - The board id name # IS_MANUAL - (Advanced) Only use AVR Libc/Includes # -# Configures the the build settings for the specified Arduino Board. +# Configures the build settings for the specified Arduino Board. # #=============================================================================# function(set_board_flags COMPILER_FLAGS LINKER_FLAGS BOARD_ID IS_MANUAL) _get_board_property(${BOARD_ID} build.core BOARD_CORE) if (BOARD_CORE) - is_sdk_version_valid(IS_VERSION_VALID DEFINED_VERSION) - if (NOT ${IS_VERSION_VALID}) - return() - endif () + _get_normalized_sdk_version(NORMALIZED_SDK_VERSION) - set_board_compiler_flags(COMPILE_FLAGS ${DEFINED_VERSION} ${BOARD_ID} ${IS_MANUAL}) + set_board_compiler_flags(COMPILE_FLAGS ${NORMALIZED_SDK_VERSION} ${BOARD_ID} ${IS_MANUAL}) set_board_linker_flags(LINK_FLAGS ${BOARD_ID} ${IS_MANUAL}) # output @@ -37,25 +34,72 @@ function(set_board_flags COMPILER_FLAGS LINKER_FLAGS BOARD_ID IS_MANUAL) endfunction() -function(is_sdk_version_valid IS_VALID OUTPUT_VAR) +#=============================================================================# +# _get_normalized_sdk_version +# [PRIVATE/INTERNAL] +# +# _get_normalized_sdk_version(OUTPUT_VAR) +# +# OUTPUT_VAR - Returned variable storing the normalized version +# +# Normalizes SDK's version for a proper use of the '-DARDUINO' compile flag. +# Note that there are differences between normalized versions in specific SDK versions: +# SDK Version 1.5.8 and above - Appends zeros to version parts. +# e.g Version 1.6.5 will be normalized as 10605 +# SDK Versions between 1.0.0 and 1.5.8 - Joins all version parts together. +# e.g Version 1.5.3 will be normalized as 153 +# SDK Version 1.0.0 and below - Uses only the 'Minor' version part. +# e.g Version 0.20.0 will be normalized as 20 +# +#=============================================================================# +function(_get_normalized_sdk_version OUTPUT_VAR) - if (ARDUINO_SDK_VERSION MATCHES "([0-9]+)[.]([0-9]+)") - string(REPLACE "." "" ARDUINO_VERSION_DEFINE "${ARDUINO_SDK_VERSION}") # Normalize version (remove all periods) - set(ARDUINO_VERSION_DEFINE "") - if (CMAKE_MATCH_1 GREATER 0) - set(ARDUINO_VERSION_DEFINE "${CMAKE_MATCH_1}") - endif () - if (CMAKE_MATCH_2 GREATER 10) - set(ARDUINO_VERSION_DEFINE "${ARDUINO_VERSION_DEFINE}${CMAKE_MATCH_2}") + if (${ARDUINO_SDK_VERSION} VERSION_GREATER 1.5.8) + # -DARDUINO format has changed since 1.6.0 by appending zeros when required, + # e.g for 1.6.5 version -DARDUINO=10605 + _append_suffix_zero_to_version_if_required(${ARDUINO_SDK_VERSION_MAJOR} 10 MAJOR_VERSION) + _append_suffix_zero_to_version_if_required(${ARDUINO_SDK_VERSION_MINOR} 10 MINOR_VERSION) + set(NORMALIZED_VERSION + "${MAJOR_VERSION}${MINOR_VERSION}${ARDUINO_SDK_VERSION_PATCH}") + else () + # -DARDUINO format before 1.0.0 uses only minor version, + # e.g. for 0020 version -DARDUINO=20 + if (${ARDUINO_SDK_VERSION} VERSION_LESS 1.0.0) + set(NORMALIZED_VERSION "${ARDUINO_SDK_VERSION_MINOR}") else () - set(ARDUINO_VERSION_DEFINE "${ARDUINO_VERSION_DEFINE}0${CMAKE_MATCH_2}") + # -DARDUINO format after 1.0.0 combines all 3 version parts together, + # e.g. for 1.5.3 version -DARDUINO=153 + set(NORMALIZED_VERSION + "${ARDUINO_SDK_VERSION_MAJOR}\ + ${ARDUINO_SDK_VERSION_MINOR}\ + ${ARDUINO_SDK_VERSION_PATCH}") endif () - else () - message(WARNING "Invalid Arduino SDK Version (${ARDUINO_SDK_VERSION})") - set(${IS_VALID} False PARENT_SCOPE) endif () - set(${IS_VALID} True PARENT_SCOPE) - set(${OUTPUT_VAR} ${ARDUINO_VERSION_DEFINE} PARENT_SCOPE) + set(${OUTPUT_VAR} ${NORMALIZED_VERSION} PARENT_SCOPE) endfunction() + +#=============================================================================# +# _append_suffix_zero_to_version_if_required +# [PRIVATE/INTERNAL] +# +# _append_suffix_zero_to_version_if_required(VERSION_PART VERSION_LIMIT OUTPUT_VAR) +# +# VERSION_PART - Version to check and possibly append to. +# Must be a version part - Major, Minor or Patch. +# VERSION_LIMIT - Append limit. For a version greater than this number +# a zero will NOT be appended. +# OUTPUT_VAR - Returned variable storing the normalized version. +# +# Appends a suffic zero to the given version part if it's below than the given limit. +# Otherwise, the version part is returned as it is. +# +#=============================================================================# +macro(_append_suffix_zero_to_version_if_required VERSION_PART VERSION_LIMIT OUTPUT_VAR) + if (${VERSION_PART} LESS ${VERSION_LIMIT}) + set(${OUTPUT_VAR} "${VERSION_PART}0") + else () + set(${OUTPUT_VAR} "${VERSION_PART}") + endif () +endmacro() diff --git a/cmake/Platform/Core/BoardPropertiesReader.cmake b/cmake/Platform/Core/BoardPropertiesReader.cmake index d836dc3..7fbc5b7 100644 --- a/cmake/Platform/Core/BoardPropertiesReader.cmake +++ b/cmake/Platform/Core/BoardPropertiesReader.cmake @@ -73,7 +73,7 @@ endfunction() # # Similar to _get_board_property, except it returns empty value if value was not found. #=============================================================================# -function(_GET_BOARD_PROPERTY_IF_EXISTS BOARD_ID PROPERTY_NAME OUTPUT_VAR) +function(_try_get_board_property BOARD_ID PROPERTY_NAME OUTPUT_VAR) string(REPLACE "." ";" BOARD_INFO ${BOARD_ID}) list(GET BOARD_INFO 0 BOARD_NAME) set(VALUE ${${BOARD_NAME}.${PROPERTY_NAME}}) diff --git a/cmake/Platform/Core/Libraries/ArduinoLibraryFactory.cmake b/cmake/Platform/Core/Libraries/ArduinoLibraryFactory.cmake index 982dd03..0878707 100644 --- a/cmake/Platform/Core/Libraries/ArduinoLibraryFactory.cmake +++ b/cmake/Platform/Core/Libraries/ArduinoLibraryFactory.cmake @@ -27,7 +27,7 @@ function(make_arduino_library VAR_NAME BOARD_ID LIB_PATH COMPILE_FLAGS LINK_FLAG # Detect if recursion is needed if (NOT DEFINED ${LIB_SHORT_NAME}_RECURSE) - set(${LIB_SHORT_NAME}_RECURSE False) + set(${LIB_SHORT_NAME}_RECURSE ${ARDUINO_CMAKE_RECURSION_DEFAULT}) endif () find_sources(LIB_SRCS ${LIB_PATH} ${${LIB_SHORT_NAME}_RECURSE}) @@ -54,24 +54,32 @@ function(make_arduino_library VAR_NAME BOARD_ID LIB_PATH COMPILE_FLAGS LINK_FLAG set_target_properties(${TARGET_LIB_NAME} PROPERTIES COMPILE_FLAGS "${ARDUINO_COMPILE_FLAGS} ${LIB_INCLUDES} -I\"${LIB_PATH}\" -I\"${LIB_PATH}/utility\" ${COMPILE_FLAGS}" LINK_FLAGS "${ARDUINO_LINK_FLAGS} ${LINK_FLAGS}") - list(APPEND LIB_INCLUDES "-I\"${LIB_PATH}\" -I\"${LIB_PATH}/utility\"") + list(APPEND LIB_INCLUDES "-I\"${LIB_PATH}\";-I\"${LIB_PATH}/utility\"") if (LIB_TARGETS) list(REMOVE_ITEM LIB_TARGETS ${TARGET_LIB_NAME}) endif () + target_link_libraries(${TARGET_LIB_NAME} ${BOARD_ID}_CORE ${LIB_TARGETS}) list(APPEND LIB_TARGETS ${TARGET_LIB_NAME}) endif () + else () # Target already exists, skiping creating list(APPEND LIB_TARGETS ${TARGET_LIB_NAME}) endif () + if (LIB_TARGETS) list(REMOVE_DUPLICATES LIB_TARGETS) endif () + if (LIB_INCLUDES) + list(REMOVE_DUPLICATES LIB_INCLUDES) + endif () + set(${VAR_NAME} ${LIB_TARGETS} PARENT_SCOPE) set(${VAR_NAME}_INCLUDES ${LIB_INCLUDES} PARENT_SCOPE) + endfunction() #=============================================================================# diff --git a/cmake/Platform/Core/Libraries/BlacklistedLibrariesRemover.cmake b/cmake/Platform/Core/Libraries/BlacklistedLibrariesRemover.cmake new file mode 100644 index 0000000..6bf27eb --- /dev/null +++ b/cmake/Platform/Core/Libraries/BlacklistedLibrariesRemover.cmake @@ -0,0 +1,34 @@ +#=============================================================================# +# _REMOVE_BLACKLISTED_LIBRARIES +# [PRIVATE/INTERNAL] +# +# _REMOVE_BLACKLISTED_LIBRARIES(LIBRARY_LIST OUTPUT_VAR) +# +# LIBRARY_LIST - List of libraries to remove blacklisted libraries from +# OUTPUT_VAR - Original list of libraries without blacklisted libraries. +# +# Returns a list of libraries without blacklisted libraries. +# +# Arduino-CMake looks for Arduino libraries whose names match those of include files encountered. +# Under certain circumstances this leads to undesired behavior. +# An example is an include file 'Keyboard.h' in a project that has no relation to +# Arduino's standard Keyboard library. +# To prevent the standard library from being falsely added to the list of libraries to build, +# this function removes all blacklisted libraries from the source list, which contains +# all the included libraries found in the search process. +# In the example above the blacklisted and remove library would be +# ${ARDUINO_SDK_PATH}/libraries/Keyboard/src). +# +function(_REMOVE_BLACKLISTED_LIBRARIES LIBRARY_LIST OUTPUT_VAR) + set(NEW_LIBS) + foreach (LIB ${LIBRARY_LIST}) + list(FIND ARDUINO_LIBRARY_BLACKLIST "${LIB}" BLACKLISTED_LIB_INDEX) + if (NOT ${BLACKLISTED_LIB_INDEX} GREATER -1) + list(APPEND NEW_LIBS "${LIB}") + else () + ARDUINO_DEBUG_MSG("Suppressing blacklisted library ${LIB}") + endif () + endforeach () + + set("${OUTPUT_VAR}" "${NEW_LIBS}" PARENT_SCOPE) +endfunction() \ No newline at end of file diff --git a/cmake/Platform/Core/LibraryFinder.cmake b/cmake/Platform/Core/LibraryFinder.cmake index a2e45c4..5425bc3 100644 --- a/cmake/Platform/Core/LibraryFinder.cmake +++ b/cmake/Platform/Core/LibraryFinder.cmake @@ -129,5 +129,8 @@ function(find_arduino_libraries VAR_NAME SRCS ARDLIBS) if (ARDUINO_LIBS) list(REMOVE_DUPLICATES ARDUINO_LIBS) endif () - set(${VAR_NAME} ${ARDUINO_LIBS} PARENT_SCOPE) + + _REMOVE_BLACKLISTED_LIBRARIES("${ARDUINO_LIBS}" FILTERED_LIBRARIES) + set(${VAR_NAME} ${FILTERED_LIBRARIES} PARENT_SCOPE) + endfunction() diff --git a/cmake/Platform/Core/Sketch/ArduinoSketchFactory.cmake b/cmake/Platform/Core/Sketch/ArduinoSketchFactory.cmake index e889f6e..5949659 100644 --- a/cmake/Platform/Core/Sketch/ArduinoSketchFactory.cmake +++ b/cmake/Platform/Core/Sketch/ArduinoSketchFactory.cmake @@ -30,7 +30,6 @@ function(make_arduino_sketch TARGET_NAME SKETCH_PATH OUTPUT_VAR) (${SKETCH_NAME}.pde or ${SKETCH_NAME}.ino) at ${SKETCH_PATH}!") endif () list(SORT SKETCH_SOURCES) - message(STATUS "SKETCH_SOURCES: ${SKETCH_SOURCES}") convert_sketch_to_cpp(${SKETCH_SOURCES} ${SKETCH_CPP}) diff --git a/cmake/Platform/Core/Targets/ArduinoBootloaderBurnTargetCreator.cmake b/cmake/Platform/Core/Targets/ArduinoBootloaderBurnTargetCreator.cmake index ef49a62..a28a2ef 100644 --- a/cmake/Platform/Core/Targets/ArduinoBootloaderBurnTargetCreator.cmake +++ b/cmake/Platform/Core/Targets/ArduinoBootloaderBurnTargetCreator.cmake @@ -28,7 +28,7 @@ function(create_arduino_bootloader_burn_target TARGET_NAME BOARD_ID PROGRAMMER P endif () # look at bootloader.file - _get_board_property_if_exists(${BOARD_ID} bootloader.file BOOTLOADER_FILE) + _try_get_board_property(${BOARD_ID} bootloader.file BOOTLOADER_FILE) if (NOT BOOTLOADER_FILE) message("Missing bootloader.file, not creating bootloader burn target ${BOOTLOADER_TARGET}.") return() @@ -49,7 +49,7 @@ function(create_arduino_bootloader_burn_target TARGET_NAME BOARD_ID PROGRAMMER P #check for required bootloader parameters foreach (ITEM lock_bits unlock_bits high_fuses low_fuses) #do not make fatal error if field doesn't exists, just don't create bootloader burn target - _get_board_property_if_exists(${BOARD_ID} bootloader.${ITEM} BOOTLOADER_${ITEM}) + _try_get_board_property(${BOARD_ID} bootloader.${ITEM} BOOTLOADER_${ITEM}) if (NOT BOOTLOADER_${ITEM}) message("Missing bootloader.${ITEM}, not creating bootloader burn target ${BOOTLOADER_TARGET}.") return() @@ -62,7 +62,7 @@ function(create_arduino_bootloader_burn_target TARGET_NAME BOARD_ID PROGRAMMER P # Set unlock bits and fuses (because chip is going to be erased) list(APPEND AVRDUDE_ARGS "-Ulock:w:${BOOTLOADER_unlock_bits}:m") # extended fuses is optional - _get_board_property_if_exists(${BOARD_ID} bootloader.extended_fuses BOOTLOADER_extended_fuses) + _try_get_board_property(${BOARD_ID} bootloader.extended_fuses BOOTLOADER_extended_fuses) if (BOOTLOADER_extended_fuses) list(APPEND AVRDUDE_ARGS "-Uefuse:w:${BOOTLOADER_extended_fuses}:m") endif() diff --git a/cmake/Platform/Initialization/DetectVersion.cmake b/cmake/Platform/Initialization/DetectVersion.cmake index a7da37b..d7d1115 100644 --- a/cmake/Platform/Initialization/DetectVersion.cmake +++ b/cmake/Platform/Initialization/DetectVersion.cmake @@ -13,9 +13,13 @@ find_file(ARDUINO_VERSION_PATH PATHS ${ARDUINO_SDK_PATH} DOC "Path to Arduino version file.") +find_file(ARDUINO_REVISION_PATH + NAMES revisions.txt + PATHS ${ARDUINO_SDK_PATH} + DOC "Path to Arduino's revision-tracking file.") + if (NOT ARDUINO_VERSION_PATH) message(FATAL_ERROR "Couldn't find SDK's version file, aborting.") - return() endif () file(READ ${ARDUINO_VERSION_PATH} RAW_VERSION) @@ -27,20 +31,37 @@ elseif ("${RAW_VERSION}" MATCHES "[ ]*([0-9]+[.][0-9]+)") set(PARSED_VERSION ${CMAKE_MATCH_1}.0) endif () +if (NOT ARDUINO_REVISION_PATH) + message(WARNING "Couldn't find SDK's revisions file, defaulting to 0.") +else () + file(READ ${ARDUINO_REVISION_PATH} RAW_REVISION 0 30) + if ("${RAW_REVISION}" MATCHES ".*${PARSED_VERSION}.*[-].*") + string(REGEX MATCH "[-][ ]?([0-9]+[.][0-9]+[.][0-9]+)" + TMP_REV ${RAW_REVISION}) + set(PARSED_REVISION ${CMAKE_MATCH_1}) + else () + set(PARSED_REVISION 0) + endif () +endif () + if (NOT PARSED_VERSION STREQUAL "") string(REPLACE "." ";" SPLIT_VERSION ${PARSED_VERSION}) list(GET SPLIT_VERSION 0 SPLIT_VERSION_MAJOR) list(GET SPLIT_VERSION 1 SPLIT_VERSION_MINOR) list(GET SPLIT_VERSION 2 SPLIT_VERSION_PATCH) + string(CONCAT FULL_SDK_VERSION "${PARSED_VERSION}" "-" "${PARSED_REVISION}") + set(ARDUINO_SDK_VERSION "${PARSED_VERSION}" CACHE STRING "Arduino SDK Version") - set(ARDUINO_SDK_VERSION_MAJOR ${ARDUINO_SDK_VERSION_MAJOR} CACHE STRING "Arduino SDK Major Version") - set(ARDUINO_SDK_VERSION_MINOR ${ARDUINO_SDK_VERSION_MINOR} CACHE STRING "Arduino SDK Minor Version") - set(ARDUINO_SDK_VERSION_PATCH ${ARDUINO_SDK_VERSION_PATCH} CACHE STRING "Arduino SDK Patch Version") + set(ARUDINO_SDK_FULL_VERSION "${FULL_SDK_VERSION}" CACHE STRING "Full Arduino SDK version") + set(ARDUINO_SDK_VERSION_MAJOR ${SPLIT_VERSION_MAJOR} CACHE STRING "Arduino SDK Major Version") + set(ARDUINO_SDK_VERSION_MINOR ${SPLIT_VERSION_MINOR} CACHE STRING "Arduino SDK Minor Version") + set(ARDUINO_SDK_VERSION_PATCH ${SPLIT_VERSION_PATCH} CACHE STRING "Arduino SDK Patch Version") + set(ARDUINO_SDK_VERSION_REVISION ${PARSED_REVISION} CACHE STRING "Arduino SDK Revision") endif () if (ARDUINO_SDK_VERSION VERSION_LESS 0.19) message(FATAL_ERROR "Unsupported Arduino SDK (requires version 0.19 or higher)") endif () -message(STATUS "Arduino SDK version ${ARDUINO_SDK_VERSION}: ${ARDUINO_SDK_PATH}") +message(STATUS "Arduino SDK version ${ARUDINO_SDK_FULL_VERSION}: ${ARDUINO_SDK_PATH}") diff --git a/cmake/Platform/Initialization/Initializer.cmake b/cmake/Platform/Initialization/Initializer.cmake index b8c866a..80e63be 100644 --- a/cmake/Platform/Initialization/Initializer.cmake +++ b/cmake/Platform/Initialization/Initializer.cmake @@ -14,6 +14,7 @@ if (NOT ARDUINO_FOUND AND ARDUINO_SDK_PATH) include(FindPrograms) include(SetDefaults) include(SetupFirmwareSizeScript) + include(SetupLibraryBlacklist) include(TestSetup) include(DefineAdvancedVariables) diff --git a/cmake/Platform/Initialization/RegisterHardwarePlatform.cmake b/cmake/Platform/Initialization/RegisterHardwarePlatform.cmake index 0fbbdd2..a890266 100644 --- a/cmake/Platform/Initialization/RegisterHardwarePlatform.cmake +++ b/cmake/Platform/Initialization/RegisterHardwarePlatform.cmake @@ -1,96 +1,18 @@ -#=============================================================================# -# ToDo: Document -#=============================================================================# -set(PLATFORM_PATH ${ARDUINO_SDK_PATH}/hardware/arduino/) -string(REGEX REPLACE "/$" "" PLATFORM_PATH ${PLATFORM_PATH}) -GET_FILENAME_COMPONENT(PLATFORM ${PLATFORM_PATH} NAME) - -# platform path changed in versions 1.5 and greater -if (ARDUINO_SDK_VERSION VERSION_GREATER 1.0.5) - set(PLATFORM_PATH "${PLATFORM_PATH}/avr") +if (NOT PLATFORM_PATH) + # Arduino is assumed as the default platform + set(PLATFORM_PATH ${ARDUINO_SDK_PATH}/hardware/arduino/) endif () +string(REGEX REPLACE "/$" "" PLATFORM_PATH ${PLATFORM_PATH}) +GET_FILENAME_COMPONENT(VENDOR_ID ${PLATFORM_PATH} NAME) +GET_FILENAME_COMPONENT(BASE_PATH ${PLATFORM_PATH} PATH) -if (NOT PLATFORM) - return() -endif () - -# Avoid defining a platform multiple times if it has already been defined before -string(TOUPPER ${PLATFORM} PLATFORM) -list(FIND ARDUINO_PLATFORMS ${PLATFORM} PLATFORM_EXISTS) - -if (PLATFORM_EXISTS GREATER -1) - return() +if (NOT PLATFORM_ARCHITECTURE) + # avr is the default architecture + set(PLATFORM_ARCHITECTURE "avr") endif () -set(${PLATFORM}_PLATFORM_PATH ${PLATFORM_PATH} CACHE INTERNAL "The path to ${PLATFORM}") -set(ARDUINO_PLATFORMS ${ARDUINO_PLATFORMS} ${PLATFORM} CACHE INTERNAL "A list of registered platforms") - -find_file(${PLATFORM}_CORES_PATH - NAMES cores - PATHS ${PLATFORM_PATH} - DOC "Path to directory containing the Arduino core sources.") - -find_file(${PLATFORM}_VARIANTS_PATH - NAMES variants - PATHS ${PLATFORM_PATH} - DOC "Path to directory containing the Arduino variant sources.") - -find_file(${PLATFORM}_BOOTLOADERS_PATH - NAMES bootloaders - PATHS ${PLATFORM_PATH} - DOC "Path to directory containing the Arduino bootloader images and sources.") - -find_file(${PLATFORM}_PROGRAMMERS_PATH - NAMES programmers.txt - PATHS ${PLATFORM_PATH} - DOC "Path to Arduino programmers definition file.") - -find_file(${PLATFORM}_BOARDS_PATH - NAMES boards.txt - PATHS ${PLATFORM_PATH} - DOC "Path to Arduino boards definition file.") - -# some libraries are in platform path in versions 1.5 and greater -if (ARDUINO_SDK_VERSION VERSION_GREATER 1.0.5) - find_file(${PLATFORM}_PLATFORM_LIBRARIES_PATH - NAMES libraries - PATHS ${PLATFORM_PATH} - DOC "Path to platform directory containing the Arduino libraries.") - set(ARDUINO_PLATFORM_LIBRARIES_PATH "${${PLATFORM}_PLATFORM_LIBRARIES_PATH}") +if (CUSTOM_PLATFORM_REGISTRATION_SCRIPT) + include("${CUSTOM_PLATFORM_REGISTRATION_SCRIPT}") else () - set(ARDUINO_PLATFORM_LIBRARIES_PATH "") -endif () - -if (${PLATFORM}_BOARDS_PATH) - set(SETTINGS_LIST ${PLATFORM}_BOARDS) - set(SETTINGS_PATH "${${PLATFORM}_BOARDS_PATH}") - include(LoadArduinoPlatformSettings) -endif () - -if (${PLATFORM}_PROGRAMMERS_PATH) - set(SETTINGS_LIST ${PLATFORM}_PROGRAMMERS) - set(SETTINGS_PATH "${${PLATFORM}_PROGRAMMERS_PATH}") - include(LoadArduinoPlatformSettings) -endif () - -if (${PLATFORM}_VARIANTS_PATH) - file(GLOB sub-dir ${${PLATFORM}_VARIANTS_PATH}/*) - foreach (dir ${sub-dir}) - if (IS_DIRECTORY ${dir}) - get_filename_component(variant ${dir} NAME) - set(VARIANTS ${VARIANTS} ${variant} CACHE INTERNAL "A list of registered variant boards") - set(${variant}.path ${dir} CACHE INTERNAL "The path to the variant ${variant}") - endif () - endforeach () -endif () - -if (${PLATFORM}_CORES_PATH) - file(GLOB sub-dir ${${PLATFORM}_CORES_PATH}/*) - foreach (dir ${sub-dir}) - if (IS_DIRECTORY ${dir}) - get_filename_component(core ${dir} NAME) - set(CORES ${CORES} ${core} CACHE INTERNAL "A list of registered cores") - set(${core}.path ${dir} CACHE INTERNAL "The path to the core ${core}") - endif () - endforeach () + include(RegisterSpecificHardwarePlatform) endif () diff --git a/cmake/Platform/Initialization/RegisterSpecificHardwarePlatform.cmake b/cmake/Platform/Initialization/RegisterSpecificHardwarePlatform.cmake new file mode 100644 index 0000000..434384f --- /dev/null +++ b/cmake/Platform/Initialization/RegisterSpecificHardwarePlatform.cmake @@ -0,0 +1,96 @@ +#=============================================================================# +# ToDo: Document +#=============================================================================# + +set(PLATFORM_PATH "${BASE_PATH}/${VENDOR_ID}/${PLATFORM_ARCHITECTURE}") +set(PLATFORM "${VENDOR_ID}") +set(ARCHITECTURE_ID ${PLATFORM_ARCHITECTURE}) + +# Avoid defining a platform multiple times if it has already been defined before +string(TOUPPER ${PLATFORM} PLATFORM) +list(FIND ARDUINO_PLATFORMS ${PLATFORM} PLATFORM_EXISTS) + +if (PLATFORM_EXISTS GREATER -1) + return() +endif () + +set(${PLATFORM}_PLATFORM_PATH ${PLATFORM_PATH} CACHE INTERNAL "The path to ${PLATFORM}") +set(ARDUINO_PLATFORMS ${ARDUINO_PLATFORMS} ${PLATFORM} CACHE INTERNAL "A list of registered platforms") + +find_file(${PLATFORM}_CORES_PATH + NAMES cores + PATHS ${PLATFORM_PATH} + DOC "Path to directory containing the Arduino core sources.") + +find_file(${PLATFORM}_VARIANTS_PATH + NAMES variants + PATHS ${PLATFORM_PATH} + DOC "Path to directory containing the Arduino variant sources.") + +find_file(${PLATFORM}_BOOTLOADERS_PATH + NAMES bootloaders + PATHS ${PLATFORM_PATH} + DOC "Path to directory containing the Arduino bootloader images and sources.") + +find_file(${PLATFORM}_PROGRAMMERS_PATH + NAMES programmers.txt + PATHS ${PLATFORM_PATH} + DOC "Path to Arduino programmers definition file.") + +find_file(${PLATFORM}_BOARDS_PATH + NAMES boards.txt + PATHS ${PLATFORM_PATH} + DOC "Path to Arduino boards definition file.") + +# some libraries are in platform path in versions 1.5 and greater +if (ARDUINO_SDK_VERSION VERSION_GREATER 1.0.5) + find_file(${PLATFORM}_PLATFORM_LIBRARIES_PATH + NAMES libraries + PATHS ${PLATFORM_PATH} + DOC "Path to platform directory containing the Arduino libraries.") + set(ARDUINO_PLATFORM_LIBRARIES_PATH "${${PLATFORM}_PLATFORM_LIBRARIES_PATH}") +else () + set(ARDUINO_PLATFORM_LIBRARIES_PATH "") +endif () + +if (${PLATFORM}_BOARDS_PATH) + set(SETTINGS_LIST ${PLATFORM}_BOARDS) + set(SETTINGS_PATH "${${PLATFORM}_BOARDS_PATH}") + include(LoadArduinoPlatformSettings) +endif () + +if (${PLATFORM}_PROGRAMMERS_PATH) + set(SETTINGS_LIST ${PLATFORM}_PROGRAMMERS) + set(SETTINGS_PATH "${${PLATFORM}_PROGRAMMERS_PATH}") + include(LoadArduinoPlatformSettings) +endif () + +if (${PLATFORM}_VARIANTS_PATH) + file(GLOB sub-dir ${${PLATFORM}_VARIANTS_PATH}/*) + foreach (dir ${sub-dir}) + if (IS_DIRECTORY ${dir}) + get_filename_component(variant ${dir} NAME) + set(VARIANTS ${VARIANTS} ${variant} CACHE INTERNAL "A list of registered variant boards") + set(${variant}.path ${dir} CACHE INTERNAL "The path to the variant ${variant}") + endif () + endforeach () +endif () + +if (${PLATFORM}_CORES_PATH) + file(GLOB sub-dir ${${PLATFORM}_CORES_PATH}/*) + foreach (dir ${sub-dir}) + if (IS_DIRECTORY ${dir}) + get_filename_component(core ${dir} NAME) + set(CORES ${CORES} ${core} CACHE INTERNAL "A list of registered cores") + set(${core}.path ${dir} CACHE INTERNAL "The path to the core ${core}") + + # See https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#referencing-another-core-variant-or-tool + # for an explanation why cores must also be available as : + # and :: + set(CORES ${CORES} "${VENDOR_ID}:${core}" CACHE INTERNAL "A list of registered cores") + set(${VENDOR_ID}:${core}.path ${dir} CACHE INTERNAL "The path to the core ${core}") + set(CORES ${CORES} "${VENDOR_ID}:${ARCHITECTURE_ID}:${core}" CACHE INTERNAL "A list of registered cores") + + endif () + endforeach () +endif () diff --git a/cmake/Platform/Initialization/SetDefaults.cmake b/cmake/Platform/Initialization/SetDefaults.cmake index 14ee7a1..945a9d0 100644 --- a/cmake/Platform/Initialization/SetDefaults.cmake +++ b/cmake/Platform/Initialization/SetDefaults.cmake @@ -2,3 +2,5 @@ set(ARDUINO_DEFAULT_BOARD uno CACHE STRING "Default Arduino Board ID when not sp set(ARDUINO_DEFAULT_PORT CACHE STRING "Default Arduino port when not specified.") set(ARDUINO_DEFAULT_SERIAL CACHE STRING "Default Arduino Serial command when not specified.") set(ARDUINO_DEFAULT_PROGRAMMER CACHE STRING "Default Arduino Programmer ID when not specified.") +set(ARDUINO_CMAKE_RECURSION_DEFAULT FALSE CACHE BOOL + "The default recursion behavior during library setup") diff --git a/cmake/Platform/Initialization/SetupLibraryBlacklist.cmake b/cmake/Platform/Initialization/SetupLibraryBlacklist.cmake new file mode 100644 index 0000000..94253c2 --- /dev/null +++ b/cmake/Platform/Initialization/SetupLibraryBlacklist.cmake @@ -0,0 +1,3 @@ +set(ARDUINO_LIBRARY_BLACKLIST "" CACHE STRING + "A list of absolute paths to Arduino libraries that are meant to be ignored \ +during library search") \ No newline at end of file