Skip to content
Permalink
Browse files

Set HYDRO_TARGET_DEVICE_XXX in main CMakeLists.txt

This way it can be configured by projects importing libhydrogen as a
dependency via add_subdirectory. The Arduino toolchain file still
automatically configures it to match the target Arduino MCU.
  • Loading branch information...
spinda committed Jun 26, 2019
1 parent 5649856 commit 8868ceb0e23fe77afce727b422847684fe69c7a2
Showing with 14 additions and 4 deletions.
  1. +7 −1 CMakeLists.txt
  2. +7 −3 cmake/arduino-avr-toolchain.cmake
@@ -39,14 +39,18 @@ set(arduino_files "library.properties")

# Compile options

get_setting(target_arch STRING "Target system architecture (fed to the compiler's -march=...).")
get_setting(target_arch STRING "Target system architecture (fed to the compiler's -march=XXX).")
if(NOT target_arch AND NOT CMAKE_CROSSCOMPILING)
set(target_arch native)
endif()

get_setting(target_device STRING "Target device identifier (defines HYDRO_TARGET_DEVICE_XXX).")

set(compile_options
# --- GNU, Clang ---
$<$<OR:$<C_COMPILER_ID:AppleClang>,$<C_COMPILER_ID:Clang>,$<C_COMPILER_ID:GNU>>:
# ---- Definitions ----
$<$<BOOL:${target_device}>:-DHYDRO_TARGET_DEVICE_${target_device}>
# ---- Optimizations ----
-Os $<$<BOOL:${target_arch}>:-march=${target_arch}> -fno-exceptions
# ---- Warnings ----
@@ -69,6 +73,8 @@ set(compile_options
>
# --- MSVC ---
$<$<C_COMPILER_ID:MSVC>:
# ---- Definitions ----
$<$<BOOL:${target_device}>:/DHYDRO_TARGET_DEVICE_${target_device}>
# ---- Optimizations ----
/Os /EHsc
# ---- Warnings ----
@@ -11,6 +11,11 @@ function(get_setting setting_name setting_type setting_description)
set("${setting_name}" "${${setting_external_name}}" PARENT_SCOPE)
endfunction()

set(project_setting_prefix HYDROGEN)
function(set_project_setting setting_name setting_value)
set("${project_setting_prefix}_${setting_name}" "${setting_value}" CACHE INTERNAL "")
endfunction()

# Target device setting

get_setting(target_device STRING "Target Arduino device MCU identifier.")
@@ -19,7 +24,7 @@ if(NOT target_device)
endif()

if("${target_device}" STREQUAL atmega328p)
set(hw_type ATMEGA328)
set_project_setting(TARGET_DEVICE ATMEGA328)
else()
message(FATAL_ERROR "Unrecognized ${setting_prefix}_TARGET_DEVICE value ${target_device}")
endif()
@@ -107,8 +112,7 @@ set(CMAKE_ASM_OUTPUT_EXTENSION .o)
# Add compile flags

string(APPEND CMAKE_C_FLAGS " -mmcu=${target_device} -Os -mcall-prologues -fno-exceptions"
" -ffunction-sections -fdata-sections -flto"
" -DHYDRO_TARGET_DEVICE_${hw_type}")
" -ffunction-sections -fdata-sections -flto")

# Add include directories

0 comments on commit 8868ceb

Please sign in to comment.
You can’t perform that action at this time.