]> granicus.if.org Git - esp-idf/blob - CMakeLists.txt
Merge branch 'bugfix/wifi_fix_invalid_csi_data_index' into 'master'
[esp-idf] / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.5)
2 project(esp-idf C CXX ASM)
3
4 if(NOT IDF_PATH)
5     set(IDF_PATH ${CMAKE_CURRENT_LIST_DIR})
6 endif()
7
8 include(tools/cmake/idf_functions.cmake)
9
10 #
11 # Set variables that control the build configuration and the build itself
12 #
13 idf_set_variables()
14
15 kconfig_set_variables()
16
17 #
18 # Generate a component dependencies file, enumerating components to be included in the build
19 # as well as their dependencies.
20 #
21 execute_process(COMMAND "${CMAKE_COMMAND}"
22     -D "COMPONENTS=${IDF_COMPONENTS}"
23     -D "COMPONENT_REQUIRES_COMMON=${IDF_COMPONENT_REQUIRES_COMMON}"
24     -D "EXCLUDE_COMPONENTS=${IDF_EXCLUDE_COMPONENTS}"
25     -D "TEST_COMPONENTS=${IDF_TEST_COMPONENTS}"
26     -D "TEST_EXCLUDE_COMPONENTS=${IDF_TEST_EXCLUDE_COMPONENTS}"
27     -D "BUILD_TESTS=${IDF_BUILD_TESTS}"
28     -D "DEPENDENCIES_FILE=${CMAKE_BINARY_DIR}/component_depends.cmake"
29     -D "COMPONENT_DIRS=${IDF_COMPONENT_DIRS}"
30     -D "BOOTLOADER_BUILD=${BOOTLOADER_BUILD}"
31     -D "IDF_TARGET=${IDF_TARGET}"
32     -D "IDF_PATH=${IDF_PATH}"
33     -D "DEBUG=${DEBUG}"
34     -P "${IDF_PATH}/tools/cmake/scripts/expand_requirements.cmake"
35     WORKING_DIRECTORY "${PROJECT_PATH}"
36     RESULT_VARIABLE expand_requirements_result)
37
38 if(expand_requirements_result)
39     message(FATAL_ERROR "Failed to expand component requirements")
40 endif()
41
42 include("${CMAKE_BINARY_DIR}/component_depends.cmake")
43
44 #
45 # We now have the following component-related variables:
46 #
47 # IDF_COMPONENTS is the list of initial components set by the user
48 # (or empty to include all components in the build).
49 # BUILD_COMPONENTS is the list of components to include in the build.
50 # BUILD_COMPONENT_PATHS is the paths to all of these components, obtained from the component dependencies file.
51 #
52 # Print the list of found components and test components
53 #
54 string(REPLACE ";" " " BUILD_COMPONENTS_SPACES "${BUILD_COMPONENTS}")
55 message(STATUS "Component names: ${BUILD_COMPONENTS_SPACES}")
56 unset(BUILD_COMPONENTS_SPACES)
57 message(STATUS "Component paths: ${BUILD_COMPONENT_PATHS}")
58
59 # Print list of test components
60 if(TESTS_ALL EQUAL 1 OR TEST_COMPONENTS)
61     string(REPLACE ";" " " BUILD_TEST_COMPONENTS_SPACES "${BUILD_TEST_COMPONENTS}")
62     message(STATUS "Test component names: ${BUILD_TEST_COMPONENTS_SPACES}")
63     unset(BUILD_TEST_COMPONENTS_SPACES)
64     message(STATUS "Test component paths: ${BUILD_TEST_COMPONENT_PATHS}")
65 endif()
66
67 # Generate project configuration
68 kconfig_process_config()
69
70 # Include sdkconfig.cmake so rest of the build knows the configuration
71 include(${SDKCONFIG_CMAKE})
72
73 # Verify the environment is configured correctly
74 idf_verify_environment()
75
76 # Check git revision (may trigger reruns of cmake)
77 ##  sets IDF_VER to IDF git revision
78 idf_get_git_revision()
79
80 # Check that the targets set in cache, sdkconfig, and in environment all match
81 idf_check_config_target()
82
83 ## get PROJECT_VER
84 if(NOT BOOTLOADER_BUILD)
85     app_get_revision("${CMAKE_SOURCE_DIR}")
86 endif()
87
88 # Add some idf-wide definitions
89 idf_set_global_compile_options()
90
91 # generate compile_commands.json (needs to come after project)
92 set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
93
94 #
95 # Setup variables for linker script generation
96 #
97 ldgen_set_variables()
98
99 # Include any top-level project_include.cmake files from components
100 foreach(component ${BUILD_COMPONENT_PATHS})
101     set(COMPONENT_PATH "${component}")
102     include_if_exists("${component}/project_include.cmake")
103     unset(COMPONENT_PATH)
104 endforeach()
105
106 #
107 # Add each component to the build as a library
108 #
109 foreach(COMPONENT_PATH ${BUILD_COMPONENT_PATHS})
110     get_filename_component(COMPONENT_NAME ${COMPONENT_PATH} NAME)
111
112     list(FIND BUILD_TEST_COMPONENT_PATHS ${COMPONENT_PATH} idx)
113
114     if(NOT idx EQUAL -1)
115         list(GET BUILD_TEST_COMPONENTS ${idx} test_component)
116         set(COMPONENT_NAME ${test_component})
117     endif()
118
119     component_get_target(COMPONENT_TARGET ${COMPONENT_NAME})
120
121     add_subdirectory(${COMPONENT_PATH} ${COMPONENT_NAME})
122 endforeach()
123 unset(COMPONENT_NAME)
124 unset(COMPONENT_PATH)
125
126 # each component should see the include directories of its requirements
127 #
128 # (we can't do this until all components are registered and targets exist in cmake, as we have
129 # a circular requirements graph...)
130 foreach(component ${BUILD_COMPONENTS})
131     component_get_target(component_target ${component})
132     if(TARGET ${component_target})
133         get_component_requirements(${component} deps priv_deps)
134
135         list(APPEND priv_deps ${IDF_COMPONENT_REQUIRES_COMMON})
136
137         foreach(dep ${deps})
138             component_get_target(dep_target ${dep})
139             add_component_dependencies(${component_target} ${dep_target} PUBLIC)
140         endforeach()
141
142         foreach(dep ${priv_deps})
143             component_get_target(dep_target ${dep})
144             add_component_dependencies(${component_target} ${dep_target} PRIVATE)
145         endforeach()
146     endif()
147 endforeach()
148
149 if(IDF_BUILD_ARTIFACTS)
150     # Write project description JSON file
151     make_json_list("${BUILD_COMPONENTS}" build_components_json)
152     make_json_list("${BUILD_COMPONENT_PATHS}" build_component_paths_json)
153     configure_file("${IDF_PATH}/tools/cmake/project_description.json.in"
154         "${IDF_BUILD_ARTIFACTS_DIR}/project_description.json")
155     unset(build_components_json)
156     unset(build_component_paths_json)
157 endif()
158
159 set(BUILD_COMPONENTS ${BUILD_COMPONENTS} PARENT_SCOPE)
160
161 ldgen_add_dependencies()