From: Angus Gratton Date: Fri, 19 Jan 2018 05:22:08 +0000 (+1100) Subject: cmake: Remove defaults for COMPONENT_SRCDIRS, COMPONENT_SRCS, COMPONENT_ADD_INCLUDEDIRS X-Git-Tag: v3.1-rc2~9^2~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f1a856dbfd752336cd71730105e02ad8c045541;p=esp-idf 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 --- diff --git a/components/app_trace/CMakeLists.txt b/components/app_trace/CMakeLists.txt index 339733b43d..ba2fa9c7e7 100644 --- a/components/app_trace/CMakeLists.txt +++ b/components/app_trace/CMakeLists.txt @@ -1 +1,4 @@ +set(COMPONENT_SRCDIRS ".") +set(COMPONENT_ADD_INCLUDEDIRS "include") + register_component() diff --git a/components/app_update/CMakeLists.txt b/components/app_update/CMakeLists.txt index 339733b43d..ba2fa9c7e7 100644 --- a/components/app_update/CMakeLists.txt +++ b/components/app_update/CMakeLists.txt @@ -1 +1,4 @@ +set(COMPONENT_SRCDIRS ".") +set(COMPONENT_ADD_INCLUDEDIRS "include") + register_component() diff --git a/components/bootloader_support/CMakeLists.txt b/components/bootloader_support/CMakeLists.txt index f27310dfc2..1e5c52fb81 100644 --- a/components/bootloader_support/CMakeLists.txt +++ b/components/bootloader_support/CMakeLists.txt @@ -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() diff --git a/components/console/CMakeLists.txt b/components/console/CMakeLists.txt index d1187256b4..1c5648654c 100644 --- a/components/console/CMakeLists.txt +++ b/components/console/CMakeLists.txt @@ -1,3 +1,5 @@ +set(COMPONENT_ADD_INCLUDEDIRS .) set(COMPONENT_SRCDIRS linenoise argtable3 .) + register_component() diff --git a/components/cxx/CMakeLists.txt b/components/cxx/CMakeLists.txt index bf51565c43..c7341ceabc 100644 --- a/components/cxx/CMakeLists.txt +++ b/components/cxx/CMakeLists.txt @@ -1,3 +1,4 @@ +set(COMPONENT_SRCDIRS ".") register_component() target_link_libraries(cxx stdc++) diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index ca08498242..8ccaad2c32 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -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() diff --git a/components/esp32/CMakeLists.txt b/components/esp32/CMakeLists.txt index 447e95d23d..cf0dff1f0b 100644 --- a/components/esp32/CMakeLists.txt +++ b/components/esp32/CMakeLists.txt @@ -11,6 +11,7 @@ else() # Regular app build set(COMPONENT_SRCDIRS ". hwcrypto") + set(COMPONENT_ADD_INCLUDEDIRS "include") register_component() diff --git a/components/esp_adc_cal/CMakeLists.txt b/components/esp_adc_cal/CMakeLists.txt index 339733b43d..ba2fa9c7e7 100644 --- a/components/esp_adc_cal/CMakeLists.txt +++ b/components/esp_adc_cal/CMakeLists.txt @@ -1 +1,4 @@ +set(COMPONENT_SRCDIRS ".") +set(COMPONENT_ADD_INCLUDEDIRS "include") + register_component() diff --git a/components/ethernet/CMakeLists.txt b/components/ethernet/CMakeLists.txt index 4e20fbead0..a9eb903703 100644 --- a/components/ethernet/CMakeLists.txt +++ b/components/ethernet/CMakeLists.txt @@ -1,3 +1,4 @@ set(COMPONENT_SRCDIRS . eth_phy) +set(COMPONENT_ADD_INCLUDEDIRS "include") register_component() diff --git a/components/expat/CMakeLists.txt b/components/expat/CMakeLists.txt index 02445015c4..c35d79ce62 100644 --- a/components/expat/CMakeLists.txt +++ b/components/expat/CMakeLists.txt @@ -1,5 +1,4 @@ set(COMPONENT_ADD_INCLUDEDIRS port/include include/expat) - set(COMPONENT_SRCDIRS library port) register_component() diff --git a/components/fatfs/CMakeLists.txt b/components/fatfs/CMakeLists.txt index 2f3a888268..c9f5a0fcfd 100644 --- a/components/fatfs/CMakeLists.txt +++ b/components/fatfs/CMakeLists.txt @@ -1,4 +1,4 @@ +set(COMPONENT_SRCDIRS src) set(COMPONENT_ADD_INCLUDEDIRS src) -set(COMPONENT_SRCDIRS src/option src) register_component() diff --git a/components/freertos/CMakeLists.txt b/components/freertos/CMakeLists.txt index 1c6a9523b4..0a5172dc10 100644 --- a/components/freertos/CMakeLists.txt +++ b/components/freertos/CMakeLists.txt @@ -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") diff --git a/components/heap/CMakeLists.txt b/components/heap/CMakeLists.txt index 015daa9b7a..6fd009ae98 100644 --- a/components/heap/CMakeLists.txt +++ b/components/heap/CMakeLists.txt @@ -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) diff --git a/components/idf_test/CMakeLists.txt b/components/idf_test/CMakeLists.txt index 131acae4d5..e307838a8b 100644 --- a/components/idf_test/CMakeLists.txt +++ b/components/idf_test/CMakeLists.txt @@ -1,2 +1,2 @@ -# idf_test will be registered as an INTERFACE library (ie header paths only) +set(COMPONENT_ADD_INCLUDEDIRS "include") register_component() diff --git a/components/jsmn/CMakeLists.txt b/components/jsmn/CMakeLists.txt index 817f6e4beb..2eabcf5fe6 100644 --- a/components/jsmn/CMakeLists.txt +++ b/components/jsmn/CMakeLists.txt @@ -1,2 +1,4 @@ -set(COMPONENT_SRCDIRS src) +set(COMPONENT_SRCDIRS "src") +set(COMPONENT_ADD_INCLUDEDIRS "include") + register_component() diff --git a/components/json/CMakeLists.txt b/components/json/CMakeLists.txt index e3559b2690..c19ec43fa8 100644 --- a/components/json/CMakeLists.txt +++ b/components/json/CMakeLists.txt @@ -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() diff --git a/components/log/CMakeLists.txt b/components/log/CMakeLists.txt index 339733b43d..eebd20a046 100644 --- a/components/log/CMakeLists.txt +++ b/components/log/CMakeLists.txt @@ -1 +1,3 @@ +set(COMPONENT_SRCDIRS ".") +set(COMPONENT_ADD_INCLUDEDIRS "include") register_component() diff --git a/components/mdns/CMakeLists.txt b/components/mdns/CMakeLists.txt index 0ba2e49dc3..149dcb0bcc 100644 --- a/components/mdns/CMakeLists.txt +++ b/components/mdns/CMakeLists.txt @@ -1,2 +1,5 @@ +set(COMPONENT_SRCDIRS ".") +set(COMPONENT_ADD_INCLUDEDIRS "include") +set(COMPONENT_PRIV_INCLUDEDIRS "private_include") register_component() diff --git a/components/newlib/CMakeLists.txt b/components/newlib/CMakeLists.txt index 0fa454cba2..09f26c46a1 100644 --- a/components/newlib/CMakeLists.txt +++ b/components/newlib/CMakeLists.txt @@ -1,3 +1,4 @@ +set(COMPONENT_SRCDIRS ".") set(COMPONENT_ADD_INCLUDEDIRS platform_include include) if(CONFIG_SPIRAM_CACHE_WORKAROUND) diff --git a/components/nvs_flash/CMakeLists.txt b/components/nvs_flash/CMakeLists.txt index 7a9584c6d0..5970a79154 100644 --- a/components/nvs_flash/CMakeLists.txt +++ b/components/nvs_flash/CMakeLists.txt @@ -1,4 +1,4 @@ -set(COMPONENT_ADD_INCLUDEDIRS include) set(COMPONENT_SRCDIRS src) +set(COMPONENT_ADD_INCLUDEDIRS include) register_component() diff --git a/components/sdmmc/CMakeLists.txt b/components/sdmmc/CMakeLists.txt index 339733b43d..ba2fa9c7e7 100644 --- a/components/sdmmc/CMakeLists.txt +++ b/components/sdmmc/CMakeLists.txt @@ -1 +1,4 @@ +set(COMPONENT_SRCDIRS ".") +set(COMPONENT_ADD_INCLUDEDIRS "include") + register_component() diff --git a/components/tcpip_adapter/CMakeLists.txt b/components/tcpip_adapter/CMakeLists.txt index 339733b43d..ba2fa9c7e7 100644 --- a/components/tcpip_adapter/CMakeLists.txt +++ b/components/tcpip_adapter/CMakeLists.txt @@ -1 +1,4 @@ +set(COMPONENT_SRCDIRS ".") +set(COMPONENT_ADD_INCLUDEDIRS "include") + register_component() diff --git a/components/ulp/CMakeLists.txt b/components/ulp/CMakeLists.txt index 339733b43d..ba2fa9c7e7 100644 --- a/components/ulp/CMakeLists.txt +++ b/components/ulp/CMakeLists.txt @@ -1 +1,4 @@ +set(COMPONENT_SRCDIRS ".") +set(COMPONENT_ADD_INCLUDEDIRS "include") + register_component() diff --git a/components/vfs/CMakeLists.txt b/components/vfs/CMakeLists.txt index 339733b43d..ba2fa9c7e7 100644 --- a/components/vfs/CMakeLists.txt +++ b/components/vfs/CMakeLists.txt @@ -1 +1,4 @@ +set(COMPONENT_SRCDIRS ".") +set(COMPONENT_ADD_INCLUDEDIRS "include") + register_component() diff --git a/components/wear_levelling/CMakeLists.txt b/components/wear_levelling/CMakeLists.txt index f4f2f14ec3..a72d0f565f 100644 --- a/components/wear_levelling/CMakeLists.txt +++ b/components/wear_levelling/CMakeLists.txt @@ -1,2 +1,4 @@ +set(COMPONENT_SRCDIRS ".") +set(COMPONENT_ADD_INCLUDEDIRS "include") set(COMPONENT_PRIV_INCLUDEDIRS private_include) register_component() diff --git a/components/wpa_supplicant/CMakeLists.txt b/components/wpa_supplicant/CMakeLists.txt index 73c7294a66..0b06eeeb42 100644 --- a/components/wpa_supplicant/CMakeLists.txt +++ b/components/wpa_supplicant/CMakeLists.txt @@ -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() diff --git a/components/xtensa-debug-module/CMakeLists.txt b/components/xtensa-debug-module/CMakeLists.txt index 339733b43d..ba2fa9c7e7 100644 --- a/components/xtensa-debug-module/CMakeLists.txt +++ b/components/xtensa-debug-module/CMakeLists.txt @@ -1 +1,4 @@ +set(COMPONENT_SRCDIRS ".") +set(COMPONENT_ADD_INCLUDEDIRS "include") + register_component() diff --git a/examples/protocols/aws_iot/subscribe_publish/CMakeLists.txt b/examples/protocols/aws_iot/subscribe_publish/CMakeLists.txt index bf0e566104..297e7b73aa 100644 --- a/examples/protocols/aws_iot/subscribe_publish/CMakeLists.txt +++ b/examples/protocols/aws_iot/subscribe_publish/CMakeLists.txt @@ -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) -include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(subscribe_publish ASM C CXX) + +set(MAIN_SRCS main/subscribe_publish_sample.c) -add_executable(subscribe_publish.elf - main/subscribe_publish_sample.c) +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +# 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}) diff --git a/tools/cmake/components.cmake b/tools/cmake/components.cmake index 8e2b857756..bd9481b487 100644 --- a/tools/cmake/components.cmake +++ b/tools/cmake/components.cmake @@ -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(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() - get_filename_component(include_dir ${include_dir} ABSOLUTE BASE_DIR ${component_dir}) - target_include_directories(${component} PRIVATE ${include_dir}) + target_include_directories(${component} PRIVATE ${abs_dir}) endforeach() endfunction(register_component) diff --git a/tools/cmake/utilities.cmake b/tools/cmake/utilities.cmake index 045b884973..5c3bac996e 100644 --- a/tools/cmake/utilities.cmake +++ b/tools/cmake/utilities.cmake @@ -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()