Skip to content

Commit

Permalink
Update CMakeLists.txt
Browse files Browse the repository at this point in the history
Change of top lvl CMake to variant with description
  • Loading branch information
JohnK1987 authored Oct 6, 2024
1 parent 44e508a commit 86bff65
Showing 1 changed file with 69 additions and 11 deletions.
80 changes: 69 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,79 @@
cmake_minimum_required(VERSION 3.19)
cmake_policy(VERSION 3.19)

# Initialize Mbed OS build system.
# Note: This block must be before the project() call.
#### 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 everytime if mbed_app.json5 is in project) ]]
set(MBED_APP_JSON_PATH mbed_app.json5)
# set(CUSTOM_TARGETS_JSON_PATH custom_targets.json) # If you need a custom target, use this line to specify the custom_targets.json

include(mbed-os/tools/cmake/app.cmake) # Load Mbed CE toolchain file and basic build system
###---------------------------------------------------------------------------------------------------
#[[ This part is dedicated for custom targets only! Settings below activate targets from
custom_targets.json5 and upload method config, otherwise functions 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
- use default expected path for custom targets upload methods where you create your own config
MY_PROJECT/custom_targets/upload_method_cfg
- of course you can do it by yourself directly via cmake in this file
For more visit https://github.com/mbed-ce/mbed-os/wiki/Upload-Methods ]]

### End of block
######################################################################################################

### include app.cmake (necessary everytime) ###
include(mbed-os/tools/cmake/app.cmake)

######################################################################################################
### 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
######################################################################################################

### Set up your project name (necessary everytime)
project(mbed-ce-custom-targets)

### add executable (necessary everytime)
add_executable(${CMAKE_PROJECT_NAME} main.cpp)

### Set post build (necessary everytime)
mbed_set_post_build(${CMAKE_PROJECT_NAME})
#[[Or in case of custom linker script which should be placed like this
directory PROJECT_NAME/custom_targets/MBED_TARGET/MBED_TARGET.ld]]
#mbed_set_post_build(${CMAKE_PROJECT_NAME} ${CMAKE_SOURCE_DIR}/custom_targets/${MBED_TARGET}/${MBED_TARGET}.ld)

# If you need any custom upload method configuration for your target, do that here
######################################################################################################
### Link libraries block
#[[For more about this configuraion visit wiki page MbedOS-configuration
https://github.com/mbed-ce/mbed-os/wiki/MbedOS-configuration#configuration-via-cmake-files]]

add_subdirectory(mbed-os) # Load Mbed OS build targets. Must be added before any other subdirectories
#[[link MbedOS and its libraries (necessary everytime)]]
target_link_libraries(${CMAKE_PROJECT_NAME} mbed-os)

project(MbedCEHelloWorld) # TODO: change this to your project name
### link user library (if needed)
#target_link_libraries(${CMAKE_PROJECT_NAME} YourLibrary)

add_executable(HelloWorld main.cpp)
target_link_libraries(HelloWorld mbed-os) # Can also link to mbed-baremetal here
mbed_set_post_build(HelloWorld) # Must call this for each target to set up bin file creation, code upload, etc
### End of block
######################################################################################################

mbed_finalize_build() # Make sure this is the last line of the top-level buildscript
### Build finalize does necessary configuration for debug in most cases (necessary everytime)
mbed_finalize_build()

0 comments on commit 86bff65

Please sign in to comment.