diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2016-09-12 00:13:59 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2016-09-12 00:13:59 +0200 |
commit | 17ced7d38a9f1fcefc723420038470b4382f6dad (patch) | |
tree | 15f9c0d6b5182bef59ac64456ff0ecbdcc475ed3 | |
parent | 1e44cbf29d35ca020e0402f2a8289935abcb54c6 (diff) | |
download | mcu.cmake-17ced7d38a9f1fcefc723420038470b4382f6dad.tar.gz mcu.cmake-17ced7d38a9f1fcefc723420038470b4382f6dad.tar.bz2 mcu.cmake-17ced7d38a9f1fcefc723420038470b4382f6dad.tar.xz mcu.cmake-17ced7d38a9f1fcefc723420038470b4382f6dad.zip |
o Working version back to listing everything in the cmake file but some help from the cmake libs.
-rw-r--r-- | mcu.cmake | 4 | ||||
-rw-r--r-- | mcu_include_directories_from_sources.cmake | 47 | ||||
-rw-r--r-- | nrf51.cmake | 2 | ||||
-rw-r--r-- | nrf51/utils.cmake | 187 |
4 files changed, 168 insertions, 72 deletions
@@ -1,9 +1,11 @@ if (NOT MCU_CHIP) message(FATAL_ERROR "Missing required argument CHIP.") -elseif (MCU_CHIP MATCHES nrf51822) +elseif (MCU_CHIP MATCHES "nrf5.*") set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/nrf51.cmake") elseif (MCU_CHIP MATCHES D2000) set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/intel-quark-d2000.toolchain.cmake") else () message(FATAL_ERROR "Unsupported MCU_CHIP setting: ${MCU_CHIP}") endif () + +include(${CMAKE_CURRENT_LIST_DIR}/mcu_include_directories_from_sources.cmake) diff --git a/mcu_include_directories_from_sources.cmake b/mcu_include_directories_from_sources.cmake new file mode 100644 index 0000000..792b239 --- /dev/null +++ b/mcu_include_directories_from_sources.cmake @@ -0,0 +1,47 @@ +function(mcu_include_directories_from_sources) + set(options) + set(oneValueArgs SOURCES_VAR HEADERS_VAR INCLUDES_VAR) + set(multiValueArgs SOURCE_DIR EXCLUDE) + cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + set(ALL_SOURCES) + set(ALL_HEADERS) + set(ALL_INCLUDES) + + foreach (DIR IN LISTS ARGS_SOURCE_DIR) + file(GLOB_RECURSE SOURCES ${DIR}/*.c) + + foreach (E IN LISTS ARGS_EXCLUDE) + list(FILTER SOURCES EXCLUDE REGEX ${E}) + endforeach () + list(APPEND ALL_SOURCES ${SOURCES}) + + file(GLOB_RECURSE HEADERS LIST_DIRECTORIES TRUE ${DIR}/*.h) + list(APPEND ALL_HEADERS ${HEADERS}) + + # Add all directories that contain header files as private include directories + foreach (H IN LISTS HEADERS) + get_filename_component(D ${H} DIRECTORY) + list(APPEND INCLUDES ${D}) + endforeach () + list(APPEND ALL_INCLUDES ${INCLUDES}) + endforeach () + + if (ARGS_SOURCES_VAR AND ALL_SOURCES) + list(SORT ALL_SOURCES) + list(REMOVE_DUPLICATES ALL_SOURCES) + set(${ARGS_SOURCES_VAR} ${ALL_SOURCES} PARENT_SCOPE) + endif () + + if (ARGS_HEADERS_VAR AND ALL_HEADERS) + list(SORT ALL_HEADERS) + list(REMOVE_DUPLICATES ALL_HEADERS) + set(${ARGS_HEADERS_VAR} ${ALL_HEADERS} PARENT_SCOPE) + endif () + + if (ARGS_INCLUDES_VAR AND ALL_INCLUDES) + list(SORT ALL_INCLUDES) + list(REMOVE_DUPLICATES ALL_INCLUDES) + set(${ARGS_INCLUDES_VAR} ${ALL_INCLUDES} PARENT_SCOPE) + endif () +endfunction() diff --git a/nrf51.cmake b/nrf51.cmake index 6746527..4145f91 100644 --- a/nrf51.cmake +++ b/nrf51.cmake @@ -23,5 +23,3 @@ find_program(ARM_SIZE_TOOL arm-none-eabi-size ${TOOLCHAIN_DIR}/bin) set(CMAKE_C_COMPILER ${ARM_CC}) set(CMAKE_CXX_COMPILER ${ARM_CXX}) set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) - -add_compile_options("-mcpu=cortex-m0" "-mthumb" "-mabi=aapcs" "--std=gnu99" "-Wall" "-mfloat-abi=soft") diff --git a/nrf51/utils.cmake b/nrf51/utils.cmake index df9cc35..b934dd8 100644 --- a/nrf51/utils.cmake +++ b/nrf51/utils.cmake @@ -1,4 +1,15 @@ +function(mcu_nrf5_startup_files VAR) + if ("${MCU_NRF51_SDK_VERSION}" VERSION_LESS 12) + set(startup "${MCU_NRF51_SDK_PATH}/components/toolchain/gcc/gcc_startup_nrf51.s") + else () + set(startup "${MCU_NRF51_SDK_PATH}/components/toolchain/gcc/gcc_startup_nrf51.S") + endif () + + set(${VAR} ${startup} PARENT_SCOPE) +endfunction() + function(mcu_add_executable) + message("mcu_add_executable: ARGN=${ARGN}") set(options) set(oneValueArgs TARGET SDK_CONFIG SOFTDEVICE) set(multiValueArgs) @@ -17,114 +28,148 @@ function(mcu_add_executable) target_sources(${ARGS_TARGET} PUBLIC "${MCU_NRF51_SDK_PATH}/components/toolchain/gcc/gcc_startup_nrf51.S") endif () - # target_compile_options(${ARGS_TARGET} PUBLIC "-mcpu=cortex-m0" "-mthumb" "-mabi=aapcs" "--std=gnu99" "-Wall" "-mfloat-abi=soft") + target_compile_options(${ARGS_TARGET} PUBLIC -Wall -Werror -g3 -O3) + + # -Wall -Werror -O3 -g3 + if (${MCU_CHIP} MATCHES "nrf51.*") + target_compile_options(${ARGS_TARGET} PUBLIC + "-mcpu=cortex-m0" + "-mthumb" + "-mabi=aapcs" + "-mfloat-abi=soft") + elseif (${MCU_CHIP} MATCHES "nrf52.*") + target_compile_options(${ARGS_TARGET} PUBLIC + "-mcpu=cortex-m4" + "-mthumb" + "-mabi=aapcs" + "-mfloat-abi=hard" + "-mfpu=fpv4-sp-d16" + "-ffunction-sections" + "-fdata-sections" + "-fno-strict-aliasing" + "-fno-builtin" + "--short-enums") + # -fshort-wchar + target_compile_features(${ARGS_TARGET} PUBLIC c_static_assert) + target_link_libraries(${ARGS_TARGET} PRIVATE + "-mcpu=cortex-m4" + "-mthumb" + "-mabi=aapcs" + "-mfloat-abi=hard" + "-mfpu=fpv4-sp-d16" + "-Wl,--gc-sections" + # "--specs=nano.specs" + ) + # target_link_libraries(${ARGS_TARGET} PUBLIC c nosys) + endif () if (ARGS_SDK_CONFIG) get_filename_component(SDK_CONFIG ${ARGS_SDK_CONFIG} ABSOLUTE) get_filename_component(SDK_CONFIG ${SDK_CONFIG} DIRECTORY) - set_target_properties(${ARGS_TARGET} PROPERTIES SDK_CONFIG "${SDK_CONFIG}") message("set_target_properties(${ARGS_TARGET} PROPERTIES SDK_CONFIG ${SDK_CONFIG})") endif () - target_link_libraries(${ARGS_TARGET} PUBLIC "-L${MCU_NRF51_SDK_PATH}/components/toolchain/gcc") - target_link_libraries(${ARGS_TARGET} PUBLIC "-T${MCU_NRF51_SDK_PATH}/components/toolchain/gcc/nrf51_xxac.ld") + set_target_properties(${ARGS_TARGET} PROPERTIES SDK_CONFIG "${SDK_CONFIG}") if (ARGS_SOFTDEVICE) set_target_properties(${ARGS_TARGET} PROPERTIES MCU_SOFTDEVICE "${ARGS_SOFTDEVICE}") - _nrf51_create_softdevice(${ARGS_TARGET} ${ARGS_SOFTDEVICE}) - target_link_libraries(${ARGS_TARGET} PUBLIC ${ARGS_TARGET}-softdevice) - else () - target_include_directories(${ARGS_TARGET} PUBLIC ${MCU_NRF51_SDK_PATH}/components/drivers_nrf/nrf_soc_nosd) endif () - _nrf5_set_from_main_target(${ARGS_TARGET} ${ARGS_TARGET}) + _nrf5_set_from_main_target(${ARGS_TARGET}) endfunction() -function(_nrf_softdevice_includes VAR SOFTDEVICE) - list(APPEND list ${MCU_NRF51_SDK_PATH}/components/softdevice/s${SOFTDEVICE}/headers) - - if (MCU_NRF51_SDK_VERSION VERSION_GREATER 7) - if (${MCU_CHIP} MATCHES "nrf51.*") - list(APPEND list ${MCU_NRF51_SDK_PATH}/components/softdevice/s${SOFTDEVICE}/headers/nrf51) - elseif (${MCU_CHIP} MATCHES "nrf52.*") - list(APPEND list ${MCU_NRF51_SDK_PATH}/components/softdevice/s${SOFTDEVICE}/headers/nrf52) - endif () - endif () - - set(${VAR} ${list} PARENT_SCOPE) -endfunction() +function(_nrf5_set_from_main_target T) + message("_nrf5_set_from_main_target, T=${T}") + _nrf_chip_values(CHIP_INCLUDES CHIP_DEFINES) + target_include_directories(${T} PUBLIC ${CHIP_INCLUDES}) + target_compile_definitions(${T} PUBLIC ${CHIP_DEFINES}) -function(_nrf51_create_softdevice TARGET SOFTDEVICE) - get_target_property(SDK_CONFIG ${TARGET} SDK_CONFIG) + target_include_directories(${T} PUBLIC + ${MCU_NRF51_SDK_PATH}/components/device + ${MCU_NRF51_SDK_PATH}/components/toolchain + ${MCU_NRF51_SDK_PATH}/components/toolchain/gcc + ${MCU_NRF51_SDK_PATH}/components/toolchain/cmsis/include + ) - set(T ${TARGET}-softdevice) + get_target_property(SDK_CONFIG ${T} SDK_CONFIG) + if (SDK_CONFIG) + # message("_nrf5_set_from_main_target: SDK_CONFIG=${SDK_CONFIG}") + target_include_directories(${T} PRIVATE ${SDK_CONFIG}) + endif () - if (SOFTDEVICE STREQUAL 130) - _nrf51_add_library(${TARGET} ${T} SOURCE_DIR ${MCU_NRF51_SDK_PATH}/components/softdevice/common) + get_target_property(MCU_SOFTDEVICE ${T} MCU_SOFTDEVICE) + _nrf_softdevice_includes(${MCU_SOFTDEVICE} SOFTDEVICE_INCLUDES SOFTDEVICE_DEFINES) + target_include_directories(${T} PUBLIC ${SOFTDEVICE_INCLUDES}) + target_compile_definitions(${T} PUBLIC ${SOFTDEVICE_DEFINES}) - target_include_directories(${T} PUBLIC - ${MCU_NRF51_SDK_PATH}/components/device - ${MCU_NRF51_SDK_PATH}/components/softdevice/common - ${SDK_CONFIG}) + list(APPEND link_libraries -L${MCU_NRF51_SDK_PATH}/components/toolchain/gcc) - _nrf_softdevice_includes(SOFTDEVICE_INCLUDES ${SOFTDEVICE}) - target_include_directories(${T} PRIVATE ${SOFTDEVICE_INCLUDES}) + if (SOFTDEVICE) + set(ld ${MCU_NRF51_SDK_PATH}/components/softdevice/s${SOFTDEVICE}/toolchain/armgcc/armgcc_s${SOFTDEVICE}_${MCU_CHIP}.ld) - # These should be libraries, not just includes added here - target_include_directories(${T} PUBLIC - ${MCU_NRF51_SDK_PATH}/components/libraries/util - ${MCU_NRF51_SDK_PATH}/components/drivers_nrf/clock) + if (NOT EXISTS ${ld}) + message(FATAL_ERROR "No linker script defined for combination: softdevice=${SOFTDEVICE} and chip=${MCU_CHIP}: expected location: ${ld}") + return() + endif () - _nrf5_set_from_main_target(${TARGET} ${T}) - _nrf5_gen_lib(${TARGET} ble ADD_TO ${T}) - _nrf5_gen_lib(${TARGET} drv_common ADD_TO ${T}) - _nrf5_gen_lib(${TARGET} hal ADD_TO ${T}) - _nrf5_gen_lib(${TARGET} log ADD_TO ${T}) - _nrf5_gen_lib(${TARGET} util ADD_TO ${T}) - _nrf5_gen_lib(${TARGET} scheduler ADD_TO ${T}) + list(APPEND link_libraries -T${ld}) else () - message(FATAL_ERROR "MCU: Unsupported softdevice: ${SOFTDEVICE}") - return() + if (${MCU_CHIP} MATCHES "nrf51.*_xxaa") + list(APPEND link_libraries -T${MCU_NRF51_SDK_PATH}/components/toolchain/gcc/nrf51_xxaa.ld) + elseif (${MCU_CHIP} MATCHES "nrf52.*_xxaa") + list(APPEND link_libraries -T${MCU_NRF51_SDK_PATH}/components/toolchain/gcc/nrf52_xxaa.ld) + else () + message(FATAL_ERROR "MCU: Unsupported nRF MCU chip: ${MCU_CHIP}") + endif () endif () - target_compile_definitions(${TARGET} PUBLIC S${SOFTDEVICE}) - target_compile_definitions(${TARGET} PUBLIC SOFTDEVICE_PRESENT) + target_link_libraries(${T} PUBLIC ${link_libraries}) endfunction() -function(_nrf5_set_from_main_target MAIN_TARGET T) - # message("_nrf5_set_from_main_target: MAIN_TARGET=${MAIN_TARGET} T=${T}") - +function(_nrf_chip_values INCLUDES_VAR DEFINES_VAR) if (${MCU_CHIP} MATCHES "nrf51.*") - target_compile_definitions(${T} PUBLIC NRF51) + list(APPEND defines NRF51) if (${MCU_CHIP} MATCHES "nrf51822") - target_compile_definitions(${T} PUBLIC NRF51822) + list(APPEND defines NRF51822) else () message(FATAL_ERROR "MCU: Unsupported nRF MCU chip: ${MCU_CHIP}") endif () elseif (${MCU_CHIP} MATCHES "nrf52.*") - target_compile_definitions(${T} PUBLIC NRF52) + list(APPEND defines NRF52) + + if (${MCU_CHIP} MATCHES "nrf52832_.*") + list(APPEND defines NRF52832) + else () + message(FATAL_ERROR "MCU: Unsupported nRF MCU chip: ${MCU_CHIP}") + endif () else () message(FATAL_ERROR "MCU: Unsupported MCU chip: ${MCU_CHIP}") endif () - target_include_directories(${T} PUBLIC - ${MCU_NRF51_SDK_PATH}/components/device - ${MCU_NRF51_SDK_PATH}/components/toolchain - ${MCU_NRF51_SDK_PATH}/components/toolchain/gcc - ${MCU_NRF51_SDK_PATH}/components/toolchain/cmsis/include - ) + set(${INCLUDES_VAR} ${includes} PARENT_SCOPE) + set(${DEFINES_VAR} ${defines} PARENT_SCOPE) +endfunction() - get_target_property(SDK_CONFIG ${MAIN_TARGET} SDK_CONFIG) - if (SDK_CONFIG) - # message("_nrf5_set_from_main_target: SDK_CONFIG=${SDK_CONFIG}") - target_include_directories(${T} PRIVATE ${SDK_CONFIG}) - endif () +function(_nrf_softdevice_includes SOFTDEVICE INCLUDES_VAR DEFINES_VAR) + message("_nrf_softdevice_includes: SOFTDEVICE=${SOFTDEVICE}") + if (SOFTDEVICE) + list(APPEND includes ${MCU_NRF51_SDK_PATH}/components/softdevice/s${SOFTDEVICE}/headers) + + if (EXISTS ${MCU_NRF51_SDK_PATH}/components/softdevice/s${SOFTDEVICE}/headers/nrf51) + list(APPEND includes ${MCU_NRF51_SDK_PATH}/components/softdevice/s${SOFTDEVICE}/headers/nrf51) + endif () - get_target_property(MCU_SOFTDEVICE ${MAIN_TARGET} MCU_SOFTDEVICE) - if (MCU_SOFTDEVICE) - _nrf_softdevice_includes(SOFTDEVICE_INCLUDES ${MCU_SOFTDEVICE}) - target_include_directories(${T} PRIVATE ${SOFTDEVICE_INCLUDES}) + if (EXISTS ${MCU_NRF51_SDK_PATH}/components/softdevice/s${SOFTDEVICE}/headers/nrf52) + list(APPEND includes ${MCU_NRF51_SDK_PATH}/components/softdevice/s${SOFTDEVICE}/headers/nrf52) + endif () + + list(APPEND defines S${SOFTDEVICE} SOFTDEVICE_PRESENT) + else () + list(APPEND includes ${MCU_NRF51_SDK_PATH}/components/drivers_nrf/nrf_soc_nosd) endif () + + set(${INCLUDES_VAR} ${includes} PARENT_SCOPE) + set(${DEFINES_VAR} ${defines} PARENT_SCOPE) endfunction() # Toolchain files are executed many times when detecting c/c++ compilers, but it will only read the cache on the first @@ -176,6 +221,7 @@ function(mcu_nrf51_detect_sdk) set(MCU_NRF51_SDK_PATH "${MCU_NRF51_SDK_PATH}" CACHE PATH "MCU: nRF51 SDK path" FORCE) endfunction() +#[[ function(_nrf51_add_library MAIN_TARGET T) # message("_nrf51_add_library(${MAIN_TARGET} ${T} ARGN=${ARGN})") @@ -214,8 +260,10 @@ function(_nrf51_add_library MAIN_TARGET T) _nrf5_set_from_main_target(${MAIN_TARGET} ${T}) endfunction() +]] # TODO: this is really a public function, move arguments to parsed arguments +#[[ function(_nrf5_gen_lib TARGET LIB) set(options) set(oneValueArgs ADD_TO) @@ -347,3 +395,4 @@ function(_nrf5_gen_lib TARGET LIB) set(_MCU_NRF51_LIB_CREATED_${T} TRUE CACHE BOOL "" FORCE) endfunction() +]] |