]> granicus.if.org Git - esp-idf/commitdiff
cmake: Remove defaults for COMPONENT_SRCDIRS, COMPONENT_SRCS, COMPONENT_ADD_INCLUDEDIRS
authorAngus Gratton <angus@espressif.com>
Fri, 19 Jan 2018 05:22:08 +0000 (16:22 +1100)
committerAngus Gratton <gus@projectgus.com>
Sun, 29 Apr 2018 23:59:20 +0000 (09:59 +1000)
* 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

30 files changed:
components/app_trace/CMakeLists.txt
components/app_update/CMakeLists.txt
components/bootloader_support/CMakeLists.txt
components/console/CMakeLists.txt
components/cxx/CMakeLists.txt
components/driver/CMakeLists.txt
components/esp32/CMakeLists.txt
components/esp_adc_cal/CMakeLists.txt
components/ethernet/CMakeLists.txt
components/expat/CMakeLists.txt
components/fatfs/CMakeLists.txt
components/freertos/CMakeLists.txt
components/heap/CMakeLists.txt
components/idf_test/CMakeLists.txt
components/jsmn/CMakeLists.txt
components/json/CMakeLists.txt
components/log/CMakeLists.txt
components/mdns/CMakeLists.txt
components/newlib/CMakeLists.txt
components/nvs_flash/CMakeLists.txt
components/sdmmc/CMakeLists.txt
components/tcpip_adapter/CMakeLists.txt
components/ulp/CMakeLists.txt
components/vfs/CMakeLists.txt
components/wear_levelling/CMakeLists.txt
components/wpa_supplicant/CMakeLists.txt
components/xtensa-debug-module/CMakeLists.txt
examples/protocols/aws_iot/subscribe_publish/CMakeLists.txt
tools/cmake/components.cmake
tools/cmake/utilities.cmake

index 339733b43da5860158bca5b4054ef1d7f3b3926a..ba2fa9c7e7969fc30c1581d965c214f584dd777e 100644 (file)
@@ -1 +1,4 @@
+set(COMPONENT_SRCDIRS ".")
+set(COMPONENT_ADD_INCLUDEDIRS "include")
+
 register_component()
index 339733b43da5860158bca5b4054ef1d7f3b3926a..ba2fa9c7e7969fc30c1581d965c214f584dd777e 100644 (file)
@@ -1 +1,4 @@
+set(COMPONENT_SRCDIRS ".")
+set(COMPONENT_ADD_INCLUDEDIRS "include")
+
 register_component()
index f27310dfc25535c3f6395bb51c75d6e973adeb52..1e5c52fb8142b2f140908b2afeb089122250f1c8 100644 (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()
 
index d1187256b4de298e5b37610685140d5cc7e9e050..1c5648654cd3e03bbbf9fde2aa36488e113760a0 100644 (file)
@@ -1,3 +1,5 @@
+set(COMPONENT_ADD_INCLUDEDIRS .)
 set(COMPONENT_SRCDIRS linenoise argtable3 .)
+
 register_component()
 
index bf51565c4366feeaf96be538e589ebf510ac2519..c7341ceabc145e63a5ac0f879d6a32d0bf6d812e 100644 (file)
@@ -1,3 +1,4 @@
+set(COMPONENT_SRCDIRS ".")
 register_component()
 
 target_link_libraries(cxx stdc++)
index ca084982420ddc56fadd590a7f4533c5fbcfdf33..8ccaad2c32dcc7de1a1b25ff8f8b331c3f614ca3 100644 (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()
index 447e95d23d4cbce79292a13110f13569b30a7850..cf0dff1f0b4f588d544255c44ae8385a36296a5b 100644 (file)
@@ -11,6 +11,7 @@ else()
   # Regular app build
 
   set(COMPONENT_SRCDIRS ". hwcrypto")
+  set(COMPONENT_ADD_INCLUDEDIRS "include")
 
   register_component()
 
index 339733b43da5860158bca5b4054ef1d7f3b3926a..ba2fa9c7e7969fc30c1581d965c214f584dd777e 100644 (file)
@@ -1 +1,4 @@
+set(COMPONENT_SRCDIRS ".")
+set(COMPONENT_ADD_INCLUDEDIRS "include")
+
 register_component()
index 4e20fbead01145c24d20030c7bbde7122277748d..a9eb903703dbb909095baddfbf4da27532e54232 100644 (file)
@@ -1,3 +1,4 @@
 set(COMPONENT_SRCDIRS . eth_phy)
+set(COMPONENT_ADD_INCLUDEDIRS "include")
 
 register_component()
index 02445015c48ba98a25abf0746b5667595a39d651..c35d79ce62ce984b98286b8cc2b752b4ccd75251 100644 (file)
@@ -1,5 +1,4 @@
 set(COMPONENT_ADD_INCLUDEDIRS port/include include/expat)
-
 set(COMPONENT_SRCDIRS library port)
 
 register_component()
index 2f3a8882684ccf35d73ee1437cb90fd4f43278f4..c9f5a0fcfd5a1b10799a9e834dd0c0df4ee78827 100644 (file)
@@ -1,4 +1,4 @@
+set(COMPONENT_SRCDIRS src)
 set(COMPONENT_ADD_INCLUDEDIRS src)
-set(COMPONENT_SRCDIRS src/option src)
 
 register_component()
index 1c6a9523b4344f02b299f79404a298f85413cd7e..0a5172dc10b7acfafe4a8eda1585c18070ec0a96 100644 (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")
index 015daa9b7a514b7c496a41aec8aa544b71433315..6fd009ae9801ccfdfe3b1135511ece46b765ed55 100644 (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)
index 131acae4d5ca4d52ad6d9dc7af857fdd34760fed..e307838a8b2d096e8fc025f0144306699eb4b32c 100644 (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()
index 817f6e4bebe960b3b19bef7f6d770650a7db60da..2eabcf5fe616966a4905b890011a9592df717b85 100644 (file)
@@ -1,2 +1,4 @@
-set(COMPONENT_SRCDIRS src)
+set(COMPONENT_SRCDIRS "src")
+set(COMPONENT_ADD_INCLUDEDIRS "include")
+
 register_component()
index e3559b2690f18ef2281ef25730c266560a2b9636..c19ec43fa8b4e281f93f6e652de56c93dba85e83 100644 (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()
index 339733b43da5860158bca5b4054ef1d7f3b3926a..eebd20a046213a730b2a05b8158054f12fe16925 100644 (file)
@@ -1 +1,3 @@
+set(COMPONENT_SRCDIRS ".")
+set(COMPONENT_ADD_INCLUDEDIRS "include")
 register_component()
index 0ba2e49dc3d06d069f2e2fb64baebfec382a5670..149dcb0bccbc899a5b30c91b1cfaa07af04a9a35 100644 (file)
@@ -1,2 +1,5 @@
+set(COMPONENT_SRCDIRS ".")
+set(COMPONENT_ADD_INCLUDEDIRS "include")
+set(COMPONENT_PRIV_INCLUDEDIRS "private_include")
 register_component()
 
index 0fa454cba2697f80acf6f1d60be552499e003919..09f26c46a1d1689d0756492da690519835297caf 100644 (file)
@@ -1,3 +1,4 @@
+set(COMPONENT_SRCDIRS ".")
 set(COMPONENT_ADD_INCLUDEDIRS platform_include include)
 
 if(CONFIG_SPIRAM_CACHE_WORKAROUND)
index 7a9584c6d0c4ec63f2d7ea0f1d6069685be77850..5970a79154b9f61cd40a8024748e9f360a2697df 100644 (file)
@@ -1,4 +1,4 @@
-set(COMPONENT_ADD_INCLUDEDIRS include)
 set(COMPONENT_SRCDIRS src)
+set(COMPONENT_ADD_INCLUDEDIRS include)
 
 register_component()
index 339733b43da5860158bca5b4054ef1d7f3b3926a..ba2fa9c7e7969fc30c1581d965c214f584dd777e 100644 (file)
@@ -1 +1,4 @@
+set(COMPONENT_SRCDIRS ".")
+set(COMPONENT_ADD_INCLUDEDIRS "include")
+
 register_component()
index 339733b43da5860158bca5b4054ef1d7f3b3926a..ba2fa9c7e7969fc30c1581d965c214f584dd777e 100644 (file)
@@ -1 +1,4 @@
+set(COMPONENT_SRCDIRS ".")
+set(COMPONENT_ADD_INCLUDEDIRS "include")
+
 register_component()
index 339733b43da5860158bca5b4054ef1d7f3b3926a..ba2fa9c7e7969fc30c1581d965c214f584dd777e 100644 (file)
@@ -1 +1,4 @@
+set(COMPONENT_SRCDIRS ".")
+set(COMPONENT_ADD_INCLUDEDIRS "include")
+
 register_component()
index 339733b43da5860158bca5b4054ef1d7f3b3926a..ba2fa9c7e7969fc30c1581d965c214f584dd777e 100644 (file)
@@ -1 +1,4 @@
+set(COMPONENT_SRCDIRS ".")
+set(COMPONENT_ADD_INCLUDEDIRS "include")
+
 register_component()
index f4f2f14ec3f46c395acf14bc52e144afc9b338e1..a72d0f565f69974b6602dd3628424a73abc9a30b 100644 (file)
@@ -1,2 +1,4 @@
+set(COMPONENT_SRCDIRS ".")
+set(COMPONENT_ADD_INCLUDEDIRS "include")
 set(COMPONENT_PRIV_INCLUDEDIRS private_include)
 register_component()
index 73c7294a664ddf0ddc41fdd77b11b5704f3a8576..0b06eeeb42b46ff4c92a2ea75d5e5b515e4090f7 100644 (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()
 
index 339733b43da5860158bca5b4054ef1d7f3b3926a..ba2fa9c7e7969fc30c1581d965c214f584dd777e 100644 (file)
@@ -1 +1,4 @@
+set(COMPONENT_SRCDIRS ".")
+set(COMPONENT_ADD_INCLUDEDIRS "include")
+
 register_component()
index bf0e566104bb4028041bc480cae19527d075aebb..297e7b73aa1b9ae5701cbdd0766d17c15a50f5e6 100644 (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)
 
-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})
index 8e2b857756475fad10947f6d77cf46899ccf149d..bd9481b4870493355f0c4f86ce1f08d1724e6f62 100644 (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(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)
index 045b884973414709ab51e8d66230ce9583e83ca5..5c3bac996ec26621f3a787fa4ba46b3fe42d8ff7 100644 (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()