-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
94 lines (73 loc) · 4.52 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#
# Mbed CE Hello World Project
#
cmake_minimum_required(VERSION 3.19)
cmake_policy(VERSION 3.19...3.22)
#### Initialize Mbed OS build system. ####
######################################################################################################
### Block of including .json5 files. Files of this block must be included before the app.cmake
#[[ Set path of mbed_app.json (necessary at all times) ]]
set(MBED_APP_JSON_PATH mbed_app.json5)
###---------------------------------------------------------------------------------------------------
#[[ This part is dedicated for custom targets only! The settings below activate targets from
custom_targets.json5 and upload method config. If custom targets are not used the lines below should be commented. ]]
#[[ Here set path for custom_targets.json5 (this is our default) ]]
#set(CUSTOM_TARGETS_JSON_PATH custom_targets/custom_targets.json5)
#[[ Here you can set path for custom upload config .cmake (optional example) ]]
#set(CUSTOM_UPLOAD_CFG_PATH ${CMAKE_SOURCE_DIR}/${MBED_TARGET}/${MBED_TARGET}.cmake)
#[[ Note: For custom target you need also an upload method and we have few options how you can do that
- use the variable CUSTOM_UPLOAD_CFG_PATH above to set the location of your config file
- use the default expected path for custom targets upload method config file:
MY_PROJECT/custom_targets/upload_method_cfg
- of course you can set upload method parameters directly via cmake in this file
For more visit https://github.com/mbed-ce/mbed-os/wiki/Upload-Methods ]]
### End of block
######################################################################################################
### Include Mbed toolchain setup file
include(mbed-os/tools/cmake/mbed_toolchain_setup.cmake)
### Set up your project.
# The project name will be made available in the ${PROJECT_NAME} variable.
# If you like, you can specify a version here, which CMake will make available in the ${PROJECT_VERSION} variable.
project(MbedCEHelloWorld
# VERSION 1.0.0
LANGUAGES C CXX ASM)
### Include Mbed project setup file
include(mbed_project_setup)
######################################################################################################
### Block of including project folders
#[[ If using a custom target, the subdirectory containing the custom target must be included before
the mbed-os subdir, otherwise the next line should be commented]]
#add_subdirectory(custom_targets)
###--------------------------------------------------------------------------------------------------
## Add mbed-os subdirectory (necessary everytime)
add_subdirectory(mbed-os)
###--------------------------------------------------------------------------------------------------
## Add another subdirectory, for example subdirectory of a library (if needed)
#add_subdirectory(YourLibrary)
### End of block
######################################################################################################
### add executable (necessary everytime)
# This will compile an elf file named the same as the project with the given source files.
add_executable(${PROJECT_NAME} main.cpp)
######################################################################################################
### Link libraries block
#[[For more about this configuration visit wiki page MbedOS-configuration
https://github.com/mbed-ce/mbed-os/wiki/MbedOS-configuration#configuration-via-cmake-files]]
# Link Mbed OS core library. This is called mbed-os when using the Mbed RTOS, and mbed-baremetal when using
# the bare metal version. This if statement checks to see which is in use and links it.
# Important: The mbed-os and mbed-baremetal libraries are object libraries, so they should ONLY be
# linked to executables, not to other libraries. Libraries should link to `mbed-core-flags` instead.
if("MBED_CONF_TARGET_APPLICATION_PROFILE=bare-metal" IN_LIST MBED_CONFIG_DEFINITIONS)
target_link_libraries(${PROJECT_NAME} mbed-baremetal)
else()
target_link_libraries(${PROJECT_NAME} mbed-os)
endif()
### link user library (if needed)
#target_link_libraries(${PROJECT_NAME} YourLibrary)
# This generates build rules to generate bin/hex files, and to flash the code if you have configured an
# upload method.
mbed_set_post_build(${PROJECT_NAME})
#[[ Note: if you wish to use a custom linker script instead of the default Mbed one for
your target, you can do that with mbed_set_post_build(${PROJECT_NAME} path/to/linker_script.ld) ]]
### End of block
######################################################################################################