message(FATAL_ERROR "Bootloader subproject expects the SDKCONFIG variable to be passed in by the app build process.")
endif()
-include($ENV{IDF_PATH}/idf.cmake)
+include($ENV{IDF_PATH}/tools/cmake/project.cmake)
add_executable(bootloader.elf
main/bootloader_start.c
set(CMAKE_TOOLCHAIN_FILE $ENV{IDF_PATH}/toolchain.cmake)
project(idf_project ASM C CXX)
-include($ENV{IDF_PATH}/idf.cmake)
+include($ENV{IDF_PATH}/tools/cmake/project.cmake)
add_executable(hello_world.elf
main/hello_world_main.c)
#
# component_paths contains only unique component names. Directories
# earlier in the component_dirs list take precedence.
-function(find_all_components component_dirs filter_names component_paths component_names)
+function(components_find_all component_dirs filter_names component_paths component_names)
# component_dirs entries can be files or lists of files
set(paths "")
set(names "")
set(${component_paths} ${paths} PARENT_SCOPE)
set(${component_names} ${names} PARENT_SCOPE)
-endfunction()
+endfunction(components_find_all)
# Add a component to the build, using the COMPONENT variables defined
target_include_directories(${component} PRIVATE ${include_dir})
endforeach()
-endfunction()
+endfunction(register_component)
function(register_config_only_component)
get_filename_component(component_dir ${CMAKE_CURRENT_LIST_FILE} DIRECTORY)
get_filename_component(component ${component_dir} NAME)
# No-op for now...
-endfunction()
+endfunction(register_config_only_component)
-function(finish_component_registration)
+function(components_finish_registration)
# each component should see the include directories of each other
#
# (we can't do this until all components are registered, because if(TARGET ...) won't work
# set COMPONENT_LIBRARIES in top-level scope
set(COMPONENT_LIBRARIES "${COMPONENT_LIBRARIES}" PARENT_SCOPE)
-endfunction()
+endfunction(components_finish_registration)
# Some IDF-specific functions and functions
+include(crosstool_version_check)
+
+macro(idf_set_global_variables)
+
+ set_default(EXTRA_COMPONENT_DIRS "")
+
+ # PROJECT_PATH has the path to the IDF project (top-level cmake directory)
+ #
+ # (cmake calls this CMAKE_SOURCE_DIR, keeping old name for compatibility.)
+ set(PROJECT_PATH "${CMAKE_SOURCE_DIR}")
+
+ # Note: "main" is no longer a component...
+ #
+ set_default(COMPONENT_DIRS "${PROJECT_PATH}/components ${EXTRA_COMPONENT_DIRS} ${IDF_PATH}/components")
+ spaces2list(COMPONENT_DIRS)
+
+ spaces2list(COMPONENTS)
+
+endmacro()
# Add all the IDF global compiler & preprocessor options
# (applied to all components). Some are config-dependent
# go itno ther final binary
add_compile_options(-ggdb)
-endfunction()
+ add_compile_options("-I${CMAKE_BINARY_DIR}") # for sdkconfig.h
+
+endfunction(idf_set_global_compiler_options)
# Override add_executable to add IDF-specific
# linker flags & map file to all built executables
target_link_libraries(${target} "-Wl,--gc-sections -Wl,--cref -Wl,--Map=${mapfile} -Wl,--start-group")
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/${mapfile}")
-endfunction()
+endfunction(add_executable)
+
+
+# Verify the IDF environment is configured correctly (environment, toolchain, etc)
+function(idf_verify_environment)
+
+ # Check toolchain is configured properly in cmake
+ if(NOT ( ${CMAKE_SYSTEM_NAME} STREQUAL "Generic" AND ${CMAKE_C_COMPILER} MATCHES xtensa))
+ message(FATAL_ERROR "The parent project CMakeLists.txt file needs to set CMAKE_TOOLCHAIN_FILE "
+ "before including this file. "
+ "Update CMakeLists.txt to match the template project and delete CMakeCache.txt before "
+ "re-running cmake.")
+ endif()
+
+ #
+ # Warn if the toolchain version doesn't match
+ #
+ gcc_version_check("5.2.0")
+ crosstool_version_check("1.22.0-80-g6c4433a")
+
+
+
+endfunction(idf_verify_environment)
include(ExternalProject)
-add_compile_options("-I${CMAKE_BINARY_DIR}")
+macro(kconfig_set_variables)
+ set(MCONF ${IDF_PATH}/tools/kconfig/mconf)
-set(MCONF ${IDF_PATH}/tools/kconfig/mconf)
+ set_default(SDKCONFIG ${PROJECT_PATH}/sdkconfig)
+ set(SDKCONFIG_HEADER ${CMAKE_BINARY_DIR}/sdkconfig.h)
+ set(SDKCONFIG_CMAKE ${CMAKE_BINARY_DIR}/sdkconfig.cmake)
-set_default(SDKCONFIG ${PROJECT_PATH}/sdkconfig)
-set(SDKCONFIG_HEADER ${CMAKE_BINARY_DIR}/sdkconfig.h)
-set(SDKCONFIG_CMAKE ${CMAKE_BINARY_DIR}/sdkconfig.cmake)
-
-set(ROOT_KCONFIG ${IDF_PATH}/Kconfig)
+ set(ROOT_KCONFIG ${IDF_PATH}/Kconfig)
+endmacro()
# Use the existing Makefile to build mconf when needed
#
)
# Find all Kconfig files for all components
-function(build_component_config)
+function(kconfig_process_config)
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/config")
set(kconfigs )
set(kconfigs_projbuild )
#
cmake_minimum_required(VERSION 3.5)
-#
-# Verify the project configured the environment correctly
-#
-if(NOT ( ${CMAKE_SYSTEM_NAME} STREQUAL "Generic" AND ${CMAKE_C_COMPILER} MATCHES xtensa))
- message(FATAL_ERROR "The parent project CMakeLists.txt file needs to set CMAKE_TOOLCHAIN_FILE "
- "before including this file. "
- "Update CMakeLists.txt to match the template project and delete CMakeCache.txt before "
- "re-running cmake.")
-endif()
-
+# Set IDF_PATH, as nothing else will work without this
set(IDF_PATH "$ENV{IDF_PATH}")
if(NOT IDF_PATH)
# Documentation says you should set IDF_PATH in your environment, but we
set($ENV{IDF_PATH} "${IDF_PATH}")
endif()
-# PROJECT_PATH has the path to the IDF project (top-level cmake directory)
-#
-# (cmake calls this CMAKE_SOURCE_DIR, keeping old name for compatibility.)
-set(PROJECT_PATH "${CMAKE_SOURCE_DIR}")
-
#
# Load cmake modules
#
include(utilities)
include(components)
include(kconfig)
-include(crosstool_version_check)
include(git_submodules)
include(idf_functions)
-#
-# Warn if the toolchain version doesn't match
-#
-gcc_version_check("5.2.0")
-crosstool_version_check("1.22.0-80-g6c4433a")
-
-#
-# Configure optional variables
-#
-set_default(EXTRA_COMPONENT_DIRS "")
+# Verify the environment is configured correctly
+idf_verify_environment()
-# Note: "main" is no longer a component...
-#
-set_default(COMPONENT_DIRS "${PROJECT_PATH}/components ${EXTRA_COMPONENT_DIRS} ${IDF_PATH}/components")
-spaces2list(COMPONENT_DIRS)
+# Set global variables used by rest of the build
+idf_set_global_variables()
-spaces2list(COMPONENTS)
# Search COMPONENT_DIRS for COMPONENTS, make a list of full paths to each component in COMPONENT_PATHS
-find_all_components("${COMPONENT_DIRS}" "${COMPONENTS}" COMPONENT_PATHS COMPONENTS)
-build_component_config()
+components_find_all("${COMPONENT_DIRS}" "${COMPONENTS}" COMPONENT_PATHS COMPONENTS)
+
+kconfig_set_variables()
+
+kconfig_process_config()
# Include sdkconfig.cmake so rest of the build knows the configuration
include(${SDKCONFIG_CMAKE})
-#
# Add some idf-wide definitions
idf_set_global_compiler_options()
+# Check git version (may trigger reruns of cmake)
+# & set GIT_REVISION/IDF_VER variable
git_describe(GIT_REVISION)
add_definitions(-DIDF_VER=\"${GIT_REVISION}\")
git_submodule_check("${IDF_PATH}")
-add_compile_options("-I${CMAKE_BINARY_DIR}") # for sdkconfig.h
#
# Add components to the build
add_subdirectory(${component} ${component_name})
endforeach()
-finish_component_registration()
+components_finish_registration()
# Load the targets for the bootloader subproject
if(NOT BOOTLOADER_BUILD)
include(bootloader_subproject)
endif()
-