1 cmake_minimum_required(VERSION 3.5)
2 project(esp-idf C CXX ASM)
5 unset(c_compile_options)
6 unset(cxx_compile_options)
7 unset(compile_definitions)
9 # Add the following build specifications here, since these seem to be dependent
10 # on config values on the root Kconfig.
12 if(CONFIG_COMPILER_OPTIMIZATION_SIZE)
13 list(APPEND compile_options "-Os")
14 list(APPEND compile_options "-freorder-blocks")
15 elseif(CONFIG_COMPILER_OPTIMIZATION_DEFAULT)
16 list(APPEND compile_options "-Og")
17 elseif(CONFIG_COMPILER_OPTIMIZATION_NONE)
18 list(APPEND compile_options "-O0")
19 elseif(CONFIG_COMPILER_OPTIMIZATION_PERF)
20 list(APPEND compile_options "-O2")
24 if(CONFIG_COMPILER_CXX_EXCEPTIONS)
25 list(APPEND cxx_compile_options "-fexceptions")
27 list(APPEND cxx_compile_options "-fno-exceptions")
30 if(CONFIG_COMPILER_CXX_RTTI)
31 list(APPEND cxx_compile_options "-frtti")
33 list(APPEND cxx_compile_options "-fno-rtti")
36 if(CONFIG_COMPILER_DISABLE_GCC8_WARNINGS)
37 list(APPEND compile_options "-Wno-parentheses"
38 "-Wno-sizeof-pointer-memaccess"
41 # doesn't use GCC_NOT_5_2_0 because idf_set_global_variables was not called before
43 list(APPEND compile_options "-Wno-format-overflow"
44 "-Wno-stringop-truncation"
45 "-Wno-misleading-indentation"
46 "-Wno-cast-function-type"
47 "-Wno-implicit-fallthrough"
48 "-Wno-unused-const-variable"
49 "-Wno-switch-unreachable"
50 "-Wno-format-truncation"
51 "-Wno-memset-elt-size"
52 "-Wno-int-in-bool-context")
56 if(CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE)
57 list(APPEND compile_definitions "-DNDEBUG")
60 if(CONFIG_COMPILER_STACK_CHECK_MODE_NORM)
61 list(APPEND compile_options "-fstack-protector")
62 elseif(CONFIG_COMPILER_STACK_CHECK_MODE_STRONG)
63 list(APPEND compile_options "-fstack-protector-strong")
64 elseif(CONFIG_COMPILER_STACK_CHECK_MODE_ALL)
65 list(APPEND compile_options "-fstack-protector-all")
69 idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND)
70 idf_build_set_property(C_COMPILE_OPTIONS "${c_compile_options}" APPEND)
71 idf_build_set_property(CXX_COMPILE_OPTIONS "${cxx_compile_options}" APPEND)
72 idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND)
74 idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS)
76 # Add each component as a subdirectory, processing each component's CMakeLists.txt
77 foreach(component_target ${build_component_targets})
78 __component_get_property(dir ${component_target} COMPONENT_DIR)
79 __component_get_property(_name ${component_target} COMPONENT_NAME)
80 __component_get_property(prefix ${component_target} __PREFIX)
81 __component_get_property(alias ${component_target} COMPONENT_ALIAS)
82 set(COMPONENT_NAME ${_name})
83 set(COMPONENT_DIR ${dir})
84 set(COMPONENT_ALIAS ${alias})
85 set(COMPONENT_PATH ${dir}) # for backward compatibility only, COMPONENT_DIR is preferred
86 idf_build_get_property(build_prefix __PREFIX)
87 set(__idf_component_context 1)
88 if(NOT prefix STREQUAL build_prefix)
89 add_subdirectory(${dir} ${prefix}_${_name})
91 add_subdirectory(${dir} ${_name})
93 set(__idf_component_context 0)