aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2016-11-12 20:28:58 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2016-11-12 20:28:58 +0100
commit7bd30b64fb5eaccb9c4a78b0bb4413d5a476089c (patch)
tree7117963893e37acfd472a37591af211990eefccd
parentd6e6c587e9f5c599bae57a9a5532c6f9a108906a (diff)
downloadmcu.cmake-7bd30b64fb5eaccb9c4a78b0bb4413d5a476089c.tar.gz
mcu.cmake-7bd30b64fb5eaccb9c4a78b0bb4413d5a476089c.tar.bz2
mcu.cmake-7bd30b64fb5eaccb9c4a78b0bb4413d5a476089c.tar.xz
mcu.cmake-7bd30b64fb5eaccb9c4a78b0bb4413d5a476089c.zip
o Compatibility with SDK v12.1.0.
o Windows compatibility, the build works but haven't tested programming yet.
-rw-r--r--.gitattributes4
-rw-r--r--mcu.cmake3
-rw-r--r--nrf5x.cmake74
-rw-r--r--nrf5x/utils.cmake8
-rw-r--r--versions-tests.cmake28
5 files changed, 98 insertions, 19 deletions
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..abebe48
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,4 @@
+* text=auto
+
+*.png binary
+*.jpg binary
diff --git a/mcu.cmake b/mcu.cmake
index df06a26..00795ab 100644
--- a/mcu.cmake
+++ b/mcu.cmake
@@ -12,3 +12,6 @@ else ()
endif ()
include(${CMAKE_CURRENT_LIST_DIR}/mcu_include_directories_from_sources.cmake)
+
+# Required on Windows
+set(CMAKE_SYSTEM_NAME Generic)
diff --git a/nrf5x.cmake b/nrf5x.cmake
index 38333af..ee3a814 100644
--- a/nrf5x.cmake
+++ b/nrf5x.cmake
@@ -1,19 +1,43 @@
+#message("MCU: nrf5x.cmake: MCU_NRF5X_SDK=${MCU_NRF5X_SDK}, MCU_TOOLCHAIN_DIR=${MCU_TOOLCHAIN_DIR}")
+#message("MCU: nrf5x.cmake: env MCU_NRF5X_SDK=$ENV{_MCU_NRF5X_SDK_PATH}, MCU_TOOLCHAIN_DIR=$ENV{_MCU_TOOLCHAIN_DIR}")
+
+function (_mcu_find_toolchain)
+# message("MCU: _mcu_find_toolchain: MCU_TOOLCHAIN_DIR=${MCU_TOOLCHAIN_DIR}, env=$ENV{_MCU_TOOLCHAIN_DIR}")
+
+ if ("$ENV{_MCU_TOOLCHAIN_DIR}" STREQUAL "")
+# message("MCU: pushing MCU_TOOLCHAIN_DIR=${MCU_TOOLCHAIN_DIR} to env")
+ set(ENV{_MCU_TOOLCHAIN_DIR} "${MCU_TOOLCHAIN_DIR}")
+ endif ()
+
+ if (MCU_TOOLCHAIN_DIR)
+# message("MCU: using existing MCU_TOOLCHAIN_DIR: ${MCU_TOOLCHAIN_DIR}")
+ return()
+ endif ()
+
+ set(MCU_TOOLCHAIN_DIR "$ENV{_MCU_TOOLCHAIN_DIR}" PARENT_SCOPE)
+
+ if (MCU_TOOLCHAIN_DIR)
+# message("MCU: Using MCU_TOOLCHAIN_DIR from ENV: ${MCU_TOOLCHAIN_DIR}")
+ return()
+ endif ()
+endfunction()
+
# Toolchain files are executed many times when detecting c/c++ compilers, but it will only read the cache on the first
# exeuction so the paths has to be saved to the environment as it is shared between executions.
function(mcu_nrf5_detect_sdk)
if (MCU_NRF5X_SDK_PATH)
- # message("MCU: NRF5x SDK already found: ${MCU_NRF5X_SDK_PATH}")
+# message("MCU: NRF5x SDK already found: ${MCU_NRF5X_SDK_PATH}")
return()
endif ()
set(MCU_NRF5X_SDK_PATH "$ENV{_MCU_NRF5X_SDK_PATH}")
if (MCU_NRF5X_SDK_PATH)
- # message("MCU: NRF5x SDK already found from ENV: ${MCU_NRF5X_SDK_PATH}")
+# message("MCU: NRF5x SDK already found from ENV: ${MCU_NRF5X_SDK_PATH}")
return()
endif ()
- message("MCU: Detecting NRF5x SDK")
+ message("MCU: Detecting NRF5x SDK in: " ${MCU_NRF5X_SDK})
if (NOT MCU_NRF5X_SDK)
set(MCU_NRF5X_SDK "" CACHE PATH "" FORCE)
@@ -43,27 +67,47 @@ function(mcu_nrf5_detect_sdk)
message("MCU: nRF5x SDK Path: ${MCU_NRF5X_SDK_PATH} (Version: ${MCU_NRF5X_SDK_VERSION})")
+ string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$" junk ${MCU_NRF5X_SDK_VERSION})
+ set(MCU_NRF5X_SDK_VERSION_MAJOR ${CMAKE_MATCH_1})
+ set(MCU_NRF5X_SDK_VERSION_MINOR ${CMAKE_MATCH_2})
+ set(MCU_NRF5X_SDK_VERSION_PATCH ${CMAKE_MATCH_3})
+ message("MCU: major=${MCU_NRF5X_SDK_VERSION_MAJOR} minor=${MCU_NRF5X_SDK_VERSION_MINOR} patch=${MCU_NRF5X_SDK_VERSION_PATCH}")
+
set(MCU_NRF5X_SDK_VERSION "${MCU_NRF5X_SDK_VERSION}" CACHE STRING "MCU: nRF5x SDK version" FORCE)
+ set(MCU_NRF5X_SDK_VERSION_MAJOR "${MCU_NRF5X_SDK_VERSION_MAJOR}" CACHE STRING "MCU: nRF5x SDK version, major" FORCE)
+ set(MCU_NRF5X_SDK_VERSION_MINOR "${MCU_NRF5X_SDK_VERSION_MINOR}" CACHE STRING "MCU: nRF5x SDK version, minor" FORCE)
+ set(MCU_NRF5X_SDK_VERSION_PATCH "${MCU_NRF5X_SDK_VERSION_PATCH}" CACHE STRING "MCU: nRF5x SDK version, patch" FORCE)
set(MCU_NRF5X_SDK_PATH "${MCU_NRF5X_SDK_PATH}" CACHE PATH "MCU: nRF5x SDK path" FORCE)
endfunction()
-set(MCU_NRF5X_LOADED TRUE CACHE BOOL INTERNAL)
+#if(MCU_NRF5X_LOADED)
+# message("MCU: nrf5x already loaded")
+# return()
+#endif()
+#
+#set(MCU_NRF5X_LOADED TRUE CACHE BOOL INTERNAL)
mcu_nrf5_detect_sdk()
-find_program(ARM_CC arm-none-eabi-gcc ${TOOLCHAIN_DIR}/bin)
-find_program(ARM_CXX arm-none-eabi-g++ ${TOOLCHAIN_DIR}/bin)
-find_program(ARM_OBJCOPY arm-none-eabi-objcopy ${TOOLCHAIN_DIR}/bin)
-find_program(ARM_SIZE_TOOL arm-none-eabi-size ${TOOLCHAIN_DIR}/bin)
-find_program(ARM_NM arm-none-eabi-nm ${TOOLCHAIN_DIR}/bin)
+_mcu_find_toolchain()
+
+find_program(MCU_ARM_CC arm-none-eabi-gcc ${MCU_TOOLCHAIN_DIR}/bin)
+find_program(MCU_ARM_CXX arm-none-eabi-g++ ${MCU_TOOLCHAIN_DIR}/bin)
+find_program(MCU_ARM_OBJCOPY arm-none-eabi-objcopy ${MCU_TOOLCHAIN_DIR}/bin)
+find_program(MCU_ARM_SIZE_TOOL arm-none-eabi-size ${MCU_TOOLCHAIN_DIR}/bin)
+find_program(MCU_ARM_NM arm-none-eabi-nm ${MCU_TOOLCHAIN_DIR}/bin)
set(_CMAKE_TOOLCHAIN_PREFIX arm-none-eabi-)
include(CMakeFindBinUtils)
-#message("ARM_CC=${ARM_CC}")
-#message("ARM_CXX=${ARM_CXX}")
-#message("ARM_OBJCOPY=${ARM_OBJCOPY}")
-#message("ARM_SIZE_TOOL=${ARM_SIZE_TOOL}")
+#message("MCU_ARM_CC = ${MCU_ARM_CC}")
+#message("MCU_ARM_CXX = ${MCU_ARM_CXX}")
+#message("MCU_ARM_OBJCOPY = ${MCU_ARM_OBJCOPY}")
+#message("MCU_ARM_SIZE_TOOL = ${MCU_ARM_SIZE_TOOL}")
+
+if (NOT MCU_ARM_CC OR NOT MCU_ARM_CXX OR NOT MCU_ARM_OBJCOPY OR NOT MCU_ARM_SIZE_TOOL)
+ message(FATAL_ERROR "Could not find required compiler tools.")
+endif()
# Old style, before 3.6
#include(CMakeForceCompiler)
@@ -71,8 +115,8 @@ include(CMakeFindBinUtils)
#CMAKE_FORCE_CXX_COMPILER(${ARM_CXX} GNU)
# New style, 3.6+
-set(CMAKE_C_COMPILER ${ARM_CC} CACHE FILE "")
-set(CMAKE_CXX_COMPILER ${ARM_CXX} CACHE FILE "")
+set(CMAKE_C_COMPILER ${MCU_ARM_CC} CACHE FILE "")
+set(CMAKE_CXX_COMPILER ${MCU_ARM_CXX} CACHE FILE "")
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
# The ARM compilers today support this.
diff --git a/nrf5x/utils.cmake b/nrf5x/utils.cmake
index a583659..efd1f4d 100644
--- a/nrf5x/utils.cmake
+++ b/nrf5x/utils.cmake
@@ -106,9 +106,9 @@ function(mcu_add_executable)
set_target_properties(${ARGS_TARGET} PROPERTIES SDK_CONFIG "${SDK_CONFIG}")
if (ARGS_SOFTDEVICE)
- if ("${MCU_NRF5X_SDK_VERSION}" VERSION_EQUAL 12 AND ARGS_SOFTDEVICE STREQUAL 130)
+ if ("${MCU_NRF5X_SDK_VERSION_MAJOR}" VERSION_EQUAL 12 AND ARGS_SOFTDEVICE STREQUAL 130)
set(hex "${MCU_NRF5X_SDK_PATH}/components/softdevice/s130/hex/s130_nrf51_2.0.1_softdevice.hex")
- elseif ("${MCU_NRF5X_SDK_VERSION}" VERSION_EQUAL 12 AND ARGS_SOFTDEVICE STREQUAL 132)
+ elseif ("${MCU_NRF5X_SDK_VERSION_MAJOR}" STREQUAL 12 AND ARGS_SOFTDEVICE STREQUAL 132)
set(hex "${MCU_NRF5X_SDK_PATH}/components/softdevice/s132/hex/s132_nrf52_3.0.0_softdevice.hex")
else ()
message(WARNING "Unknown combination of SDK version (${MCU_NRF5X_SDK_VERSION}) and softdevice (${ARGS_SOFTDEVICE}). Some features might be unavailable.")
@@ -192,8 +192,8 @@ function(_nrf5_set_from_main_target T)
endif ()
target_link_libraries(${T} PUBLIC
- -L${MCU_NRF5X_SDK_PATH}/components/toolchain/gcc
- -T$<TARGET_PROPERTY:MCU_LINKER_SCRIPT>)
+ "-L\"${MCU_NRF5X_SDK_PATH}/components/toolchain/gcc\""
+ "-T\"$<TARGET_PROPERTY:MCU_LINKER_SCRIPT>\"")
endfunction()
function(_nrf_chip_values INCLUDES_VAR DEFINES_VAR)
diff --git a/versions-tests.cmake b/versions-tests.cmake
new file mode 100644
index 0000000..b7ed86f
--- /dev/null
+++ b/versions-tests.cmake
@@ -0,0 +1,28 @@
+# Execute with cmake -P versions-tests.cmake
+
+macro(do_test L R)
+ set(eq FALSE)
+ set(lt FALSE)
+ set(gt FALSE)
+ if(${L} VERSION_EQUAL ${R})
+ set(eq TRUE)
+ endif()
+ if(${L} VERSION_LESS ${R})
+ set(lt TRUE)
+ endif()
+ if(${L} VERSION_GREATER ${R})
+ set(gt TRUE)
+ endif()
+
+ message("testing L=${L} R=${R}")
+ message(" L = R => " ${eq})
+ message(" L < R => " ${lt})
+ message(" L > R => " ${gt})
+endmacro()
+
+do_test("1" "1")
+do_test("1.0" "1.1")
+do_test("1" "2")
+do_test("1.0" "2.0")
+
+do_test("1" "1.0")