Clone of official tools
export/cmake/CMakeLists.txt.tmpl@47:21ae3e5a7128, 2021-02-04 (annotated)
- Committer:
- Anders Blomdell
- Date:
- Thu Feb 04 17:17:13 2021 +0100
- Revision:
- 47:21ae3e5a7128
- Parent:
- 43:2a7da56ebd24
Add a few normpath calls
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
theotherjimmy |
43:2a7da56ebd24 | 1 | # This file was automagically generated by mbed.org. |
theotherjimmy |
43:2a7da56ebd24 | 2 | # If you would like to add your own targets, create a |
theotherjimmy |
43:2a7da56ebd24 | 3 | # project.cmake file locally in your project directory. |
theotherjimmy |
43:2a7da56ebd24 | 4 | |
theotherjimmy |
43:2a7da56ebd24 | 5 | CMAKE_MINIMUM_REQUIRED(VERSION 3.9) |
theotherjimmy |
43:2a7da56ebd24 | 6 | SET(CMAKE_SYSTEM_NAME Generic) |
theotherjimmy |
43:2a7da56ebd24 | 7 | #SET(CMAKE_SYSTEM_PROCESSOR arm) |
theotherjimmy |
43:2a7da56ebd24 | 8 | SET(CMAKE_CROSSCOMPILING TRUE) |
theotherjimmy |
43:2a7da56ebd24 | 9 | |
theotherjimmy |
43:2a7da56ebd24 | 10 | # force compiler settings |
theotherjimmy |
43:2a7da56ebd24 | 11 | SET(CMAKE_C_COMPILER_WORKS TRUE) |
theotherjimmy |
43:2a7da56ebd24 | 12 | SET(CMAKE_CXX_COMPILER_WORKS TRUE) |
theotherjimmy |
43:2a7da56ebd24 | 13 | |
theotherjimmy |
43:2a7da56ebd24 | 14 | # force cmake compilers |
theotherjimmy |
43:2a7da56ebd24 | 15 | SET(CMAKE_ASM_COMPILER "{{asm}}") |
theotherjimmy |
43:2a7da56ebd24 | 16 | SET(CMAKE_C_COMPILER "{{cc}}") |
theotherjimmy |
43:2a7da56ebd24 | 17 | SET(CMAKE_CXX_COMPILER "{{cxx}}") |
theotherjimmy |
43:2a7da56ebd24 | 18 | SET(ELF2BIN "{{elf2bin}}") |
theotherjimmy |
43:2a7da56ebd24 | 19 | {% if hex_files %} |
theotherjimmy |
43:2a7da56ebd24 | 20 | SET(SREC_CAT "srec_cat") |
theotherjimmy |
43:2a7da56ebd24 | 21 | {%- endif %} |
theotherjimmy |
43:2a7da56ebd24 | 22 | |
theotherjimmy |
43:2a7da56ebd24 | 23 | # if the environment does not specify build type, set to Debug |
theotherjimmy |
43:2a7da56ebd24 | 24 | IF(NOT CMAKE_BUILD_TYPE) |
theotherjimmy |
43:2a7da56ebd24 | 25 | set(CMAKE_BUILD_TYPE "Debug" |
theotherjimmy |
43:2a7da56ebd24 | 26 | CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." |
theotherjimmy |
43:2a7da56ebd24 | 27 | FORCE) |
theotherjimmy |
43:2a7da56ebd24 | 28 | ENDIF() |
theotherjimmy |
43:2a7da56ebd24 | 29 | |
theotherjimmy |
43:2a7da56ebd24 | 30 | # here starts the project |
theotherjimmy |
43:2a7da56ebd24 | 31 | PROJECT({{name}} C CXX ASM) |
theotherjimmy |
43:2a7da56ebd24 | 32 | |
theotherjimmy |
43:2a7da56ebd24 | 33 | # uncomment below to have a verbose build process |
theotherjimmy |
43:2a7da56ebd24 | 34 | #SET(CMAKE_VERBOSE_MAKEFILE ON) |
theotherjimmy |
43:2a7da56ebd24 | 35 | |
theotherjimmy |
43:2a7da56ebd24 | 36 | SET(LD_SYS_LIBS "{%- block sys_libs -%} -Wl,--start-group {{ld_sys_libs|join(" ")}} {{libraries|join(" ")}} -Wl,--end-group {%- endblock -%}") |
theotherjimmy |
43:2a7da56ebd24 | 37 | |
theotherjimmy |
43:2a7da56ebd24 | 38 | SET(CMAKE_C_FLAGS "{{cc_flags}} -include mbed_config.h") |
theotherjimmy |
43:2a7da56ebd24 | 39 | SET(CMAKE_CXX_FLAGS "{{cxx_flags}} -include mbed_config.h") |
theotherjimmy |
43:2a7da56ebd24 | 40 | SET(CMAKE_ASM_FLAGS "{{asm_flags}} -include mbed_config.h") |
theotherjimmy |
43:2a7da56ebd24 | 41 | SET(CMAKE_CXX_LINK_FLAGS "{{ld_flags}} {% for p in library_paths %} {{user_library_flag}}${CMAKE_CURRENT_SOURCE_DIR}/{{p}} {% endfor %}") |
theotherjimmy |
43:2a7da56ebd24 | 42 | {% if pp -%} |
theotherjimmy |
43:2a7da56ebd24 | 43 | SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${LD_SYS_LIBS} {{link_script_option}} ${CMAKE_BINARY_DIR}/{{name}}_pp.link_script.ld") |
theotherjimmy |
43:2a7da56ebd24 | 44 | {%- endif %} |
theotherjimmy |
43:2a7da56ebd24 | 45 | |
theotherjimmy |
43:2a7da56ebd24 | 46 | ADD_DEFINITIONS( |
theotherjimmy |
43:2a7da56ebd24 | 47 | {% for d in symbols %}-D{{d}} |
theotherjimmy |
43:2a7da56ebd24 | 48 | {% endfor %}) |
theotherjimmy |
43:2a7da56ebd24 | 49 | INCLUDE_DIRECTORIES( |
theotherjimmy |
43:2a7da56ebd24 | 50 | {% for p in include_paths %}{{p}} |
theotherjimmy |
43:2a7da56ebd24 | 51 | {% endfor %}) |
theotherjimmy |
43:2a7da56ebd24 | 52 | |
theotherjimmy |
43:2a7da56ebd24 | 53 | # executable {{name}} |
theotherjimmy |
43:2a7da56ebd24 | 54 | ADD_EXECUTABLE({{name}} |
theotherjimmy |
43:2a7da56ebd24 | 55 | {% for src in sources %}{{src}} |
theotherjimmy |
43:2a7da56ebd24 | 56 | {% endfor %}) |
theotherjimmy |
43:2a7da56ebd24 | 57 | SET_TARGET_PROPERTIES({{name}} PROPERTIES ENABLE_EXPORTS 1) |
theotherjimmy |
43:2a7da56ebd24 | 58 | # add syslibs dependencies to create the correct linker order |
theotherjimmy |
43:2a7da56ebd24 | 59 | TARGET_LINK_LIBRARIES({{name}} {{ld_sys_libs|join(" ")}}) |
theotherjimmy |
43:2a7da56ebd24 | 60 | |
theotherjimmy |
43:2a7da56ebd24 | 61 | {% if pp -%} |
theotherjimmy |
43:2a7da56ebd24 | 62 | add_custom_command(TARGET {{name}} PRE_LINK |
theotherjimmy |
43:2a7da56ebd24 | 63 | COMMAND "{{pp}}" {{pp_flags}} {{linker_script}} -o ${CMAKE_CURRENT_BINARY_DIR}/{{name}}_pp.link_script.ld |
theotherjimmy |
43:2a7da56ebd24 | 64 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
theotherjimmy |
43:2a7da56ebd24 | 65 | BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/{{name}}_pp.link_script.ld" |
theotherjimmy |
43:2a7da56ebd24 | 66 | ) |
theotherjimmy |
43:2a7da56ebd24 | 67 | {%- endif %} |
theotherjimmy |
43:2a7da56ebd24 | 68 | |
theotherjimmy |
43:2a7da56ebd24 | 69 | add_custom_command(TARGET {{name}} POST_BUILD |
theotherjimmy |
43:2a7da56ebd24 | 70 | COMMAND ${ELF2BIN} -O ihex $<TARGET_FILE:{{name}}> $<TARGET_FILE:{{name}}>.hex |
theotherjimmy |
43:2a7da56ebd24 | 71 | COMMAND ${CMAKE_COMMAND} -E echo "-- built: $<TARGET_FILE:{{name}}>.hex" |
theotherjimmy |
43:2a7da56ebd24 | 72 | ) |
theotherjimmy |
43:2a7da56ebd24 | 73 | |
theotherjimmy |
43:2a7da56ebd24 | 74 | {% if hex_files %} |
theotherjimmy |
43:2a7da56ebd24 | 75 | add_custom_command(TARGET {{name}} POST_BUILD |
theotherjimmy |
43:2a7da56ebd24 | 76 | COMMAND ${SREC_CAT} |
theotherjimmy |
43:2a7da56ebd24 | 77 | {% for f in hex_files %}${CMAKE_CURRENT_SOURCE_DIR}/{{f}} {% endfor %} |
theotherjimmy |
43:2a7da56ebd24 | 78 | -intel $<TARGET_FILE:{{name}}>.hex |
theotherjimmy |
43:2a7da56ebd24 | 79 | -intel -o $<TARGET_FILE:{{name}}>-combined.hex -intel --line-length=44 |
theotherjimmy |
43:2a7da56ebd24 | 80 | COMMAND ${CMAKE_COMMAND} -E echo "-- built: $<TARGET_FILE:{{name}}>-combined.hex" |
theotherjimmy |
43:2a7da56ebd24 | 81 | ) |
theotherjimmy |
43:2a7da56ebd24 | 82 | {% endif %} |
theotherjimmy |
43:2a7da56ebd24 | 83 | |
theotherjimmy |
43:2a7da56ebd24 | 84 | |
theotherjimmy |
43:2a7da56ebd24 | 85 | ########################################################################## |
theotherjimmy |
43:2a7da56ebd24 | 86 | # mbed-cli specific targets |
theotherjimmy |
43:2a7da56ebd24 | 87 | ########################################################################## |
theotherjimmy |
43:2a7da56ebd24 | 88 | |
theotherjimmy |
43:2a7da56ebd24 | 89 | # detect the build type and select the corresponding cli profile |
theotherjimmy |
43:2a7da56ebd24 | 90 | SET(MBED_BUILD_PROFILE "") |
theotherjimmy |
43:2a7da56ebd24 | 91 | STRING(TOLOWER ${CMAKE_BUILD_TYPE} LOWERCASE_CMAKE_BUILD_TYPE) |
theotherjimmy |
43:2a7da56ebd24 | 92 | IF(LOWERCASE_CMAKE_BUILD_TYPE MATCHES debug) |
theotherjimmy |
43:2a7da56ebd24 | 93 | SET(MBED_BUILD_PROFILE "mbed-os/tools/profiles/debug.json") |
theotherjimmy |
43:2a7da56ebd24 | 94 | ELSEIF(LOWERCASE_CMAKE_BUILD_TYPE MATCHES relwithdebinfo) |
theotherjimmy |
43:2a7da56ebd24 | 95 | SET(MBED_BUILD_PROFILE "mbed-os/tools/profiles/develop.json") |
theotherjimmy |
43:2a7da56ebd24 | 96 | ELSEIF(LOWERCASE_CMAKE_BUILD_TYPE MATCHES release) |
theotherjimmy |
43:2a7da56ebd24 | 97 | SET(MBED_BUILD_PROFILE "mbed-os/tools/profiles/release.json") |
theotherjimmy |
43:2a7da56ebd24 | 98 | ELSEIF(LOWERCASE_CMAKE_BUILD_TYPE MATCHES minsizerel) |
theotherjimmy |
43:2a7da56ebd24 | 99 | SET(MBED_BUILD_PROFILE "mbed-os/tools/profiles/release.json") |
theotherjimmy |
43:2a7da56ebd24 | 100 | ELSE() |
theotherjimmy |
43:2a7da56ebd24 | 101 | MESSAGE(WARNING "Build type '${CMAKE_BUILD_TYPE}' is unknown, using debug profile") |
theotherjimmy |
43:2a7da56ebd24 | 102 | SET(MBED_BUILD_PROFILE "mbed-os/tools/profiles/debug.json") |
theotherjimmy |
43:2a7da56ebd24 | 103 | ENDIF() |
theotherjimmy |
43:2a7da56ebd24 | 104 | |
theotherjimmy |
43:2a7da56ebd24 | 105 | # optional custom target to build via mbed-cli |
theotherjimmy |
43:2a7da56ebd24 | 106 | ADD_CUSTOM_TARGET(mbed-cli-build |
theotherjimmy |
43:2a7da56ebd24 | 107 | COMMAND ${CMAKE_COMMAND} -E echo "mbed compile --build BUILD/${CMAKE_BUILD_TYPE} --profile ${MBED_BUILD_PROFILE}" |
theotherjimmy |
43:2a7da56ebd24 | 108 | COMMAND mbed compile --build BUILD/${CMAKE_BUILD_TYPE} --profile ${MBED_BUILD_PROFILE} |
theotherjimmy |
43:2a7da56ebd24 | 109 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
theotherjimmy |
43:2a7da56ebd24 | 110 | SOURCES ${SOURCE_FILES} ${SYS_SOURCE_FILES}) |
theotherjimmy |
43:2a7da56ebd24 | 111 | |
theotherjimmy |
43:2a7da56ebd24 | 112 | IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/project.cmake) |
theotherjimmy |
43:2a7da56ebd24 | 113 | INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/project.cmake) |
theotherjimmy |
43:2a7da56ebd24 | 114 | ELSE() |
theotherjimmy |
43:2a7da56ebd24 | 115 | MESSAGE(STATUS "Add a local project.cmake file to add your own targets.") |
theotherjimmy |
43:2a7da56ebd24 | 116 | ENDIF() |
theotherjimmy |
43:2a7da56ebd24 | 117 | |
theotherjimmy |
43:2a7da56ebd24 | 118 | # this will take care of binary directories generated by cmake/clion not to confuse the cli build |
theotherjimmy |
43:2a7da56ebd24 | 119 | FILE(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/.mbedignore" CONTENT "*") |