Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 4, 2019. It is now read-only.

Integrated various fixes and improvements to comply with refactored version #23

Merged
merged 12 commits into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/Platform/Arduino.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ include(ArduinoSketchFactory)

include(CoreLibraryFactory)
include(ArduinoLibraryFactory)
include(BlacklistedLibrariesRemover)

include(ArduinoExampleFactory)
include(ArduinoLibraryExampleFactory)
Expand Down
8 changes: 4 additions & 4 deletions cmake/Platform/Core/BoardFlags/CompilerFlagsSetter.cmake
Original file line number Diff line number Diff line change
@@ -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 ()
Expand Down
92 changes: 68 additions & 24 deletions cmake/Platform/Core/BoardFlags/FlagsSetter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
2 changes: 1 addition & 1 deletion cmake/Platform/Core/BoardPropertiesReader.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}})
Expand Down
12 changes: 10 additions & 2 deletions cmake/Platform/Core/Libraries/ArduinoLibraryFactory.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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()

#=============================================================================#
Expand Down
34 changes: 34 additions & 0 deletions cmake/Platform/Core/Libraries/BlacklistedLibrariesRemover.cmake
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 4 additions & 1 deletion cmake/Platform/Core/LibraryFinder.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
1 change: 0 additions & 1 deletion cmake/Platform/Core/Sketch/ArduinoSketchFactory.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
31 changes: 26 additions & 5 deletions cmake/Platform/Initialization/DetectVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}")
1 change: 1 addition & 0 deletions cmake/Platform/Initialization/Initializer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if (NOT ARDUINO_FOUND AND ARDUINO_SDK_PATH)
include(FindPrograms)
include(SetDefaults)
include(SetupFirmwareSizeScript)
include(SetupLibraryBlacklist)

include(TestSetup)
include(DefineAdvancedVariables)
Expand Down
Loading