Skip to content

Commit

Permalink
cmake: separate app from idf lib project
Browse files Browse the repository at this point in the history
mbedtls: import mbedtls using unmodified cmake file
  • Loading branch information
renzbagaporo committed Nov 27, 2018
1 parent 81231fc commit 37d30c7
Show file tree
Hide file tree
Showing 39 changed files with 711 additions and 602 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -71,3 +71,6 @@ test_multi_heap_host

# Results for the checking of the Python coding style
flake8_output.txt

# ESP-IDF library
build
153 changes: 153 additions & 0 deletions CMakeLists.txt
@@ -0,0 +1,153 @@
cmake_minimum_required(VERSION 3.5)
project(esp-idf C CXX ASM)

if(NOT IDF_PATH)
set(IDF_PATH ${CMAKE_CURRENT_LIST_DIR})
endif()

include(tools/cmake/idf_functions.cmake)

#
# Set variables that control the build configuration and the build itself
#
idf_set_variables()

kconfig_set_variables()

#
# Generate a component dependencies file, enumerating components to be included in the build
# as well as their dependencies.
#
execute_process(COMMAND "${CMAKE_COMMAND}"
-D "COMPONENTS=${IDF_COMPONENTS}"
-D "COMPONENT_REQUIRES_COMMON=${IDF_COMPONENT_REQUIRES_COMMON}"
-D "EXCLUDE_COMPONENTS=${IDF_EXCLUDE_COMPONENTS}"
-D "TEST_COMPONENTS=${IDF_TEST_COMPONENTS}"
-D "TEST_EXCLUDE_COMPONENTS=${IDF_TEST_EXCLUDE_COMPONENTS}"
-D "BUILD_TESTS=${IDF_BUILD_TESTS}"
-D "DEPENDENCIES_FILE=${CMAKE_BINARY_DIR}/component_depends.cmake"
-D "COMPONENT_DIRS=${IDF_COMPONENT_DIRS}"
-D "BOOTLOADER_BUILD=${BOOTLOADER_BUILD}"
-D "IDF_TARGET=${IDF_TARGET}"
-D "IDF_PATH=${IDF_PATH}"
-D "DEBUG=${DEBUG}"
-P "${IDF_PATH}/tools/cmake/scripts/expand_requirements.cmake"
WORKING_DIRECTORY "${PROJECT_PATH}")
include("${CMAKE_BINARY_DIR}/component_depends.cmake")

#
# We now have the following component-related variables:
#
# IDF_COMPONENTS is the list of initial components set by the user
# (or empty to include all components in the build).
# BUILD_COMPONENTS is the list of components to include in the build.
# BUILD_COMPONENT_PATHS is the paths to all of these components, obtained from the component dependencies file.
#
# Print the list of found components and test components
#
string(REPLACE ";" " " BUILD_COMPONENTS_SPACES "${BUILD_COMPONENTS}")
message(STATUS "Component names: ${BUILD_COMPONENTS_SPACES}")
unset(BUILD_COMPONENTS_SPACES)
message(STATUS "Component paths: ${BUILD_COMPONENT_PATHS}")

# Print list of test components
if(TESTS_ALL EQUAL 1 OR TEST_COMPONENTS)
string(REPLACE ";" " " BUILD_TEST_COMPONENTS_SPACES "${BUILD_TEST_COMPONENTS}")
message(STATUS "Test component names: ${BUILD_TEST_COMPONENTS_SPACES}")
unset(BUILD_TEST_COMPONENTS_SPACES)
message(STATUS "Test component paths: ${BUILD_TEST_COMPONENT_PATHS}")
endif()

# Generate project configuration
kconfig_process_config()

# Include sdkconfig.cmake so rest of the build knows the configuration
include(${SDKCONFIG_CMAKE})

# Verify the environment is configured correctly
idf_verify_environment()

# Check git revision (may trigger reruns of cmake)
## sets IDF_VER to IDF git revision
idf_get_git_revision()

# Check that the targets set in cache, sdkconfig, and in environment all match
idf_check_config_target()

## if project uses git, retrieve revision
git_describe(PROJECT_VER "${CMAKE_CURRENT_SOURCE_DIR}")

# Add some idf-wide definitions
idf_set_global_compile_options()

# generate compile_commands.json (needs to come after project)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

#
# Setup variables for linker script generation
#
ldgen_set_variables()

# Include any top-level project_include.cmake files from components
foreach(component ${BUILD_COMPONENT_PATHS})
set(COMPONENT_PATH "${component}")
include_if_exists("${component}/project_include.cmake")
unset(COMPONENT_PATH)
endforeach()

#
# Add each component to the build as a library
#
foreach(COMPONENT_PATH ${BUILD_COMPONENT_PATHS})
get_filename_component(COMPONENT_NAME ${COMPONENT_PATH} NAME)

list(FIND BUILD_TEST_COMPONENT_PATHS ${COMPONENT_PATH} idx)

if(NOT idx EQUAL -1)
list(GET BUILD_TEST_COMPONENTS ${idx} test_component)
set(COMPONENT_NAME ${test_component})
endif()

component_get_target(COMPONENT_TARGET ${COMPONENT_NAME})

add_subdirectory(${COMPONENT_PATH} ${COMPONENT_NAME})
endforeach()
unset(COMPONENT_NAME)
unset(COMPONENT_PATH)

# each component should see the include directories of its requirements
#
# (we can't do this until all components are registered and targets exist in cmake, as we have
# a circular requirements graph...)
foreach(component ${BUILD_COMPONENTS})
component_get_target(component_target ${component})
if(TARGET ${component_target})
get_component_requirements(${component} deps priv_deps)

list(APPEND priv_deps ${IDF_COMPONENT_REQUIRES_COMMON})

foreach(dep ${deps})
component_get_target(dep_target ${dep})
add_component_dependencies(${component_target} ${dep_target} PUBLIC)
endforeach()

foreach(dep ${priv_deps})
component_get_target(dep_target ${dep})
add_component_dependencies(${component_target} ${dep_target} PRIVATE)
endforeach()
endif()
endforeach()

if(IDF_BUILD_ARTIFACTS)
# Write project description JSON file
make_json_list("${BUILD_COMPONENTS}" build_components_json)
make_json_list("${BUILD_COMPONENT_PATHS}" build_component_paths_json)
configure_file("${IDF_PATH}/tools/cmake/project_description.json.in"
"${IDF_BUILD_ARTIFACTS_DIR}/project_description.json")
unset(build_components_json)
unset(build_component_paths_json)
endif()

set(BUILD_COMPONENTS ${BUILD_COMPONENTS} PARENT_SCOPE)

ldgen_add_dependencies()
2 changes: 1 addition & 1 deletion components/app_trace/CMakeLists.txt
Expand Up @@ -26,4 +26,4 @@ register_component()
# for gcov
component_compile_options("-fno-profile-arcs" "-fno-test-coverage")

target_link_libraries(app_trace gcov)
target_link_libraries(${COMPONENT_TARGET} gcov)
9 changes: 5 additions & 4 deletions components/app_update/CMakeLists.txt
Expand Up @@ -7,11 +7,12 @@ set(COMPONENT_PRIV_REQUIRES bootloader_support)
register_component()

# Add custom target for generating empty otadata partition for flashing
if(${OTADATA_PARTITION_OFFSET})
add_custom_command(OUTPUT "${PROJECT_BINARY_DIR}/${BLANK_OTADATA_FILE}"
if(OTADATA_PARTITION_OFFSET AND IDF_BUILD_ARTIFACTS)
add_custom_command(OUTPUT "${IDF_BUILD_ARTIFACTS_DIR}/${BLANK_OTADATA_FILE}"
COMMAND ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/gen_empty_partition.py
--size ${OTADATA_PARTITION_SIZE} "${PROJECT_BINARY_DIR}/${BLANK_OTADATA_FILE}")
--size ${OTADATA_PARTITION_SIZE} "${IDF_BUILD_ARTIFACTS_DIR}/${BLANK_OTADATA_FILE}")

add_custom_target(blank_ota_data ALL DEPENDS "${IDF_BUILD_ARTIFACTS_DIR}/${BLANK_OTADATA_FILE}")

add_custom_target(blank_ota_data ALL DEPENDS "${PROJECT_BINARY_DIR}/${BLANK_OTADATA_FILE}")
add_dependencies(flash blank_ota_data)
endif()
2 changes: 1 addition & 1 deletion components/app_update/project_include.cmake
Expand Up @@ -3,6 +3,6 @@
# partition table
# (NB: because of component dependency, we know partition_table
# project_include.cmake has already been included.)
if(${OTADATA_PARTITION_OFFSET})
if(OTADATA_PARTITION_OFFSET AND IDF_BUILD_ARTIFACTS)
set(BLANK_OTADATA_FILE "ota_data_initial.bin")
endif()
8 changes: 4 additions & 4 deletions components/bootloader/project_include.cmake
Expand Up @@ -2,7 +2,7 @@
if(BOOTLOADER_BUILD)
set(main_project_path "${CMAKE_BINARY_DIR}/../..")
else()
set(main_project_path "${PROJECT_PATH}")
set(main_project_path "${IDF_PROJECT_PATH}")
endif()

get_filename_component(secure_boot_signing_key
Expand All @@ -19,15 +19,15 @@ else()
add_custom_target(gen_secure_boot_signing_key)
endif()

if(BOOTLOADER_BUILD)
return() # don't keep recursing!
if(BOOTLOADER_BUILD OR NOT IDF_BUILD_ARTIFACTS)
return() # don't keep recursing, generate on project builds
endif()

# Glue to build the bootloader subproject binary as an external
# cmake project under this one
#
#
set(bootloader_build_dir "${CMAKE_BINARY_DIR}/bootloader")
set(bootloader_build_dir "${IDF_BUILD_ARTIFACTS_DIR}/bootloader")
set(bootloader_binary_files
"${bootloader_build_dir}/bootloader.elf"
"${bootloader_build_dir}/bootloader.bin"
Expand Down
12 changes: 10 additions & 2 deletions components/bootloader/subproject/CMakeLists.txt
Expand Up @@ -21,8 +21,16 @@ project(bootloader)

target_linker_script(bootloader.elf
"main/esp32.bootloader.ld"
"main/esp32.bootloader.rom.ld")
# Imported from esp32 component
"main/esp32.bootloader.rom.ld"
)

# as cmake won't attach linker args to a header-only library, attach
# linker args directly to the bootloader.elf
set(ESP32_BOOTLOADER_LINKER_SCRIPTS
"../../esp32/ld/esp32.rom.ld"
"../../esp32/ld/esp32.rom.spiram_incompatible_fns.ld"
"../../esp32/ld/esp32.peripherals.ld")

target_linker_script(bootloader.elf ${ESP32_BOOTLOADER_LINKER_SCRIPTS})

target_link_libraries(bootloader.elf gcc)
Expand Down
4 changes: 2 additions & 2 deletions components/bt/CMakeLists.txt
Expand Up @@ -281,6 +281,6 @@ if(CONFIG_BT_ENABLED)
component_compile_options(-Wno-implicit-fallthrough -Wno-unused-const-variable)
endif()

target_link_libraries(bt "-L${CMAKE_CURRENT_LIST_DIR}/lib")
target_link_libraries(bt btdm_app)
target_link_libraries(${COMPONENT_TARGET} "-L${CMAKE_CURRENT_LIST_DIR}/lib")
target_link_libraries(${COMPONENT_TARGET} btdm_app)
endif()
2 changes: 1 addition & 1 deletion components/coap/CMakeLists.txt
Expand Up @@ -24,7 +24,7 @@ register_component()
# Needed for coap headers in public builds, also.
#
# TODO: find a way to move this to a port header
target_compile_definitions(coap PUBLIC WITH_POSIX)
target_compile_definitions(${COMPONENT_TARGET} PUBLIC WITH_POSIX)

set_source_files_properties(
libcoap/src/debug.c
Expand Down
6 changes: 3 additions & 3 deletions components/cxx/CMakeLists.txt
Expand Up @@ -3,10 +3,10 @@ set(COMPONENT_SRCS "cxx_exception_stubs.cpp"
set(COMPONENT_REQUIRES)
register_component()

target_link_libraries(cxx stdc++)
target_link_libraries(${COMPONENT_TARGET} stdc++)

target_link_libraries(cxx "-u __cxa_guard_dummy")
target_link_libraries(${COMPONENT_TARGET} "-u __cxa_guard_dummy")

if(NOT CONFIG_CXX_EXCEPTIONS)
target_link_libraries(cxx "-u __cxx_fatal_exception")
target_link_libraries(${COMPONENT_TARGET} "-u __cxx_fatal_exception")
endif()

0 comments on commit 37d30c7

Please sign in to comment.