Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arduino-cmake Super Build #74

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 12 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@
# Description: Arduino CMake example #
# #
#=============================================================================#
set(CMAKE_TOOLCHAIN_FILE cmake/ArduinoToolchain.cmake) # Arduino Toolchain
cmake_minimum_required(VERSION 2.8)
project(ARDUINO C CXX)

# -----------------------------------------------------------------------------
# Enable SuperBuild option
# -----------------------------------------------------------------------------
option(ARDUINO_SUPERBUILD "Superbuild option." ON)

if(ARDUINO_SUPERBUILD)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SuperBuild.cmake)
return()
endif(ARDUINO_SUPERBUILD)

cmake_minimum_required(VERSION 2.8)
#====================================================================#
# Setup Project #
#====================================================================#
project(ArduinoExample C CXX)

print_board_list()
print_programmer_list()

#
add_subdirectory(example) #add the example directory into build
76 changes: 0 additions & 76 deletions cmake/ArduinoToolchain.cmake

This file was deleted.

27 changes: 9 additions & 18 deletions cmake/Platform/Arduino.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,6 @@
cmake_minimum_required(VERSION 2.8.5)
include(CMakeParseArguments)






#=============================================================================#
# User Functions
#=============================================================================#
Expand Down Expand Up @@ -400,7 +395,6 @@ function(GENERATE_ARDUINO_LIBRARY INPUT_NAME)
set_target_properties(${INPUT_NAME} PROPERTIES
COMPILE_FLAGS "${ARDUINO_COMPILE_FLAGS} ${COMPILE_FLAGS} ${LIB_DEP_INCLUDES}"
LINK_FLAGS "${ARDUINO_LINK_FLAGS} ${LINK_FLAGS}")

target_link_libraries(${INPUT_NAME} ${ALL_LIBS} "-lc -lm")
endfunction()

Expand Down Expand Up @@ -1447,7 +1441,6 @@ function(detect_arduino_version VAR_NAME)
elseif("${RAW_VERSION}" MATCHES "[ ]*([0-9]+[.][0-9]+)")
set(PARSED_VERSION ${CMAKE_MATCH_1}.0)
endif()

if(NOT PARSED_VERSION STREQUAL "")
string(REPLACE "." ";" SPLIT_VERSION ${PARSED_VERSION})
list(GET SPLIT_VERSION 0 SPLIT_VERSION_MAJOR)
Expand Down Expand Up @@ -2038,11 +2031,6 @@ function(ERROR_FOR_UNPARSED PREFIX)
endif()
endfunction()






#=============================================================================#
# C Flags
#=============================================================================#
Expand Down Expand Up @@ -2105,6 +2093,7 @@ set(ARDUINO_AVRDUDE_FLAGS -V CACHE STRING "")
#=============================================================================#
# Initialization
#=============================================================================#

if(NOT ARDUINO_FOUND AND ARDUINO_SDK_PATH)
register_hardware_platform(${ARDUINO_SDK_PATH}/hardware/arduino/)

Expand Down Expand Up @@ -2158,18 +2147,20 @@ if(NOT ARDUINO_FOUND AND ARDUINO_SDK_PATH)
AVRSIZE_PROGRAM
MSG "Invalid Arduino SDK path (${ARDUINO_SDK_PATH}).\n")

detect_arduino_version(ARDUINO_SDK_VERSION)
set(ARDUINO_SDK_VERSION ${ARDUINO_SDK_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")
if(NOT ARDUINO_SDK_VERSION)
detect_arduino_version(ARDUINO_SDK_VERSION)
set(ARDUINO_SDK_VERSION ${ARDUINO_SDK_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")
endif()

if(ARDUINO_SDK_VERSION VERSION_LESS 0.19)
message(FATAL_ERROR "Unsupported Arduino SDK (require verion 0.19 or higher)")
endif()

message(STATUS "Arduino SDK version ${ARDUINO_SDK_VERSION}: ${ARDUINO_SDK_PATH}")

setup_arduino_size_script(ARDUINO_SIZE_SCRIPT)
set(ARDUINO_SIZE_SCRIPT ${ARDUINO_SIZE_SCRIPT} CACHE INTERNAL "Arduino Size Script")

Expand Down
146 changes: 146 additions & 0 deletions cmake/SuperBuild.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
###########################################################################
#
# Copyright (c) Kitware Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################

set(ARDUINO_DEPENDENCIES ARDUINO_SDK AVRDUDE)

#-----------------------------------------------------------------------------
# WARNING - No change should be required after this comment
# when you are adding a new external project dependency.
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Needed to build the arduino sdk sources
#-----------------------------------------------------------------------------
find_program(PATCH_EXECUTABLE patch)

# -----------------------------------------------------------------------------
# Path to ARDUINO cmake modules
# -----------------------------------------------------------------------------
set(ARDUINO_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

#-----------------------------------------------------------------------------
# Update CMake module path
#
set(CMAKE_MODULE_PATH ${ARDUINO_MODULE_PATH} ${ARDUINO_MODULE_PATH})

#-----------------------------------------------------------------------------
# Enable and setup External project global properties
#
include(ExternalProject)
include(SuperBuild/CheckExternalProjectDependency)
include(SuperBuild/Versions)

set(ep_install_dir ${CMAKE_BINARY_DIR}/SuperBuild)
set(ep_suffix "-cmake")

set(ep_common_c_flags "${CMAKE_C_FLAGS_INIT} ${ADDITIONAL_C_FLAGS}")
set(ep_common_cxx_flags "${CMAKE_CXX_FLAGS_INIT} ${ADDITIONAL_CXX_FLAGS}")

# Compute -G arg for configuring external projects with the same CMake generator:
if(CMAKE_EXTRA_GENERATOR)
set(gen "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
else()
set(gen "${CMAKE_GENERATOR}")
endif()

# This variable will contain the list of CMake variable specific to each external project
# that should passed to ARDUINO.
# The item of this list should have the following form: -D<EP>_DIR:PATH=${<EP>_DIR}
# where '<EP>' is an external project name.
set(ARDUINO_SUPERBUILD_EP_ARGS)

CheckExternalProjectDependency(ARDUINO)

#-----------------------------------------------------------------------------
# Makes sure ${CMAKE_BINARY_DIR}/bin and ${CMAKE_BINARY_DIR}/lib exists
#-----------------------------------------------------------------------------
IF(NOT EXISTS ${CMAKE_BINARY_DIR}/bin)
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
ENDIF()
IF(NOT EXISTS ${CMAKE_BINARY_DIR}/lib)
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
ENDIF()

#-----------------------------------------------------------------------------
# Set CMake OSX variable to pass down the external project
#-----------------------------------------------------------------------------
set(CMAKE_OSX_EXTERNAL_PROJECT_ARGS)
if(APPLE)
list(APPEND CMAKE_OSX_EXTERNAL_PROJECT_ARGS
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
endif()

#-----------------------------------------------------------------------------
# ARDUINO Configure
#-----------------------------------------------------------------------------
ExternalProject_Add(ARDUINO-Configure
SOURCE_DIR ${ARDUINO_SOURCE_DIR}
BINARY_DIR ${CMAKE_BINARY_DIR}/ARDUINO-build
DOWNLOAD_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
CMAKE_GENERATOR ${gen}
CMAKE_ARGS
-DCMAKE_SYSTEM_NAME=Arduino
${CMAKE_OSX_EXTERNAL_PROJECT_ARGS}
-DARDUINO_SUPERBUILD:BOOL=OFF
-DARDUINO_SDK_VERSION:STRING=${ARDUINO_MAJOR}.${ARDUINO_MINOR}.${ARDUINO_PATCH}
-DARDUINO_SDK_VERSION_MAJOR:STRING=${ARDUINO_MAJOR}
-ARDUINO_SDK_VERSION_MINOR:STRING=${ARDUINO_MINOR}
-DARDUINO_SDK_VERSION_PATCH:STRING=${ARDUINO_PATCH}
-DCMAKE_MODULE_PATH:PATH=${ARDUINO_MODULE_PATH}
-DCMAKE_FIND_ROOT_PATH=${CMAKE_FIND_ROOT_PATH}
-DCMAKE_PREFIX_PATH:PATH=${ep_install_dir}/avr
-DCMAKE_INCLUDE_PATH:PATH=${ep_install_dir}/etc
${ARDUINO_SUPERBUILD_EP_ARGS}

DEPENDS
${ARDUINO_DEPENDENCIES}
)

if(CMAKE_GENERATOR MATCHES ".*Makefiles.*")
set(arduino_build_cmd "$(MAKE)")
else()
set(arduino_build_cmd ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/ARDUINO-build --config ${CMAKE_CFG_INTDIR})
endif()

# #-----------------------------------------------------------------------------
# # ARDUINO
# #
if(NOT DEFINED SUPERBUILD_EXCLUDE_ARDUINO_BUILD_TARGET OR NOT SUPERBUILD_EXCLUDE_ARDUINO_BUILD_TARGET)
set(ARDUINO_BUILD_TARGET_ALL_OPTION "ALL")
else()
set(ARDUINO_BUILD_TARGET_ALL_OPTION "")
endif()

add_custom_target(ARDUINO-Build ${ARDUINO_BUILD_TARGET_ALL_OPTION}
COMMAND ${arduino_build_cmd}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/ARDUINO-build
)
add_dependencies(ARDUINO-Build ARDUINO-Configure )

# #-----------------------------------------------------------------------------
# # Custom target allowing to drive the build of ARDUINO project itself
# #
add_custom_target(ARDUINO
COMMAND ${arduino_build_cmd}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/ARDUINO-build
)

Loading