cmake: Remove defaults for COMPONENT_SRCDIRS, COMPONENT_SRCS, COMPONENT_ADD_INCLUDEDIRS

* Philosophical: "explicit is better than implicit".
* Practical: Allows useful errors if invalid directories given in components as the defaults aren't
  always used. Also trims the -I path from a number of components that have no actual include
  directory.
* Simplifies knowing which components will be header-only and which won't
This commit is contained in:
Angus Gratton 2018-01-19 16:22:08 +11:00 committed by Angus Gratton
parent 3fac2b2ddc
commit 4f1a856dbf
30 changed files with 80 additions and 32 deletions

View File

@ -1 +1,4 @@
set(COMPONENT_SRCDIRS ".")
set(COMPONENT_ADD_INCLUDEDIRS "include")
register_component()

View File

@ -1 +1,4 @@
set(COMPONENT_SRCDIRS ".")
set(COMPONENT_ADD_INCLUDEDIRS "include")
register_component()

View File

@ -3,6 +3,7 @@ set(COMPONENT_SRCDIRS "src")
if(${BOOTLOADER_BUILD})
set(COMPONENT_ADD_INCLUDEDIRS "include include_priv")
else()
set(COMPONENT_ADD_INCLUDEDIRS "include")
set(COMPONENT_PRIV_INCLUDEDIRS "include_priv")
endif()

View File

@ -1,3 +1,5 @@
set(COMPONENT_ADD_INCLUDEDIRS .)
set(COMPONENT_SRCDIRS linenoise argtable3 .)
register_component()

View File

@ -1,3 +1,4 @@
set(COMPONENT_SRCDIRS ".")
register_component()
target_link_libraries(cxx stdc++)

View File

@ -1,3 +1,5 @@
set(COMPONENT_PRIV_INCLUDEDIRS include/driver)
set(COMPONENT_SRCDIRS ".")
set(COMPONENT_ADD_INCLUDEDIRS "include")
set(COMPONENT_PRIV_INCLUDEDIRS "include/driver")
register_component()

View File

@ -11,6 +11,7 @@ else()
# Regular app build
set(COMPONENT_SRCDIRS ". hwcrypto")
set(COMPONENT_ADD_INCLUDEDIRS "include")
register_component()

View File

@ -1 +1,4 @@
set(COMPONENT_SRCDIRS ".")
set(COMPONENT_ADD_INCLUDEDIRS "include")
register_component()

View File

@ -1,3 +1,4 @@
set(COMPONENT_SRCDIRS . eth_phy)
set(COMPONENT_ADD_INCLUDEDIRS "include")
register_component()

View File

@ -1,5 +1,4 @@
set(COMPONENT_ADD_INCLUDEDIRS port/include include/expat)
set(COMPONENT_SRCDIRS library port)
register_component()

View File

@ -1,4 +1,4 @@
set(COMPONENT_SRCDIRS src)
set(COMPONENT_ADD_INCLUDEDIRS src)
set(COMPONENT_SRCDIRS src/option src)
register_component()

View File

@ -1,5 +1,6 @@
set(COMPONENT_ADD_INCLUDEDIRS include)
set(COMPONENT_PRIV_INCLUDEDIRS include/freertos)
set(COMPONENT_SRCDIRS ".")
register_component()
target_link_libraries(freertos "-Wl,--undefined=uxTopUsedPriority")

View File

@ -4,6 +4,8 @@ if(NOT CONFIG_HEAP_POISONING_DISABLED)
set(COMPONENT_SRCS ${COMPONENT_SRCS} multi_heap_poisoning.c)
endif()
set(COMPONENT_ADD_INCLUDEDIRS "include")
register_component()
if(CONFIG_HEAP_TRACING)

View File

@ -1,2 +1,2 @@
# idf_test will be registered as an INTERFACE library (ie header paths only)
set(COMPONENT_ADD_INCLUDEDIRS "include")
register_component()

View File

@ -1,2 +1,4 @@
set(COMPONENT_SRCDIRS src)
set(COMPONENT_SRCDIRS "src")
set(COMPONENT_ADD_INCLUDEDIRS "include")
register_component()

View File

@ -1,4 +1,4 @@
set(COMPONENT_SRCDIRS library port)
set(COMPONENT_ADD_INCLUDEDIRS include port/include)
set(COMPONENT_SRCDIRS cJSON)
set(COMPONENT_ADD_INCLUDEDIRS cJSON)
register_component()

View File

@ -1 +1,3 @@
set(COMPONENT_SRCDIRS ".")
set(COMPONENT_ADD_INCLUDEDIRS "include")
register_component()

View File

@ -1,2 +1,5 @@
set(COMPONENT_SRCDIRS ".")
set(COMPONENT_ADD_INCLUDEDIRS "include")
set(COMPONENT_PRIV_INCLUDEDIRS "private_include")
register_component()

View File

@ -1,3 +1,4 @@
set(COMPONENT_SRCDIRS ".")
set(COMPONENT_ADD_INCLUDEDIRS platform_include include)
if(CONFIG_SPIRAM_CACHE_WORKAROUND)

View File

@ -1,4 +1,4 @@
set(COMPONENT_ADD_INCLUDEDIRS include)
set(COMPONENT_SRCDIRS src)
set(COMPONENT_ADD_INCLUDEDIRS include)
register_component()

View File

@ -1 +1,4 @@
set(COMPONENT_SRCDIRS ".")
set(COMPONENT_ADD_INCLUDEDIRS "include")
register_component()

View File

@ -1 +1,4 @@
set(COMPONENT_SRCDIRS ".")
set(COMPONENT_ADD_INCLUDEDIRS "include")
register_component()

View File

@ -1 +1,4 @@
set(COMPONENT_SRCDIRS ".")
set(COMPONENT_ADD_INCLUDEDIRS "include")
register_component()

View File

@ -1 +1,4 @@
set(COMPONENT_SRCDIRS ".")
set(COMPONENT_ADD_INCLUDEDIRS "include")
register_component()

View File

@ -1,2 +1,4 @@
set(COMPONENT_SRCDIRS ".")
set(COMPONENT_ADD_INCLUDEDIRS "include")
set(COMPONENT_PRIV_INCLUDEDIRS private_include)
register_component()

View File

@ -1,5 +1,5 @@
set(COMPONENT_ADD_INCLUDEDIRS include port/include)
set(COMPONENT_SRCDIRS src/crypto port src/fast_crypto)
set(COMPONENT_ADD_INCLUDEDIRS include port/include)
register_component()

View File

@ -1 +1,4 @@
set(COMPONENT_SRCDIRS ".")
set(COMPONENT_ADD_INCLUDEDIRS "include")
register_component()

View File

@ -2,17 +2,14 @@
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
set(CMAKE_TOOLCHAIN_FILE $ENV{IDF_PATH}/toolchain.cmake)
project(idf_project ASM C CXX)
project(subscribe_publish ASM C CXX)
set(MAIN_SRCS main/subscribe_publish_sample.c)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
add_executable(subscribe_publish.elf
main/subscribe_publish_sample.c)
# Embed the certificate data directly in the built binary
target_add_binary_data(subscribe_publish.elf main/certs/aws-root-ca.pem TEXT)
target_add_binary_data(subscribe_publish.elf main/certs/certificate.pem.crt TEXT)
target_add_binary_data(subscribe_publish.elf main/certs/private.pem.key TEXT)
# TODO: handle IDF_CI_BUILD dummy cert files here
target_link_libraries(subscribe_publish.elf ${COMPONENT_LIBRARIES})

View File

@ -54,24 +54,23 @@ function(register_component)
get_filename_component(component_dir ${CMAKE_CURRENT_LIST_FILE} DIRECTORY)
get_filename_component(component ${component_dir} NAME)
if(NOT COMPONENT_SRCDIRS)
set(COMPONENT_SRCDIRS ".")
endif()
spaces2list(COMPONENT_SRCDIRS)
if(NOT COMPONENT_ADD_INCLUDEDIRS)
set(COMPONENT_ADD_INCLUDEDIRS "include")
endif()
spaces2list(COMPONENT_ADD_INCLUDEDIRS)
# if not explicit, build COMPONENT_SRCS by globbing in COMPONENT_SRCDIRS
# Add to COMPONENT_SRCS by globbing in COMPONENT_SRCDIRS
if(NOT COMPONENT_SRCS)
foreach(dir ${COMPONENT_SRCDIRS})
get_filename_component(dir ${dir} ABSOLUTE BASE_DIR ${component_dir})
file(GLOB matches "${dir}/*.[c|S]" "${dir}/*.cpp")
get_filename_component(abs_dir ${dir} ABSOLUTE BASE_DIR ${component_dir})
if(NOT IS_DIRECTORY ${abs_dir})
message(FATAL_ERROR "${CMAKE_CURRENT_LIST_FILE}: COMPONENT_SRCDIRS entry '${dir}' does not exist")
endif()
file(GLOB matches "${abs_dir}/*.[c|S]" "${abs_dir}/*.cpp")
if(matches)
list(SORT matches)
set(COMPONENT_SRCS "${COMPONENT_SRCS};${matches}")
else()
message(FATAL_ERROR "${CMAKE_CURRENT_LIST_FILE}: COMPONENT_SRCDIRS entry '${dir}' contains no source files")
endif(matches)
endforeach()
endif()
@ -99,17 +98,24 @@ function(register_component)
# add public includes
foreach(include_dir ${COMPONENT_ADD_INCLUDEDIRS})
get_filename_component(include_dir ${include_dir} ABSOLUTE BASE_DIR ${component_dir})
target_include_directories(${component} ${include_type} ${include_dir})
get_filename_component(abs_dir ${include_dir} ABSOLUTE BASE_DIR ${component_dir})
if(NOT IS_DIRECTORY ${abs_dir})
message(FATAL_ERROR "${CMAKE_CURRENT_LIST_FILE}: COMPONENT_ADD_INCLUDEDIRS entry '${include_dir}' does not exist")
endif()
target_include_directories(${component} ${include_type} ${abs_dir})
endforeach()
# add private includes
foreach(include_dir ${COMPONENT_PRIV_INCLUDEDIRS})
if (${include_type} STREQUAL INTERFACE)
message(FATAL_ERROR "Component ${component} can't have no source files and COMPONENT_PRIV_INCLUDEDIRS set.")
message(FATAL_ERROR "${CMAKE_CURRENT_LIST_FILE} sets no component source files but sets COMPONENT_PRIV_INCLUDEDIRS")
endif()
get_filename_component(include_dir ${include_dir} ABSOLUTE BASE_DIR ${component_dir})
target_include_directories(${component} PRIVATE ${include_dir})
get_filename_component(abs_dir ${include_dir} ABSOLUTE BASE_DIR ${component_dir})
if(NOT IS_DIRECTORY ${abs_dir})
message(FATAL_ERROR "${CMAKE_CURRENT_LIST_FILE}: COMPONENT_PRIV_INCLUDEDIRS entry '${niclude_dir}' does not exist")
endif()
target_include_directories(${component} PRIVATE ${abs_dir})
endforeach()
endfunction(register_component)

View File

@ -39,6 +39,7 @@ endfunction()
#
function(lines2list variable_name)
string(REGEX REPLACE "\r?\n" ";" tmp "${${variable_name}}")
string(REGEX REPLACE ";;" ";" tmp "${tmp}")
set("${variable_name}" "${tmp}" PARENT_SCOPE)
endfunction()