cmake: Refactor main cmake project logic

pull/1946/head
Angus Gratton 2018-01-17 14:01:57 +11:00 zatwierdzone przez Angus Gratton
rodzic 7f29593a7d
commit 134f2238bd
6 zmienionych plików z 74 dodań i 55 usunięć

Wyświetl plik

@ -12,7 +12,7 @@ if(NOT SDKCONFIG)
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

Wyświetl plik

@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.5)
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)

Wyświetl plik

@ -4,7 +4,7 @@
#
# 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 "")
@ -44,7 +44,7 @@ function(find_all_components component_dirs filter_names component_paths compone
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
@ -98,16 +98,16 @@ function(register_component)
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
@ -130,4 +130,4 @@ function(finish_component_registration)
# set COMPONENT_LIBRARIES in top-level scope
set(COMPONENT_LIBRARIES "${COMPONENT_LIBRARIES}" PARENT_SCOPE)
endfunction()
endfunction(components_finish_registration)

Wyświetl plik

@ -1,5 +1,24 @@
# 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
@ -53,7 +72,9 @@ function(idf_set_global_compiler_options)
# 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
@ -66,4 +87,26 @@ function(add_executable target)
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)

Wyświetl plik

@ -1,14 +1,14 @@
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
#
@ -24,7 +24,7 @@ ExternalProject_Add(mconf
)
# 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 )

Wyświetl plik

@ -2,16 +2,7 @@
#
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
@ -20,11 +11,6 @@ if(NOT IDF_PATH)
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
#
@ -33,43 +19,34 @@ include(GetGitRevisionDescription)
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")
# Verify the environment is configured correctly
idf_verify_environment()
#
# Configure optional variables
#
set_default(EXTRA_COMPONENT_DIRS "")
# Set global variables used by rest of the build
idf_set_global_variables()
# 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)
# 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
@ -79,10 +56,9 @@ foreach(component ${COMPONENT_PATHS})
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()