55
66cmake_minimum_required (VERSION 3.19.0 FATAL_ERROR)
77
8- include (${MBED_CONFIG_PATH} /mbed_config.cmake)
9- include (mbed_set_linker_script)
8+ if (${CMAKE_CROSSCOMPILING} )
9+ include (${MBED_CONFIG_PATH} /mbed_config.cmake)
10+ include (mbed_set_linker_script)
11+ endif ()
1012
1113project (mbed-os)
1214
@@ -15,6 +17,13 @@ list(APPEND CMAKE_MODULE_PATH
1517 "${mbed-os_SOURCE_DIR}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts;${mbed-os_SOURCE_DIR}/targets/TARGET_Cypress/scripts;${mbed-os_SOURCE_DIR}/targets/TARGET_NXP/scripts"
1618)
1719
20+ option (BUILD_TESTING "Run unit tests only." OFF )
21+
22+ if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
23+ include (CTest)
24+ add_subdirectory (UNITTESTS)
25+ endif ()
26+
1827add_library (mbed-core INTERFACE )
1928
2029add_library (mbed-os INTERFACE )
@@ -33,88 +42,91 @@ target_link_libraries(mbed-baremetal
3342)
3443# Validate selected C library type
3544# The C library type selected has to match the library that the target can support
36- if (${MBED_C_LIB} STREQUAL "small" )
37- if (NOT "small" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
38- if ("std" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
39- message (WARNING
40- "We noticed that target.c_lib is set to `${MBED_C_LIB} `."
41- " As the ${MBED_TARGET} target does not support a small C library for the ${MBED_TOOLCHAIN} toolchain,"
42- " we are using the standard C library instead."
43- )
44- set (MBED_C_LIB "std" CACHE STRING "" )
45+ if (${CMAKE_CROSSCOMPILING} )
46+ if (${MBED_C_LIB} STREQUAL "small" )
47+ if (NOT "small" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
48+ if ("std" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
49+ message (WARNING
50+ "We noticed that target.c_lib is set to `${MBED_C_LIB} `."
51+ " As the ${MBED_TARGET} target does not support a small C library for the ${MBED_TOOLCHAIN} toolchain,"
52+ " we are using the standard C library instead."
53+ )
54+ set (MBED_C_LIB "std" CACHE STRING "" )
55+ endif ()
4556 endif ()
57+ elseif (NOT ${MBED_C_LIB} IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
58+ message (FATAL_ERROR
59+ "Invalid `target.c_lib` ('${MBED_C_LIB} ') for '${MBED_TARGET} ' target."
60+ "\n Possible value(s): ${MBED_TARGET_SUPPORTED_C_LIBS} "
61+ )
4662 endif ()
47- elseif (NOT ${MBED_C_LIB} IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
48- message (FATAL_ERROR
49- "Invalid `target.c_lib` ('${MBED_C_LIB} ') for '${MBED_TARGET} ' target."
50- "\n Possible value(s): ${MBED_TARGET_SUPPORTED_C_LIBS} "
51- )
52- endif ()
5363
54- # Validate selected printf library
55- set (MBED_PRINTF_LIB_TYPES std minimal-printf)
56- if (NOT ${MBED_PRINTF_LIB} IN_LIST MBED_PRINTF_LIB_TYPES)
57- message (FATAL_ERROR
58- "Invalid printf library type '${MBED_PRINTF_LIB} '. Possible values:\n ${MBED_PRINTF_LIB_TYPES} "
59- )
60- endif ()
61-
62- mbed_set_cpu_core_definitions(mbed-core)
63- if (${MBED_TOOLCHAIN_FILE_USED} )
64- mbed_set_profile_options(mbed-core ${MBED_TOOLCHAIN} )
65- mbed_set_c_lib(mbed-core ${MBED_C_LIB} )
66- mbed_set_printf_lib(mbed-core ${MBED_PRINTF_LIB} )
64+ # Validate selected printf library
65+ set (MBED_PRINTF_LIB_TYPES std minimal-printf)
66+ if (NOT ${MBED_PRINTF_LIB} IN_LIST MBED_PRINTF_LIB_TYPES)
67+ message (FATAL_ERROR
68+ "Invalid printf library type '${MBED_PRINTF_LIB} '. Possible values:\n ${MBED_PRINTF_LIB_TYPES} "
69+ )
70+ endif ()
71+
72+ mbed_set_cpu_core_definitions(mbed-core)
73+ if (${MBED_TOOLCHAIN_FILE_USED} )
74+ message (STATUS ${MBED_TOOLCHAIN} )
75+ mbed_set_profile_options(mbed-core ${MBED_TOOLCHAIN} )
76+ mbed_set_c_lib(mbed-core ${MBED_C_LIB} )
77+ mbed_set_printf_lib(mbed-core ${MBED_PRINTF_LIB} )
78+
79+ target_compile_features (mbed-core
80+ INTERFACE
81+ c_std_11
82+ cxx_std_14
83+ )
84+
85+ endif ()
6786
68- target_compile_features (mbed-core
87+ target_compile_definitions (mbed-core
6988 INTERFACE
70- c_std_11
71- cxx_std_14
89+ ${MBED_TARGET_DEFINITIONS}
90+ ${MBED_CONFIG_DEFINITIONS}
7291 )
7392
74- endif ()
75-
76- target_compile_definitions (mbed-core
77- INTERFACE
78- ${MBED_TARGET_DEFINITIONS}
79- ${MBED_CONFIG_DEFINITIONS}
80- )
81-
82- # Add MBED_TEST_MODE for backward compatibility with Greentea tests written for use with Mbed CLI 1
83- if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
84- target_compile_definitions (${PROJECT_NAME}
85- PUBLIC
86- MBED_TEST_MODE
87- )
88- endif ()
93+ # Add MBED_TEST_MODE for backward compatibility with Greentea tests written for use with Mbed CLI 1
94+ if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
95+ target_compile_definitions (${PROJECT_NAME}
96+ PUBLIC
97+ MBED_TEST_MODE
98+ )
99+ endif ()
89100
90- # We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker
91- # script, because of path length limitations on Windows. We set the response file and bind the path
92- # to a global property here. The MBED_TARGET being built queries this global property when it sets
93- # the linker script.
94- #
95- # We must set this global property before the targets subdirectory is added to the project. This is
96- # required because the MBED_TARGET depends on the response file. If the path to the response file
97- # is not defined when the target requests it the config definitions will not be passed to CPP.
98- #
99- # TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without
100- # using response files or global properties.
101- mbed_generate_options_for_linker(mbed-core RESPONSE_FILE_PATH)
102- set_property (GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${RESPONSE_FILE_PATH} )
103-
104- # Add compile definitions for backward compatibility with the toolchain
105- # supported. New source files should instead check for __GNUC__ and __clang__
106- # for the GCC_ARM and ARM toolchains respectively.
107- if (${MBED_TOOLCHAIN} STREQUAL "GCC_ARM" )
108- target_compile_definitions (mbed-core
109- INTERFACE
110- TOOLCHAIN_GCC_ARM
111- TOOLCHAIN_GCC
112- )
113- elseif (${MBED_TOOLCHAIN} STREQUAL "ARM" )
114- target_compile_definitions (mbed-core
115- INTERFACE
116- TOOLCHAIN_ARM
117- )
101+ # We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker
102+ # script, because of path le ngth limitations on Windows. We set the response file and bind the path
103+ # to a global property here. The MBED_TARGET being built queries this global property when it sets
104+ # the linker script.
105+ #
106+ # We must set this global property before the targets subdirectory is added to the project. This is
107+ # required because the MBED_TARGET depends on the response file. If the path to the response file
108+ # is not defined when the target requests it the config definitions will not be passed to CPP.
109+ #
110+ # TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without
111+ # using response files or global properties.
112+ mbed_generate_options_for_linker(mbed-core RESPONSE_FILE_PATH)
113+ set_property (GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${RESPONSE_FILE_PATH} )
114+
115+ # Add compile definitions for backward compatibility with the toolchain
116+ # supported. New source files should instead check for __GNUC__ and __clang__
117+ # for the GCC_ARM and ARM toolchains respectively.
118+ if (${MBED_TOOLCHAIN} STREQUAL "GCC_ARM" )
119+ target_compile_definitions (mbed-core
120+ INTERFACE
121+ TOOLCHAIN_GCC_ARM
122+ TOOLCHAIN_GCC
123+ )
124+ elseif (${MBED_TOOLCHAIN} STREQUAL "ARM" )
125+ target_compile_definitions (mbed-core
126+ INTERFACE
127+ TOOLCHAIN_ARM
128+ )
129+ endif ()
118130endif ()
119131
120132# Include mbed.h and config from generate folder
@@ -136,23 +148,26 @@ add_subdirectory(hal)
136148add_subdirectory (platform)
137149add_subdirectory (rtos)
138150add_subdirectory (targets)
151+ add_subdirectory (storage)
152+ add_subdirectory (events)
153+ add_subdirectory (connectivity)
139154
140155# The directories below contain optional target libraries
141- add_subdirectory (events EXCLUDE_FROM_ALL )
142- add_subdirectory (connectivity EXCLUDE_FROM_ALL )
143- add_subdirectory (storage EXCLUDE_FROM_ALL )
144156add_subdirectory (drivers/device_key EXCLUDE_FROM_ALL )
145157add_subdirectory (drivers/usb EXCLUDE_FROM_ALL )
146158add_subdirectory (features EXCLUDE_FROM_ALL )
147159add_subdirectory (cmsis/CMSIS_5/CMSIS/RTOS2 EXCLUDE_FROM_ALL )
148160add_subdirectory (cmsis/device/rtos EXCLUDE_FROM_ALL )
149161
150- # Ensure the words that make up the Mbed target name are separated with a hyphen, lowercase, and with the `mbed-` prefix.
151- string (TOLOWER ${MBED_TARGET} MBED_TARGET_CONVERTED)
152- string (REPLACE "_" "-" MBED_TARGET_CONVERTED ${MBED_TARGET_CONVERTED} )
153- string (PREPEND MBED_TARGET_CONVERTED "mbed-" )
154162
155- target_link_libraries (mbed-core INTERFACE ${MBED_TARGET_CONVERTED} )
163+ if (${CMAKE_CROSSCOMPILING} )
164+ # Ensure the words that make up the Mbed target name are separated with a hyphen, lowercase, and with the `mbed-` prefix.
165+ string (TOLOWER ${MBED_TARGET} MBED_TARGET_CONVERTED)
166+ string (REPLACE "_" "-" MBED_TARGET_CONVERTED ${MBED_TARGET_CONVERTED} )
167+ string (PREPEND MBED_TARGET_CONVERTED "mbed-" )
168+
169+ target_link_libraries (mbed-core INTERFACE ${MBED_TARGET_CONVERTED} )
170+ endif ()
156171
157172#
158173# Converts output file of `target` to binary file and to Intel HEX file.
0 commit comments