From c671a0c3ebf90f18576d6db55b51b62730c58301 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Fri, 12 Jan 2018 13:49:13 +1100 Subject: [PATCH] build system: Initial cmake support, work in progress --- Kconfig | 13 +- components/app_trace/CMakeLists.txt | 1 + components/app_update/CMakeLists.txt | 1 + components/aws_iot/CMakeLists.txt | 9 ++ components/bootloader/CMakeLists.txt | 2 + .../bootloader/subproject/CMakeLists.txt | 26 ++++ components/bootloader_support/CMakeLists.txt | 9 ++ .../include/esp_flash_encrypt.h | 2 + components/bt/CMakeLists.txt | 99 +++++++++++++ components/coap/CMakeLists.txt | 33 +++++ components/console/CMakeLists.txt | 3 + components/cxx/CMakeLists.txt | 9 ++ components/driver/CMakeLists.txt | 3 + components/esp32/CMakeLists.txt | 58 ++++++++ components/esp_adc_cal/CMakeLists.txt | 1 + components/esptool_py/CMakeLists.txt | 1 + components/ethernet/CMakeLists.txt | 3 + components/expat/CMakeLists.txt | 14 ++ components/fatfs/CMakeLists.txt | 4 + components/freertos/CMakeLists.txt | 5 + components/heap/CMakeLists.txt | 17 +++ components/idf_test/CMakeLists.txt | 2 + components/jsmn/CMakeLists.txt | 2 + components/json/CMakeLists.txt | 4 + components/libsodium/CMakeLists.txt | 104 ++++++++++++++ components/log/CMakeLists.txt | 1 + components/lwip/CMakeLists.txt | 37 +++++ components/mbedtls/CMakeLists.txt | 8 ++ components/mdns/CMakeLists.txt | 2 + components/micro-ecc/CMakeLists.txt | 8 ++ components/newlib/CMakeLists.txt | 20 +++ components/nghttp/CMakeLists.txt | 5 + components/nvs_flash/CMakeLists.txt | 4 + components/openssl/CMakeLists.txt | 5 + components/partition_table/CMakeLists.txt | 1 + components/pthread/CMakeLists.txt | 3 + components/sdmmc/CMakeLists.txt | 1 + components/smartconfig/CMakeLists.txt | 4 + components/soc/CMakeLists.txt | 6 + components/spi_flash/CMakeLists.txt | 11 ++ components/spiffs/CMakeLists.txt | 6 + components/tcpip_adapter/CMakeLists.txt | 1 + components/ulp/CMakeLists.txt | 1 + components/vfs/CMakeLists.txt | 1 + components/wear_levelling/CMakeLists.txt | 2 + components/wpa_supplicant/CMakeLists.txt | 7 + components/xtensa-debug-module/CMakeLists.txt | 1 + .../get-started/hello_world/CMakeLists.txt | 12 ++ idf.cmake | 78 ++++++++++ toolchain.cmake | 11 ++ tools/cmake/GetGitRevisionDescription.cmake | 130 +++++++++++++++++ .../cmake/GetGitRevisionDescription.cmake.in | 41 ++++++ tools/cmake/bootloader_subproject.cmake | 13 ++ tools/cmake/components.cmake | 133 ++++++++++++++++++ tools/cmake/kconfig.cmake | 82 +++++++++++ tools/cmake/utilities.cmake | 60 ++++++++ 56 files changed, 1115 insertions(+), 5 deletions(-) create mode 100644 components/app_trace/CMakeLists.txt create mode 100644 components/app_update/CMakeLists.txt create mode 100644 components/aws_iot/CMakeLists.txt create mode 100644 components/bootloader/CMakeLists.txt create mode 100644 components/bootloader/subproject/CMakeLists.txt create mode 100644 components/bootloader_support/CMakeLists.txt create mode 100644 components/bt/CMakeLists.txt create mode 100644 components/coap/CMakeLists.txt create mode 100644 components/console/CMakeLists.txt create mode 100644 components/cxx/CMakeLists.txt create mode 100644 components/driver/CMakeLists.txt create mode 100644 components/esp32/CMakeLists.txt create mode 100644 components/esp_adc_cal/CMakeLists.txt create mode 100644 components/esptool_py/CMakeLists.txt create mode 100644 components/ethernet/CMakeLists.txt create mode 100644 components/expat/CMakeLists.txt create mode 100644 components/fatfs/CMakeLists.txt create mode 100644 components/freertos/CMakeLists.txt create mode 100644 components/heap/CMakeLists.txt create mode 100644 components/idf_test/CMakeLists.txt create mode 100644 components/jsmn/CMakeLists.txt create mode 100644 components/json/CMakeLists.txt create mode 100644 components/libsodium/CMakeLists.txt create mode 100644 components/log/CMakeLists.txt create mode 100644 components/lwip/CMakeLists.txt create mode 100644 components/mbedtls/CMakeLists.txt create mode 100644 components/mdns/CMakeLists.txt create mode 100644 components/micro-ecc/CMakeLists.txt create mode 100644 components/newlib/CMakeLists.txt create mode 100644 components/nghttp/CMakeLists.txt create mode 100644 components/nvs_flash/CMakeLists.txt create mode 100644 components/openssl/CMakeLists.txt create mode 100644 components/partition_table/CMakeLists.txt create mode 100644 components/pthread/CMakeLists.txt create mode 100644 components/sdmmc/CMakeLists.txt create mode 100644 components/smartconfig/CMakeLists.txt create mode 100644 components/soc/CMakeLists.txt create mode 100644 components/spi_flash/CMakeLists.txt create mode 100644 components/spiffs/CMakeLists.txt create mode 100644 components/tcpip_adapter/CMakeLists.txt create mode 100644 components/ulp/CMakeLists.txt create mode 100644 components/vfs/CMakeLists.txt create mode 100644 components/wear_levelling/CMakeLists.txt create mode 100644 components/wpa_supplicant/CMakeLists.txt create mode 100644 components/xtensa-debug-module/CMakeLists.txt create mode 100644 examples/get-started/hello_world/CMakeLists.txt create mode 100644 idf.cmake create mode 100644 toolchain.cmake create mode 100644 tools/cmake/GetGitRevisionDescription.cmake create mode 100644 tools/cmake/GetGitRevisionDescription.cmake.in create mode 100644 tools/cmake/bootloader_subproject.cmake create mode 100644 tools/cmake/components.cmake create mode 100644 tools/cmake/kconfig.cmake create mode 100644 tools/cmake/utilities.cmake diff --git a/Kconfig b/Kconfig index 6dfaa31838..b1498870a8 100644 --- a/Kconfig +++ b/Kconfig @@ -121,11 +121,14 @@ choice STACK_CHECK_MODE smashing attacks. This is done by adding a guard variable to functions with vulnerable objects. The guards are initialized when a function is entered and then checked when the function exits. If a guard check fails, program is halted. Protection has the following modes: - - In NORMAL mode (GCC flag: -fstack-protector) only functions that call alloca, and functions with buffers larger than - 8 bytes are protected. - - STRONG mode (GCC flag: -fstack-protector-strong) is like NORMAL, but includes additional functions to be protected -- those that - have local array definitions, or have references to local frame addresses. - - In OVERALL mode (GCC flag: -fstack-protector-all) all functions are protected. + + - In NORMAL mode (GCC flag: -fstack-protector) only functions that call + alloca, and functions with buffers larger than 8 bytes are protected. + - STRONG mode (GCC flag: -fstack-protector-strong) is like NORMAL, but + includes additional functions to be protected -- those that have + local array definitions, or have references to local frame addresses. + - In OVERALL mode (GCC flag: -fstack-protector-all) all functions are + protected. Modes have the following impact on code performance and coverage: - performance: NORMAL > STRONG > OVERALL diff --git a/components/app_trace/CMakeLists.txt b/components/app_trace/CMakeLists.txt new file mode 100644 index 0000000000..339733b43d --- /dev/null +++ b/components/app_trace/CMakeLists.txt @@ -0,0 +1 @@ +register_component() diff --git a/components/app_update/CMakeLists.txt b/components/app_update/CMakeLists.txt new file mode 100644 index 0000000000..339733b43d --- /dev/null +++ b/components/app_update/CMakeLists.txt @@ -0,0 +1 @@ +register_component() diff --git a/components/aws_iot/CMakeLists.txt b/components/aws_iot/CMakeLists.txt new file mode 100644 index 0000000000..29909bd140 --- /dev/null +++ b/components/aws_iot/CMakeLists.txt @@ -0,0 +1,9 @@ +if(CONFIG_AWS_IOT_SDK) + +set(COMPONENT_ADD_INCLUDEDIRS "include aws-iot-device-sdk-embedded-C/include") +set(COMPONENT_SRCDIRS "aws-iot-device-sdk-embedded-C/src port") +set(COMPONENT_SUBMODULES aws-iot-device-sdk-embedded-C) + +register_component() + +endif(CONFIG_AWS_IOT_SDK) diff --git a/components/bootloader/CMakeLists.txt b/components/bootloader/CMakeLists.txt new file mode 100644 index 0000000000..1b694f3819 --- /dev/null +++ b/components/bootloader/CMakeLists.txt @@ -0,0 +1,2 @@ +# TODO: add config stuff for bootloader here + diff --git a/components/bootloader/subproject/CMakeLists.txt b/components/bootloader/subproject/CMakeLists.txt new file mode 100644 index 0000000000..e8f920f2ed --- /dev/null +++ b/components/bootloader/subproject/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.5) +set(CMAKE_TOOLCHAIN_FILE $ENV{IDF_PATH}/toolchain.cmake) +project(idf_bootloader ASM C CXX) + +set(COMPONENTS bootloader esptool_py esp32 soc bootloader_support log spi_flash micro-ecc soc) + +set(BOOTLOADER_BUILD 1) +set(IS_BOOTLOADER_BUILD 1) # deprecated, use BOOTLOADER_BUILD +add_definitions(-DBOOTLOADER_BUILD=1) + +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) + +add_executable(bootloader.elf + main/bootloader_start.c + main/flash_qio_mode.c) + +target_link_libraries(bootloader.elf ${COMPONENT_LIBRARIES}) + +target_link_libraries(bootloader.elf "-L ${CMAKE_CURRENT_SOURCE_DIR}/main") +target_link_libraries(bootloader.elf "-T esp32.bootloader.ld") +target_link_libraries(bootloader.elf "-T esp32.bootloader.rom.ld") +target_link_libraries(bootloader.elf "${BOOTLOADER_LINKER_ARGS}") diff --git a/components/bootloader_support/CMakeLists.txt b/components/bootloader_support/CMakeLists.txt new file mode 100644 index 0000000000..f27310dfc2 --- /dev/null +++ b/components/bootloader_support/CMakeLists.txt @@ -0,0 +1,9 @@ +set(COMPONENT_SRCDIRS "src") + +if(${BOOTLOADER_BUILD}) + set(COMPONENT_ADD_INCLUDEDIRS "include include_priv") +else() + set(COMPONENT_PRIV_INCLUDEDIRS "include_priv") +endif() + +register_component() diff --git a/components/bootloader_support/include/esp_flash_encrypt.h b/components/bootloader_support/include/esp_flash_encrypt.h index ba370644a4..31b77a734f 100644 --- a/components/bootloader_support/include/esp_flash_encrypt.h +++ b/components/bootloader_support/include/esp_flash_encrypt.h @@ -17,7 +17,9 @@ #include #include "esp_attr.h" #include "esp_err.h" +#ifndef BOOTLOADER_BUILD #include "esp_spi_flash.h" +#endif #include "soc/efuse_reg.h" /** diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt new file mode 100644 index 0000000000..7410e19d06 --- /dev/null +++ b/components/bt/CMakeLists.txt @@ -0,0 +1,99 @@ +if(CONFIG_BT_ENABLED) + + set(COMPONENT_SRCDIRS .) + set(COMPONENT_ADD_INCLUDEDIRS include) + + target_link_libraries("-L ${CMAKE_CURRENT_LIST_DIR}/lib") + target_link_libraries(bt btdm_app) + + if(CONFIG_BLUEDROID_ENABLED) + + set(COMPONENT_ADD_INCLUDEDIRS ${COMPONENT_ADD_INCLUDEDIRS} + bluedroid/bta/include + bluedroid/bta/sys/include + bluedroid/btcore/include + bluedroid/device/include + bluedroid/gki/include + bluedroid/hci/include + bluedroid/osi/include + bluedroid/utils/include + bluedroid/external/sbc/decoder/include + bluedroid/btc/core/include + bluedroid/btc/profile/esp/blufi/include + bluedroid/btc/profile/esp/include + bluedroid/btc/profile/std/gatt/include + bluedroid/btc/profile/std/gap/include + bluedroid/btc/profile/std/a2dp/include + bluedroid/btc/profile/std/include + bluedroid/btc/include + bluedroid/btif/include + bluedroid/stack/btm/include + bluedroid/stack/btu/include + bluedroid/stack/gap/include + bluedroid/stack/gatt/include + bluedroid/stack/hcic/include + bluedroid/stack/l2cap/include + bluedroid/stack/sdp/include + bluedroid/stack/smp/include + bluedroid/stack/avct/include + bluedroid/stack/avrc/include + bluedroid/stack/avdt/include + bluedroid/stack/a2dp/include + bluedroid/stack/rfcomm/include + bluedroid/stack/include + bluedroid/utils/include + bluedroid/api/include + bluedroid/include) + + set(COMPONENT_SRCDIRS ${COMPONENT_SRCDIRS} + bluedroid/bta/dm + bluedroid/bta/gatt + bluedroid/bta/hh + bluedroid/bta/sdp + bluedroid/bta/av + bluedroid/bta/ar + bluedroid/bta/sys + bluedroid/bta/jv + bluedroid/bta + bluedroid/btcore + bluedroid/btif + bluedroid/device + bluedroid/gki + bluedroid/hci + bluedroid/main + bluedroid/osi + bluedroid/external/sbc/decoder/srce + bluedroid/btc/core + bluedroid/btc/profile/esp/blufi + bluedroid/btc/profile/std/gap + bluedroid/btc/profile/std/gatt + bluedroid/btc/profile/std/a2dp + bluedroid/btc/profile/std/avrc + bluedroid/btc/profile/std/spp + bluedroid/btc/profile + bluedroid/stack/btm + bluedroid/stack/btu + bluedroid/stack/gap + bluedroid/stack/gatt + bluedroid/stack/hcic + bluedroid/stack/include + bluedroid/stack/l2cap + bluedroid/stack/sdp + bluedroid/stack/smp + bluedroid/stack/avct + bluedroid/stack/avrc + bluedroid/stack/avdt + bluedroid/stack/a2dp + bluedroid/stack/rfcomm + bluedroid/stack + bluedroid/utils + bluedroid/api + bluedroid) + + endif(CONFIG_BLUEDROID_ENABLED) + + register_component() + +endif(CONFIG_BT_ENABLED) + + diff --git a/components/coap/CMakeLists.txt b/components/coap/CMakeLists.txt new file mode 100644 index 0000000000..9a9b65ccbb --- /dev/null +++ b/components/coap/CMakeLists.txt @@ -0,0 +1,33 @@ +set(COMPONENT_ADD_INCLUDEDIRS port/include port/include/coap libcoap/include libcoap/include/coap) + +set(COMPONENT_SRCS + libcoap/src/address.c + libcoap/src/async.c + libcoap/src/block.c + libcoap/src/coap_time.c + libcoap/src/debug.c + libcoap/src/encode.c + libcoap/src/hashkey.c + libcoap/src/mem.c + libcoap/src/net.c + libcoap/src/option.c + libcoap/src/pdu.c + libcoap/src/resource.c + libcoap/src/str.c + libcoap/src/subscribe.c + libcoap/src/uri.c + port/coap_io_socket.c + ) + +set(COMPONENT_SUBMODULES libcoap) + +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 +) + + diff --git a/components/console/CMakeLists.txt b/components/console/CMakeLists.txt new file mode 100644 index 0000000000..d1187256b4 --- /dev/null +++ b/components/console/CMakeLists.txt @@ -0,0 +1,3 @@ +set(COMPONENT_SRCDIRS linenoise argtable3 .) +register_component() + diff --git a/components/cxx/CMakeLists.txt b/components/cxx/CMakeLists.txt new file mode 100644 index 0000000000..bf51565c43 --- /dev/null +++ b/components/cxx/CMakeLists.txt @@ -0,0 +1,9 @@ +register_component() + +target_link_libraries(cxx stdc++) + +target_link_libraries(cxx "-u __cxa_guard_dummy") + +if(NOT CONFIG_CXX_EXCEPTIONS) + target_link_libraries(cxx "-u __cxx_fatal_exception") +endif() diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt new file mode 100644 index 0000000000..ca08498242 --- /dev/null +++ b/components/driver/CMakeLists.txt @@ -0,0 +1,3 @@ +set(COMPONENT_PRIV_INCLUDEDIRS include/driver) + +register_component() diff --git a/components/esp32/CMakeLists.txt b/components/esp32/CMakeLists.txt new file mode 100644 index 0000000000..9a9d4c7838 --- /dev/null +++ b/components/esp32/CMakeLists.txt @@ -0,0 +1,58 @@ +if(BOOTLOADER_BUILD) + # For bootloader, all we need from esp32 is headers + add_library(esp32 INTERFACE) + target_include_directories(esp32 INTERFACE include) + + # as cmake won't attach linker args to a header-only library, attach + # linker args directly to the bootloader.elf + set(BOOTLOADER_LINKER_ARGS "-L ${CMAKE_CURRENT_SOURCE_DIR}/ld -T esp32.rom.ld -Tesp32.rom.spiram_incompatible_fns.ld -T esp32.peripherals.ld" PARENT_SCOPE) + +else() + # Regular app build + + register_component() + + target_link_libraries(esp32 "-L ${CMAKE_CURRENT_SOURCE_DIR}/lib") + if(NOT CONFIG_NO_BLOBS) + target_link_libraries(esp32 coexist core espnow net80211 phy pp rtc smartconfig wpa2 wpa wps) + endif() + target_link_libraries(esp32 "-L ${CMAKE_CURRENT_SOURCE_DIR}/ld") + target_link_libraries(esp32 "-T ${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld") + target_link_libraries(esp32 "-T esp32.common.ld") + target_link_libraries(esp32 "-T esp32.rom.ld") + target_link_libraries(esp32 "-T esp32.peripherals.ld") + + if(CONFIG_SPIRAM_CACHE_WORKAROUND) + target_link_libraries(esp32 ${CMAKE_CURRENT_SOURCE_DIR}/libstdc++-psram-workaround.a) + else() + target_link_libraries(esp32 "-T esp32.rom.spiram_incompatible_fns.ld") + endif() + + if(CONFIG_NEWLIB_NANO_FORMAT) + target_link_libraries(esp32 "-T esp32.rom.nanofmt.ld") + endif() + + if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH) + target_link_libraries(esp32 "-T esp32.rom.spiflash.ld") + endif() + + target_link_libraries(esp32 "${CMAKE_CURRENT_SOURCE_DIR}/libhal.a") + target_link_libraries(esp32 gcc) + + #ld_include_panic_highint_hdl is added as an undefined symbol because otherwise the +#linker will ignore panic_highint_hdl.S as it has no other files depending on any +#symbols in it. + target_link_libraries(esp32 "-u ld_include_panic_highint_hdl") + + # Preprocess esp32.ld linker script to include configuration, becomes esp32_out.ld + set(LD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ld) + add_custom_command( + OUTPUT esp32_out.ld + COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o esp32_out.ld -I ${CMAKE_BINARY_DIR} ${LD_DIR}/esp32.ld + MAIN_DEPENDENCY ${LD_DIR}/esp32.ld + COMMENT "Generating linker script..." + VERBATIM) + add_custom_target(esp32_linker_script DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld) + add_dependencies(esp32 esp32_linker_script) + +endif() diff --git a/components/esp_adc_cal/CMakeLists.txt b/components/esp_adc_cal/CMakeLists.txt new file mode 100644 index 0000000000..339733b43d --- /dev/null +++ b/components/esp_adc_cal/CMakeLists.txt @@ -0,0 +1 @@ +register_component() diff --git a/components/esptool_py/CMakeLists.txt b/components/esptool_py/CMakeLists.txt new file mode 100644 index 0000000000..bdd55ceeac --- /dev/null +++ b/components/esptool_py/CMakeLists.txt @@ -0,0 +1 @@ +register_config_only_component() diff --git a/components/ethernet/CMakeLists.txt b/components/ethernet/CMakeLists.txt new file mode 100644 index 0000000000..4e20fbead0 --- /dev/null +++ b/components/ethernet/CMakeLists.txt @@ -0,0 +1,3 @@ +set(COMPONENT_SRCDIRS . eth_phy) + +register_component() diff --git a/components/expat/CMakeLists.txt b/components/expat/CMakeLists.txt new file mode 100644 index 0000000000..02445015c4 --- /dev/null +++ b/components/expat/CMakeLists.txt @@ -0,0 +1,14 @@ +set(COMPONENT_ADD_INCLUDEDIRS port/include include/expat) + +set(COMPONENT_SRCDIRS library port) + +register_component() + +target_compile_definitions(expat PRIVATE HAVE_EXPAT_CONFIG_H) + +# patch around warnings in third-party files +set_source_files_properties( + library/xmlparse.c + PROPERTIES COMPILE_FLAGS + -Wno-unused-function + ) diff --git a/components/fatfs/CMakeLists.txt b/components/fatfs/CMakeLists.txt new file mode 100644 index 0000000000..2f3a888268 --- /dev/null +++ b/components/fatfs/CMakeLists.txt @@ -0,0 +1,4 @@ +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 new file mode 100644 index 0000000000..1c6a9523b4 --- /dev/null +++ b/components/freertos/CMakeLists.txt @@ -0,0 +1,5 @@ +set(COMPONENT_ADD_INCLUDEDIRS include) +set(COMPONENT_PRIV_INCLUDEDIRS include/freertos) +register_component() + +target_link_libraries(freertos "-Wl,--undefined=uxTopUsedPriority") diff --git a/components/heap/CMakeLists.txt b/components/heap/CMakeLists.txt new file mode 100644 index 0000000000..015daa9b7a --- /dev/null +++ b/components/heap/CMakeLists.txt @@ -0,0 +1,17 @@ +set(COMPONENT_SRCS heap_caps_init.c heap_caps.c multi_heap.c heap_trace.c) + +if(NOT CONFIG_HEAP_POISONING_DISABLED) + set(COMPONENT_SRCS ${COMPONENT_SRCS} multi_heap_poisoning.c) +endif() + +register_component() + +if(CONFIG_HEAP_TRACING) + set(WRAP_FUNCTIONS + calloc malloc free realloc heap_caps_malloc heap_caps_free heap_caps_realloc) + + foreach(wrap ${WRAP_FUNCTIONS}) + target_link_libraries(heap "-Wl,--wrap=${wrap}") + endforeach() + +endif(CONFIG_HEAP_TRACING) diff --git a/components/idf_test/CMakeLists.txt b/components/idf_test/CMakeLists.txt new file mode 100644 index 0000000000..131acae4d5 --- /dev/null +++ b/components/idf_test/CMakeLists.txt @@ -0,0 +1,2 @@ +# idf_test will be registered as an INTERFACE library (ie header paths only) +register_component() diff --git a/components/jsmn/CMakeLists.txt b/components/jsmn/CMakeLists.txt new file mode 100644 index 0000000000..817f6e4beb --- /dev/null +++ b/components/jsmn/CMakeLists.txt @@ -0,0 +1,2 @@ +set(COMPONENT_SRCDIRS src) +register_component() diff --git a/components/json/CMakeLists.txt b/components/json/CMakeLists.txt new file mode 100644 index 0000000000..e3559b2690 --- /dev/null +++ b/components/json/CMakeLists.txt @@ -0,0 +1,4 @@ +set(COMPONENT_SRCDIRS library port) +set(COMPONENT_ADD_INCLUDEDIRS include port/include) + +register_component() diff --git a/components/libsodium/CMakeLists.txt b/components/libsodium/CMakeLists.txt new file mode 100644 index 0000000000..78ab23c646 --- /dev/null +++ b/components/libsodium/CMakeLists.txt @@ -0,0 +1,104 @@ +set(SRC libsodium/src/libsodium) + +set(COMPONENT_SUBMODULES libsodium) + +set(COMPONENT_SRCDIRS + port + + # Derived from libsodium/src/libsodium/Makefile.am + # (ignoring the !MINIMAL set) + ${SRC}/crypto_aead/chacha20poly1305/sodium + ${SRC}/crypto_aead/xchacha20poly1305/sodium + ${SRC}/crypto_auth + ${SRC}/crypto_auth/hmacsha256 + ${SRC}/crypto_auth/hmacsha512 + ${SRC}/crypto_auth/hmacsha512256 + ${SRC}/crypto_box + ${SRC}/crypto_box/curve25519xsalsa20poly1305 + ${SRC}/crypto_core/curve25519/ref10 + ${SRC}/crypto_core/hchacha20 + ${SRC}/crypto_core/hsalsa20/ref2 + ${SRC}/crypto_core/hsalsa20 + ${SRC}/crypto_core/salsa/ref + ${SRC}/crypto_generichash + ${SRC}/crypto_generichash/blake2b + ${SRC}/crypto_generichash/blake2b/ref + ${SRC}/crypto_hash + ${SRC}/crypto_hash/sha256 + ${SRC}/crypto_hash/sha512 + ${SRC}/crypto_kdf/blake2b + ${SRC}/crypto_kdf + ${SRC}/crypto_kx + ${SRC}/crypto_onetimeauth + ${SRC}/crypto_onetimeauth/poly1305 + ${SRC}/crypto_onetimeauth/poly1305/donna + ${SRC}/crypto_pwhash/argon2 + ${SRC}/crypto_pwhash + ${SRC}/crypto_pwhash/scryptsalsa208sha256 + ${SRC}/crypto_pwhash/scryptsalsa208sha256/nosse + ${SRC}/crypto_scalarmult + ${SRC}/crypto_scalarmult/curve25519 + ${SRC}/crypto_scalarmult/curve25519/ref10 + ${SRC}/crypto_secretbox + ${SRC}/crypto_secretbox/xsalsa20poly1305 + ${SRC}/crypto_shorthash + ${SRC}/crypto_shorthash/siphash24 + ${SRC}/crypto_shorthash/siphash24/ref + ${SRC}/crypto_sign + ${SRC}/crypto_sign/ed25519 + ${SRC}/crypto_sign/ed25519/ref10 + ${SRC}/crypto_stream/chacha20 + ${SRC}/crypto_stream/chacha20/ref + ${SRC}/crypto_stream + ${SRC}/crypto_stream/salsa20 + ${SRC}/crypto_stream/salsa20/ref + ${SRC}/crypto_stream/xsalsa20 + ${SRC}/crypto_verify/sodium + ${SRC}/randombytes + ${SRC}/sodium + ) + +if(CONFIG_LIBSODIUM_USE_MBEDTLS_SHA) + set(COMPONENT_SRCDIRS ${COMPONENT_SRCDIRS} + port/crypto_hash_mbedtls + ) +else() + set(COMPONENT_SRCDIRS ${COMPONENT_SRCDIRS} + ${SRC}/crypto_hash/sha256/cp + ${SRC}/crypto_hash/sha512/cp + ) +endif() + +set(COMPONENT_ADD_INCLUDEDIRS ${SRC}/include port_include) +set(COMPONENT_PRIV_INCLUDEDIRS ${SRC}/include/sodium port_include/sodium port) + +register_component() + +target_compile_definitions(libsodium PRIVATE + CONFIGURED + NATIVE_LITTLE_ENDIAN + HAVE_WEAK_SYMBOLS + __STDC_LIMIT_MACROS + __STDC_CONSTANT_MACROS +) + +target_compile_options(libsodium PRIVATE + -Wno-unknown-pragmas + ) + +# patch around warnings in third-party files +set_source_files_properties( + ${SRC}/crypto_pwhash/argon2/argon2-fill-block-ref.c + ${SRC}/crypto_pwhash/argon2/pwhash_argon2i.c + ${SRC}/crypto_pwhash/argon2/argon2-core.c + ${SRC}/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c + PROPERTIES COMPILE_FLAGS + -Wno-type-limits + ) +set_source_files_properties( + ${SRC}/sodium/utils.c + PROPERTIES COMPILE_FLAGS + -Wno-unused-variable + ) + + diff --git a/components/log/CMakeLists.txt b/components/log/CMakeLists.txt new file mode 100644 index 0000000000..339733b43d --- /dev/null +++ b/components/log/CMakeLists.txt @@ -0,0 +1 @@ +register_component() diff --git a/components/lwip/CMakeLists.txt b/components/lwip/CMakeLists.txt new file mode 100644 index 0000000000..1ffa69f47b --- /dev/null +++ b/components/lwip/CMakeLists.txt @@ -0,0 +1,37 @@ +set(COMPONENT_ADD_INCLUDEDIRS + include/lwip + include/lwip/port + include/lwip/posix + apps/ping + ) + +if(CONFIG_PPP_SUPPORT) +set(LWIP_PPP_DIRS netif/ppp/polarssl netif/ppp) +endif() + +set(COMPONENT_SRCDIRS + api + apps apps/sntp apps/ping + core core/ipv4 core/ipv6 + ${LWIP_PPP_DIRS} netif + port/freertos port/netif port/debug port) + +register_component() + +target_compile_options(lwip PRIVATE + -Wno-address +) + +# patch around warnings in third-party files +set_source_files_properties(api/tcpip.c + PROPERTIES COMPILE_FLAGS + -Wno-unused-variable + ) +set_source_files_properties(core/pbuf.c core/tcp_in.c + PROPERTIES COMPILE_FLAGS + -Wno-unused-but-set-variable + ) +set_source_files_properties(apps/dhcpserver.c + PROPERTIES COMPILE_FLAGS + "-Wno-unused-variable -Wno-unused-but-set-variable -Wno-type-limits" + ) diff --git a/components/mbedtls/CMakeLists.txt b/components/mbedtls/CMakeLists.txt new file mode 100644 index 0000000000..96ac14d123 --- /dev/null +++ b/components/mbedtls/CMakeLists.txt @@ -0,0 +1,8 @@ +set(COMPONENT_ADD_INCLUDEDIRS port/include include) +set(COMPONENT_SRCDIRS library port) + +register_component() + +target_compile_definitions(mbedtls PUBLIC + MBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" +) diff --git a/components/mdns/CMakeLists.txt b/components/mdns/CMakeLists.txt new file mode 100644 index 0000000000..0ba2e49dc3 --- /dev/null +++ b/components/mdns/CMakeLists.txt @@ -0,0 +1,2 @@ +register_component() + diff --git a/components/micro-ecc/CMakeLists.txt b/components/micro-ecc/CMakeLists.txt new file mode 100644 index 0000000000..6ae9c8ae39 --- /dev/null +++ b/components/micro-ecc/CMakeLists.txt @@ -0,0 +1,8 @@ +# only compile the micro-ecc/uECC.c source file +set(COMPONENT_SRCS micro-ecc/uECC.c) + +set(COMPONENT_ADD_INCLUDEDIRS micro-ecc) + +set(COMPONENT_SUBMODULES micro-ecc) + +register_component() diff --git a/components/newlib/CMakeLists.txt b/components/newlib/CMakeLists.txt new file mode 100644 index 0000000000..0fa454cba2 --- /dev/null +++ b/components/newlib/CMakeLists.txt @@ -0,0 +1,20 @@ +set(COMPONENT_ADD_INCLUDEDIRS platform_include include) + +if(CONFIG_SPIRAM_CACHE_WORKAROUND) + set(LIBC c-psram-workaround) + set(LIBM m-psram-workaround) +else() + + if(CONFIG_NEWLIB_NANO_FORMAT) + set(LIBC c_nano) + else() + set(LIBC c) + endif(CONFIG_NEWLIB_NANO_FORMAT) + + set(LIBM m) +endif(CONFIG_SPIRAM_CACHE_WORKAROUND) + +register_component() + +target_link_libraries(newlib "-L ${CMAKE_CURRENT_SOURCE_DIR}/lib") +target_link_libraries(newlib ${LIBC} ${LIBM}) diff --git a/components/nghttp/CMakeLists.txt b/components/nghttp/CMakeLists.txt new file mode 100644 index 0000000000..1a549b0751 --- /dev/null +++ b/components/nghttp/CMakeLists.txt @@ -0,0 +1,5 @@ +set(COMPONENT_ADD_INCLUDEDIRS port/include nghttp2/lib/includes) +set(COMPONENT_SRCDIRS nghttp2/lib port) +set(COMPONENT_SUBMODULES nghttp2) + +register_component() diff --git a/components/nvs_flash/CMakeLists.txt b/components/nvs_flash/CMakeLists.txt new file mode 100644 index 0000000000..7a9584c6d0 --- /dev/null +++ b/components/nvs_flash/CMakeLists.txt @@ -0,0 +1,4 @@ +set(COMPONENT_ADD_INCLUDEDIRS include) +set(COMPONENT_SRCDIRS src) + +register_component() diff --git a/components/openssl/CMakeLists.txt b/components/openssl/CMakeLists.txt new file mode 100644 index 0000000000..347ade6387 --- /dev/null +++ b/components/openssl/CMakeLists.txt @@ -0,0 +1,5 @@ +set(COMPONENT_ADD_INCLUDEDIRS include) +set(COMPONENT_PRIV_INCLUDEDIRS include/internal include/platform include/openssl) +set(COMPONENT_SRCDIRS library platform) + +register_component() diff --git a/components/partition_table/CMakeLists.txt b/components/partition_table/CMakeLists.txt new file mode 100644 index 0000000000..bdd55ceeac --- /dev/null +++ b/components/partition_table/CMakeLists.txt @@ -0,0 +1 @@ +register_config_only_component() diff --git a/components/pthread/CMakeLists.txt b/components/pthread/CMakeLists.txt new file mode 100644 index 0000000000..eebd20a046 --- /dev/null +++ b/components/pthread/CMakeLists.txt @@ -0,0 +1,3 @@ +set(COMPONENT_SRCDIRS ".") +set(COMPONENT_ADD_INCLUDEDIRS "include") +register_component() diff --git a/components/sdmmc/CMakeLists.txt b/components/sdmmc/CMakeLists.txt new file mode 100644 index 0000000000..339733b43d --- /dev/null +++ b/components/sdmmc/CMakeLists.txt @@ -0,0 +1 @@ +register_component() diff --git a/components/smartconfig/CMakeLists.txt b/components/smartconfig/CMakeLists.txt new file mode 100644 index 0000000000..ba2fa9c7e7 --- /dev/null +++ b/components/smartconfig/CMakeLists.txt @@ -0,0 +1,4 @@ +set(COMPONENT_SRCDIRS ".") +set(COMPONENT_ADD_INCLUDEDIRS "include") + +register_component() diff --git a/components/soc/CMakeLists.txt b/components/soc/CMakeLists.txt new file mode 100644 index 0000000000..24e8595514 --- /dev/null +++ b/components/soc/CMakeLists.txt @@ -0,0 +1,6 @@ +set(SOC_NAME esp32) + +set(COMPONENT_SRCDIRS ${SOC_NAME}) +set(COMPONENT_ADD_INCLUDEDIRS ${SOC_NAME}/include include) + +register_component() diff --git a/components/spi_flash/CMakeLists.txt b/components/spi_flash/CMakeLists.txt new file mode 100644 index 0000000000..2b2622261a --- /dev/null +++ b/components/spi_flash/CMakeLists.txt @@ -0,0 +1,11 @@ +if(BOOTLOADER_BUILD) + # Bootloader needs SPIUnlock from this file, but doesn't + # need other parts of this component + set(COMPONENT_SRCS spi_flash_rom_patch.c) +else() + set(COMPONENT_SRCDIRS .) +endif() + +set(COMPONENT_ADD_INCLUDEDIRS include) + +register_component() diff --git a/components/spiffs/CMakeLists.txt b/components/spiffs/CMakeLists.txt new file mode 100644 index 0000000000..0435a38b69 --- /dev/null +++ b/components/spiffs/CMakeLists.txt @@ -0,0 +1,6 @@ +set(COMPONENT_ADD_INCLUDEDIRS "include") +set(COMPONENT_PRIV_INCLUDEDIRS "spiffs/src") +set(COMPONENT_SRCDIRS ". spiffs/src") +set(COMPONENT_SUBMODULES "spiffs") +register_component() + diff --git a/components/tcpip_adapter/CMakeLists.txt b/components/tcpip_adapter/CMakeLists.txt new file mode 100644 index 0000000000..339733b43d --- /dev/null +++ b/components/tcpip_adapter/CMakeLists.txt @@ -0,0 +1 @@ +register_component() diff --git a/components/ulp/CMakeLists.txt b/components/ulp/CMakeLists.txt new file mode 100644 index 0000000000..339733b43d --- /dev/null +++ b/components/ulp/CMakeLists.txt @@ -0,0 +1 @@ +register_component() diff --git a/components/vfs/CMakeLists.txt b/components/vfs/CMakeLists.txt new file mode 100644 index 0000000000..339733b43d --- /dev/null +++ b/components/vfs/CMakeLists.txt @@ -0,0 +1 @@ +register_component() diff --git a/components/wear_levelling/CMakeLists.txt b/components/wear_levelling/CMakeLists.txt new file mode 100644 index 0000000000..f4f2f14ec3 --- /dev/null +++ b/components/wear_levelling/CMakeLists.txt @@ -0,0 +1,2 @@ +set(COMPONENT_PRIV_INCLUDEDIRS private_include) +register_component() diff --git a/components/wpa_supplicant/CMakeLists.txt b/components/wpa_supplicant/CMakeLists.txt new file mode 100644 index 0000000000..73c7294a66 --- /dev/null +++ b/components/wpa_supplicant/CMakeLists.txt @@ -0,0 +1,7 @@ +set(COMPONENT_ADD_INCLUDEDIRS include port/include) +set(COMPONENT_SRCDIRS src/crypto port src/fast_crypto) + +register_component() + +target_compile_definitions(wpa_supplicant PRIVATE __ets__) +target_compile_options(wpa_supplicant PRIVATE -Wno-strict-aliasing) diff --git a/components/xtensa-debug-module/CMakeLists.txt b/components/xtensa-debug-module/CMakeLists.txt new file mode 100644 index 0000000000..339733b43d --- /dev/null +++ b/components/xtensa-debug-module/CMakeLists.txt @@ -0,0 +1 @@ +register_component() diff --git a/examples/get-started/hello_world/CMakeLists.txt b/examples/get-started/hello_world/CMakeLists.txt new file mode 100644 index 0000000000..62a03947f6 --- /dev/null +++ b/examples/get-started/hello_world/CMakeLists.txt @@ -0,0 +1,12 @@ +# The following four lines of boilerplate have to be in your project's CMakeLists +# 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}/idf.cmake) + +add_executable(hello_world.elf + main/hello_world_main.c) + +target_link_libraries(hello_world.elf ${COMPONENT_LIBRARIES}) diff --git a/idf.cmake b/idf.cmake new file mode 100644 index 0000000000..8586d687a1 --- /dev/null +++ b/idf.cmake @@ -0,0 +1,78 @@ +# Designed to be included from an IDF app's CMakeLists.txt file +# +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 $ENV{IDF_PATH}) +if(NOT IDF_PATH) + # Documentation says you should set IDF_PATH in your environment, but we + # can infer it here if it's not set. + set(IDF_PATH ${CMAKE_CURRENT_LIST_DIR}) +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 +# +set(CMAKE_MODULE_PATH "${IDF_PATH}/tools/cmake" ${CMAKE_MODULE_PATH}) +include(GetGitRevisionDescription) +include(utilities) +include(components) +include(kconfig) + +# +# Configure optional variables +# +set_default(EXTRA_COMPONENT_DIRS "") + +# Note: "main" is no longer a component... +# +set_default(COMPONENT_DIRS "${PROJECT_PATH}/components ${EXTRA_COMPONENT_DIRS} ${IDF_PATH}/components") +spaces2list(COMPONENT_DIRS) + +# expand COMPONENT_DIRS variable into full paths to all components and their names +spaces2list(COMPONENTS) +find_all_components("${COMPONENT_DIRS}" "${COMPONENTS}" COMPONENT_PATHS COMPONENTS) +build_component_config() + +# Include sdkconfig.cmake so rest of the build knows the configuration +include(${SDKCONFIG_CMAKE}) + +# +# Add some idf-wide definitions +# +add_definitions(-DESP_PLATFORM) +add_definitions(-DHAVE_CONFIG_H) + +git_describe(GIT_REVISION) +add_definitions(-DIDF_VER=\"${GIT_REVISION}\") + +add_compile_options("-I${CMAKE_BINARY_DIR}") # for sdkconfig.h + +# +# Add components to the build +# +foreach(component ${COMPONENT_PATHS}) + get_filename_component(component_name ${component} NAME) + add_subdirectory(${component} ${component_name}) +endforeach() + +finish_component_registration() + +# Load the targets for the bootloader subproject +if(NOT BOOTLOADER_BUILD) + include(bootloader_subproject) +endif() diff --git a/toolchain.cmake b/toolchain.cmake new file mode 100644 index 0000000000..12e3f5a5a8 --- /dev/null +++ b/toolchain.cmake @@ -0,0 +1,11 @@ +set(CMAKE_SYSTEM_NAME Generic) + +set(CMAKE_C_COMPILER xtensa-esp32-elf-gcc) +set(CMAKE_CXX_COMPILER xtensa-esp32-elf-g++) +set(CMAKE_ASM_COMPILER xtensa-esp32-elf-gcc) + +set(CMAKE_C_FLAGS_INIT "-Og -ggdb -std=gnu99 -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-old-style-declaration") +set(CMAKE_CXX_FLAGS_INIT "-Og -ggdb -std=gnu++11 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare") +# TODO work out a better way to pass start-group... +# TODO put -Map arg somewhere more logical, make it depend on the app name +set(CMAKE_EXE_LINKER_FLAGS_INIT ${CMAKE_EXE_LINKER_FLAGS} "-nostdlib -Wl,--gc-sections -Wl,--cref -Wl,--Map=linker.map -Wl,--start-group" CACHE STRING "Linker Flags") diff --git a/tools/cmake/GetGitRevisionDescription.cmake b/tools/cmake/GetGitRevisionDescription.cmake new file mode 100644 index 0000000000..85eae1562f --- /dev/null +++ b/tools/cmake/GetGitRevisionDescription.cmake @@ -0,0 +1,130 @@ +# - Returns a version string from Git +# +# These functions force a re-configure on each git commit so that you can +# trust the values of the variables in your build system. +# +# get_git_head_revision( [ ...]) +# +# Returns the refspec and sha hash of the current head revision +# +# git_describe( [ ...]) +# +# Returns the results of git describe on the source tree, and adjusting +# the output so that it tests false if an error occurs. +# +# git_get_exact_tag( [ ...]) +# +# Returns the results of git describe --exact-match on the source tree, +# and adjusting the output so that it tests false if there was no exact +# matching tag. +# +# Requires CMake 2.6 or newer (uses the 'function' command) +# +# Original Author: +# 2009-2010 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2009-2010. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +if(__get_git_revision_description) + return() +endif() +set(__get_git_revision_description YES) + +# We must run the following at "include" time, not at function call time, +# to find the path to this module rather than the path to a calling list file +get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) + +function(get_git_head_revision _refspecvar _hashvar) + set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + set(GIT_DIR "${GIT_PARENT_DIR}/.git") + while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories + set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") + get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) + if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) + # We have reached the root directory, we are not in git + set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + return() + endif() + set(GIT_DIR "${GIT_PARENT_DIR}/.git") + endwhile() + # check if this is a submodule + if(NOT IS_DIRECTORY ${GIT_DIR}) + file(READ ${GIT_DIR} submodule) + string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule}) + get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH) + get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE) + endif() + set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") + if(NOT EXISTS "${GIT_DATA}") + file(MAKE_DIRECTORY "${GIT_DATA}") + endif() + + if(NOT EXISTS "${GIT_DIR}/HEAD") + return() + endif() + set(HEAD_FILE "${GIT_DATA}/HEAD") + configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) + + configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" + "${GIT_DATA}/grabRef.cmake" + @ONLY) + include("${GIT_DATA}/grabRef.cmake") + + set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) + set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE) +endfunction() + +function(git_describe _var) + if(NOT GIT_FOUND) + find_package(Git QUIET) + endif() + get_git_head_revision(refspec hash) + if(NOT GIT_FOUND) + set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) + return() + endif() + if(NOT hash) + set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) + return() + endif() + + # TODO sanitize + #if((${ARGN}" MATCHES "&&") OR + # (ARGN MATCHES "||") OR + # (ARGN MATCHES "\\;")) + # message("Please report the following error to the project!") + # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") + #endif() + + #message(STATUS "Arguments to execute_process: ${ARGN}") + + execute_process(COMMAND + "${GIT_EXECUTABLE}" + describe + ${hash} + ${ARGN} + WORKING_DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE + res + OUTPUT_VARIABLE + out + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT res EQUAL 0) + set(out "${out}-${res}-NOTFOUND") + endif() + + set(${_var} "${out}" PARENT_SCOPE) +endfunction() + +function(git_get_exact_tag _var) + git_describe(out --exact-match ${ARGN}) + set(${_var} "${out}" PARENT_SCOPE) +endfunction() diff --git a/tools/cmake/GetGitRevisionDescription.cmake.in b/tools/cmake/GetGitRevisionDescription.cmake.in new file mode 100644 index 0000000000..6d8b708efe --- /dev/null +++ b/tools/cmake/GetGitRevisionDescription.cmake.in @@ -0,0 +1,41 @@ +# +# Internal file for GetGitRevisionDescription.cmake +# +# Requires CMake 2.6 or newer (uses the 'function' command) +# +# Original Author: +# 2009-2010 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2009-2010. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +set(HEAD_HASH) + +file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024) + +string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS) +if(HEAD_CONTENTS MATCHES "ref") + # named branch + string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") + if(EXISTS "@GIT_DIR@/${HEAD_REF}") + configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) + else() + configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY) + file(READ "@GIT_DATA@/packed-refs" PACKED_REFS) + if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}") + set(HEAD_HASH "${CMAKE_MATCH_1}") + endif() + endif() +else() + # detached HEAD + configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY) +endif() + +if(NOT HEAD_HASH) + file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) + string(STRIP "${HEAD_HASH}" HEAD_HASH) +endif() diff --git a/tools/cmake/bootloader_subproject.cmake b/tools/cmake/bootloader_subproject.cmake new file mode 100644 index 0000000000..924a7ea77a --- /dev/null +++ b/tools/cmake/bootloader_subproject.cmake @@ -0,0 +1,13 @@ +# Glue to build the bootloader subproject binary as an external +# cmake project under this one +# +# +ExternalProject_Add(bootloader_subproject + # TODO: support overriding the bootloader in COMPONENT_PATHS + SOURCE_DIR ${IDF_PATH}/components/bootloader/subproject + BINARY_DIR ${CMAKE_BINARY_DIR}/bootloader_subproject + CMAKE_ARGS -DSDKCONFIG=${SDKCONFIG} -DIDF_PATH=${IDF_PATH} + INSTALL_COMMAND "" + ) + + diff --git a/tools/cmake/components.cmake b/tools/cmake/components.cmake new file mode 100644 index 0000000000..540caadf9b --- /dev/null +++ b/tools/cmake/components.cmake @@ -0,0 +1,133 @@ +# Search 'component_dirs' for components and return them +# as a list of names in 'component_names' and a list of full paths in +# 'component_paths' +# +# 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) + # component_dirs entries can be files or lists of files + set(paths "") + set(names "") + + # start by expanding the component_dirs list with all subdirectories + foreach(dir ${component_dirs}) + # Iterate any subdirectories for values + file(GLOB subdirs LIST_DIRECTORIES true "${dir}/*") + foreach(subdir ${subdirs}) + set(component_dirs "${component_dirs};${subdir}") + endforeach() + endforeach() + + # Look for a component in each component_dirs entry + foreach(dir ${component_dirs}) + file(GLOB component "${dir}/CMakeLists.txt") + if(component) + get_filename_component(component "${component}" DIRECTORY) + get_filename_component(name "${component}" NAME) + if(NOT filter_names OR (name IN_LIST filter_names)) + if(NOT name IN_LIST names) + set(names "${names};${name}") + set(paths "${paths};${component}") + endif() + endif() + + else() # no CMakeLists.txt file + # test for legacy component.mk and warn + file(GLOB legacy_component "${dir}/component.mk") + if(legacy_component) + get_filename_component(legacy_component "${legacy_component}" DIRECTORY) + message(WARNING "Component ${legacy_component} contains old-style component.mk but no CMakeLists.txt. Component will be skipped.") + endif() + endif(component) + + endforeach(dir ${component_dirs}) + + set(${component_paths} ${paths} PARENT_SCOPE) + set(${component_names} ${names} PARENT_SCOPE) +endfunction() + + +# Add a component to the build, using the COMPONENT variables defined +# in the parent +# +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 + 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") + if(matches) + list(SORT matches) + set(COMPONENT_SRCS "${COMPONENT_SRCS};${matches}") + endif(matches) + endforeach() + endif() + + # add public includes from other components when building this component + if(COMPONENT_SRCS) + add_library(${component} STATIC ${COMPONENT_SRCS}) + set(include_type PUBLIC) + else() + add_library(${component} INTERFACE) # header-only component + set(include_type INTERFACE) + endif(COMPONENT_SRCS) + + 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}) + endforeach() + + 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.") + endif() + get_filename_component(include_dir ${include_dir} ABSOLUTE BASE_DIR ${component_dir}) + target_include_directories(${component} PRIVATE ${include_dir}) + endforeach() + +endfunction() + +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() + +function(finish_component_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 + foreach(a ${COMPONENTS}) + if (TARGET ${a}) + get_target_property(a_type ${a} TYPE) + if (${a_type} STREQUAL STATIC_LIBRARY) + foreach(b ${COMPONENTS}) + if (TARGET ${b} AND NOT ${a} STREQUAL ${b}) + target_include_directories(${a} PRIVATE + $ + ) + endif() + endforeach(b) + endif(${a_type} STREQUAL STATIC_LIBRARY) + + set(COMPONENT_LIBRARIES "${COMPONENT_LIBRARIES};${a}") + endif() + endforeach() + + # set COMPONENT_LIBRARIES in top-level scope + set(COMPONENT_LIBRARIES "${COMPONENT_LIBRARIES}" PARENT_SCOPE) +endfunction() diff --git a/tools/cmake/kconfig.cmake b/tools/cmake/kconfig.cmake new file mode 100644 index 0000000000..2c7e68ede2 --- /dev/null +++ b/tools/cmake/kconfig.cmake @@ -0,0 +1,82 @@ +include(ExternalProject) + +add_compile_options("-I${CMAKE_BINARY_DIR}") + +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(ROOT_KCONFIG ${IDF_PATH}/Kconfig) + +# Use the existing Makefile to build mconf when needed +# +# TODO: replace this with something more Windows-friendly +ExternalProject_Add(mconf + SOURCE_DIR ${IDF_PATH}/tools/kconfig + CONFIGURE_COMMAND "" + BUILD_IN_SOURCE 1 + BUILD_COMMAND make mconf + BUILD_BYPRODUCTS ${MCONF} + INSTALL_COMMAND "" + EXCLUDE_FROM_ALL 1 + ) + +# Find all Kconfig files for all components +function(build_component_config) + file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/config") + set(kconfigs ) + set(kconfigs_projbuild ) + + # Find Kconfig and Kconfig.projbuild for each component as applicable + # if any of these change, cmake should rerun + foreach(dir ${COMPONENT_PATHS}) + file(GLOB kconfig "${dir}/Kconfig") + if(kconfig) + set(kconfigs "${kconfigs} ${kconfig}") + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${kconfig}) + endif() + file(GLOB kconfig ${dir}/Kconfig.projbuild) + if(kconfig) + set(kconfigs_projbuild "${kconfigs_projbuild} ${kconfig}") + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${kconfig}) + endif() + endforeach(dir ${COMPONENT_PATHS}) + + # Generate the menuconfig target (uses C-based mconf tool) + add_custom_target(menuconfig + DEPENDS mconf + COMMAND ${CMAKE_COMMAND} -E env + "COMPONENT_KCONFIGS=${kconfigs}" + "COMPONENT_KCONFIGS_PROJBUILD=${kconfigs_projbuild}" + "KCONFIG_CONFIG=${SDKCONFIG}" + ${IDF_PATH}/tools/kconfig/mconf ${ROOT_KCONFIG} + VERBATIM + USES_TERMINAL) + + # Generate configuration output via confgen.py + # makes sdkconfig.h and skdconfig.cmake + # + # This happens at cmake runtime not during the build + execute_process(COMMAND python ${IDF_PATH}/tools/kconfig_new/confgen.py + --kconfig ${ROOT_KCONFIG} + --config ${SDKCONFIG} + --env "COMPONENT_KCONFIGS=${kconfigs}" + --env "COMPONENT_KCONFIGS_PROJBUILD=${kconfigs_projbuild}" + --output header ${SDKCONFIG_HEADER} + --output cmake ${SDKCONFIG_CMAKE}) + + # When sdkconfig file changes in the future, trigger a cmake run + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${SDKCONFIG}) + + # Ditto if either of the generated files are missing/modified (this is a bit irritating as it means + # you can't edit these manually without them being regenerated, but I don't know of a better way...) + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${SDKCONFIG_HEADER}) + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${SDKCONFIG_CMAKE}) + + # Or if the config generation tool changes + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${IDF_PATH}/tools/kconfig_new/confgen.py) + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${IDF_PATH}/tools/kconfig_new/kconfiglib.py) + +endfunction() diff --git a/tools/cmake/utilities.cmake b/tools/cmake/utilities.cmake new file mode 100644 index 0000000000..29eb78aad0 --- /dev/null +++ b/tools/cmake/utilities.cmake @@ -0,0 +1,60 @@ +# set_default +# +# Define a variable to a default value if otherwise unset. +# +# Priority for new value is: +# - Existing cmake value (ie set with cmake -D, or already set in CMakeLists) +# - Value of any non-empty environment variable of the same name +# - Default value as provided to function +# +function(set_default variable default_value) + if(NOT ${variable}) + if($ENV{${variable}}) + set(${variable} $ENV{${variable}} PARENT_SCOPE) + else() + set(${variable} ${default_value} PARENT_SCOPE) + endif() + endif() +endfunction() + +# spaces2list +# +# Take a variable whose value was space-delimited values, convert to a cmake +# list (semicolon-delimited) +# +# Note: if using this for directories, keeps the issue in place that +# directories can't contain spaces... +function(spaces2list variable_name) + string(REPLACE " " ";" tmp "${${variable_name}}") + set("${variable_name}" "${tmp}" PARENT_SCOPE) +endfunction() + +# move_if_different +# +# If 'source' has different md5sum to 'destination' (or destination +# does not exist, move it across. +# +# If 'source' has the same md5sum as 'destination', delete 'source'. +# +# Avoids timestamp updates for re-generated files where content hasn't +# changed. +function(move_if_different source destination) + set(do_copy 1) + file(GLOB dest_exists ${destination}) + if(dest_exists) + file(MD5 ${source} source_md5) + file(MD5 ${destination} dest_md5) + if(source_md5 STREQUAL dest_md5) + set(do_copy "") + endif() + endif() + + if(do_copy) + message("Moving ${source} -> ${destination}") + file(RENAME ${source} ${destination}) + else() + message("Not moving ${source} -> ${destination}") + file(REMOVE ${source}) + endif() + +endfunction() -- 2.40.0