mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
cmake: Use cmake_lint project, tidy up all CMake source files
This commit is contained in:
parent
15d5e88618
commit
88df8fd293
@ -32,3 +32,8 @@ insert_final_newline = false
|
||||
|
||||
[*.py]
|
||||
max_line_length = 119
|
||||
|
||||
[{*.cmake,CMakeLists.txt}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
max_line_length = 120
|
||||
|
@ -1,8 +1,8 @@
|
||||
if(CONFIG_AWS_IOT_SDK)
|
||||
if(NOT CONFIG_AWS_IOT_SDK)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(COMPONENT_ADD_INCLUDEDIRS "include aws-iot-device-sdk-embedded-C/include")
|
||||
set(COMPONENT_SRCDIRS "aws-iot-device-sdk-embedded-C/src port")
|
||||
|
||||
register_component()
|
||||
|
||||
endif(CONFIG_AWS_IOT_SDK)
|
||||
|
@ -13,7 +13,7 @@ set(bootloader_binary_files
|
||||
"${bootloader_build_dir}/bootloader.map"
|
||||
)
|
||||
|
||||
ExternalProject_Add(bootloader
|
||||
externalproject_add(bootloader
|
||||
# TODO: support overriding the bootloader in COMPONENT_PATHS
|
||||
SOURCE_DIR "${IDF_PATH}/components/bootloader/subproject"
|
||||
BINARY_DIR "${bootloader_build_dir}"
|
||||
@ -28,4 +28,6 @@ ExternalProject_Add(bootloader
|
||||
# see thread: https://cmake.org/pipermail/cmake/2016-December/064660.html
|
||||
#
|
||||
# So for now we just have the top-level build remove the final build products...
|
||||
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${bootloader_binary_files})
|
||||
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
|
||||
ADDITIONAL_MAKE_CLEAN_FILES
|
||||
${bootloader_binary_files})
|
||||
|
@ -1,7 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
if(NOT SDKCONFIG)
|
||||
message(FATAL_ERROR "Bootloader subproject expects the SDKCONFIG variable to be passed in by the parent build process.")
|
||||
message(FATAL_ERROR "Bootloader subproject expects the SDKCONFIG variable to be passed "
|
||||
"in by the parent build process.")
|
||||
endif()
|
||||
|
||||
set(COMPONENTS bootloader esptool_py esp32 soc bootloader_support log spi_flash micro-ecc soc)
|
||||
@ -18,4 +19,3 @@ 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}")
|
||||
target_link_libraries(bootloader.elf gcc)
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
if(CONFIG_BT_ENABLED)
|
||||
if(NOT CONFIG_BT_ENABLED)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(COMPONENT_SRCDIRS .)
|
||||
set(COMPONENT_ADD_INCLUDEDIRS include)
|
||||
@ -90,10 +92,6 @@ if(CONFIG_BT_ENABLED)
|
||||
bluedroid/api
|
||||
bluedroid)
|
||||
|
||||
endif(CONFIG_BLUEDROID_ENABLED)
|
||||
endif()
|
||||
|
||||
register_component()
|
||||
|
||||
endif(CONFIG_BT_ENABLED)
|
||||
|
||||
|
||||
|
@ -24,8 +24,5 @@ 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(coap PUBLIC WITH_POSIX)
|
||||
|
||||
|
@ -5,7 +5,12 @@ if(BOOTLOADER_BUILD)
|
||||
|
||||
# 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)
|
||||
set(BOOTLOADER_LINKER_ARGS
|
||||
"-L ${CMAKE_CURRENT_SOURCE_DIR}/ld"
|
||||
"-T esp32.rom.ld"
|
||||
"-T esp32.rom.spiram_incompatible_fns.ld"
|
||||
"-T esp32.peripherals.ld"
|
||||
PARENT_SCOPE)
|
||||
|
||||
else()
|
||||
# Regular app build
|
||||
@ -62,16 +67,20 @@ else()
|
||||
if(CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION)
|
||||
set(PHY_INIT_DATA_BIN phy_init_data.bin)
|
||||
|
||||
# To get the phy_init_data.bin file, compile phy_init_data.h as a C file and then objcopy the object file to a raw binary
|
||||
# To get the phy_init_data.bin file, compile phy_init_data.h as a C file and then objcopy
|
||||
# the object file to a raw binary
|
||||
add_custom_command(
|
||||
OUTPUT ${PHY_INIT_DATA_BIN}
|
||||
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/phy_init_data.h
|
||||
COMMAND ${CMAKE_C_COMPILER} -x c -c -o phy_init_data.obj -I ${CMAKE_CURRENT_LIST_DIR} -I ${CMAKE_CURRENT_LIST_DIR}/include -I ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/phy_init_data.h
|
||||
COMMAND ${CMAKE_C_COMPILER} -x c -c
|
||||
-I ${CMAKE_CURRENT_LIST_DIR} -I ${CMAKE_CURRENT_LIST_DIR}/include -I ${CMAKE_BINARY_DIR}
|
||||
-o phy_init_data.obj
|
||||
${CMAKE_CURRENT_LIST_DIR}/phy_init_data.h
|
||||
COMMAND ${CMAKE_OBJCOPY} -O binary phy_init_data.obj ${PHY_INIT_DATA_BIN}
|
||||
)
|
||||
add_custom_target(phy_init_data ALL DEPENDS ${PHY_INIT_DATA_BIN})
|
||||
add_dependencies(flash phy_init_data)
|
||||
|
||||
endif(CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION)
|
||||
endif()
|
||||
|
||||
endif(BOOTLOADER_BUILD)
|
||||
endif()
|
||||
|
@ -10,7 +10,11 @@ set(ESPFLASHSIZE ${CONFIG_ESPTOOLPY_FLASHSIZE})
|
||||
|
||||
set(ESPTOOLPY_SERIAL "${ESPTOOLPY}" --port "${ESPPORT}" --baud ${ESPBAUD})
|
||||
|
||||
set(ESPTOOLPY_ELF2IMAGE_FLASH_OPTIONS --flash_mode ${ESPFLASHMODE} --flash_freq ${ESPFLASHFREQ} --flash_size ${ESPFLASHSIZE})
|
||||
set(ESPTOOLPY_ELF2IMAGE_FLASH_OPTIONS
|
||||
--flash_mode ${ESPFLASHMODE}
|
||||
--flash_freq ${ESPFLASHFREQ}
|
||||
--flash_size ${ESPFLASHSIZE}
|
||||
)
|
||||
|
||||
if(CONFIG_ESPTOOLPY_FLASHSIZE_DETECT)
|
||||
# Set ESPFLASHSIZE to 'detect' *after* elf2image options are generated,
|
||||
@ -39,7 +43,8 @@ add_custom_target(app ALL DEPENDS "${PROJECT_NAME}.bin")
|
||||
#
|
||||
function(esptool_py_custom_target target_name flasher_filename dependencies)
|
||||
add_custom_target(${target_name} DEPENDS ${dependencies}
|
||||
COMMAND ${ESPTOOLPY} -p ${CONFIG_ESPTOOLPY_PORT} -b ${CONFIG_ESPTOOLPY_BAUD} write_flash @flash_${flasher_filename}_args
|
||||
COMMAND ${ESPTOOLPY} -p ${CONFIG_ESPTOOLPY_PORT} -b ${CONFIG_ESPTOOLPY_BAUD}
|
||||
write_flash @flash_${flasher_filename}_args
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
)
|
||||
endfunction()
|
||||
|
@ -16,4 +16,4 @@ if(CONFIG_HEAP_TRACING)
|
||||
target_link_libraries(heap "-Wl,--wrap=${wrap}")
|
||||
endforeach()
|
||||
|
||||
endif(CONFIG_HEAP_TRACING)
|
||||
endif()
|
||||
|
@ -96,5 +96,3 @@ set_source_files_properties(
|
||||
PROPERTIES COMPILE_FLAGS
|
||||
-Wno-unused-variable
|
||||
)
|
||||
|
||||
|
||||
|
@ -10,10 +10,10 @@ else()
|
||||
set(LIBC c_nano)
|
||||
else()
|
||||
set(LIBC c)
|
||||
endif(CONFIG_NEWLIB_NANO_FORMAT)
|
||||
endif()
|
||||
|
||||
set(LIBM m)
|
||||
endif(CONFIG_SPIRAM_CACHE_WORKAROUND)
|
||||
endif()
|
||||
|
||||
register_component()
|
||||
|
||||
|
@ -36,10 +36,13 @@ add_custom_command(OUTPUT "${unsigned_partition_bin}"
|
||||
|
||||
# Add signing steps
|
||||
if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
|
||||
get_filename_component(secure_boot_signing_key "${CONFIG_SECURE_BOOT_SIGNING_KEY}" ABSOLUTE BASE_DIR "${PROJECT_PATH}")
|
||||
get_filename_component(secure_boot_signing_key
|
||||
"${CONFIG_SECURE_BOOT_SIGNING_KEY}"
|
||||
ABSOLUTE BASE_DIR "${PROJECT_PATH}")
|
||||
|
||||
add_custom_command(OUTPUT "${final_partition_bin}"
|
||||
COMMAND "${PYTHON}" "${ESPSECUREPY}" sign_data --keyfile "${secure_boot_signing_key}" -o "${final_partition_bin}" "${unsigned_partition_bin}"
|
||||
COMMAND "${PYTHON}" "${ESPSECUREPY}" sign_data --keyfile "${secure_boot_signing_key}"
|
||||
-o "${final_partition_bin}" "${unsigned_partition_bin}"
|
||||
DEPENDS "${unsigned_partition_bin}"
|
||||
VERBATIM)
|
||||
|
||||
@ -47,7 +50,10 @@ endif()
|
||||
|
||||
add_custom_target(partition_table ALL DEPENDS "${final_partition_bin}")
|
||||
|
||||
# Use global properties ESPTOOL_WRITE_FLASH_ARGS to pass this info to build hte list of esptool write arguments for flashing
|
||||
set_property(GLOBAL APPEND_STRING PROPERTY ESPTOOL_WRITE_FLASH_ARGS "${partition_table_offset} ${final_partition_bin} ")
|
||||
# Use global properties ESPTOOL_WRITE_FLASH_ARGS to pass this info to build
|
||||
# the list of esptool write arguments for flashing
|
||||
set_property(GLOBAL APPEND_STRING PROPERTY
|
||||
ESPTOOL_WRITE_FLASH_ARGS
|
||||
"${partition_table_offset} ${final_partition_bin} ")
|
||||
|
||||
register_config_only_component()
|
||||
|
@ -564,7 +564,7 @@ the esp-idf build system entirely by using a CMake feature called ExternalProjec
|
||||
|
||||
# External build process for quirc, runs in source dir and
|
||||
# produces libquirc.a
|
||||
ExternalProject_Add(quirc_build
|
||||
externalproject_add(quirc_build
|
||||
PREFIX ${COMPONENT_PATH}
|
||||
SOURCE_DIR ${COMPONENT_PATH}/quirc
|
||||
CONFIGURE_COMMAND ""
|
||||
@ -588,10 +588,10 @@ the esp-idf build system entirely by using a CMake feature called ExternalProjec
|
||||
|
||||
(The above CMakeLists.txt can be used to create a component named ``quirc`` that builds the quirc_ project using its own Makefile.)
|
||||
|
||||
- ExternalProject_Add defines an external build system.
|
||||
- ``externalproject_add`` defines an external build system.
|
||||
- ``SOURCE_DIR``, ``CONFIGURE_COMMAND``, ``BUILD_COMMAND`` and ``INSTALL_COMMAND`` should always be set. ``CONFIGURE_COMMAND`` can be set to an empty string if the build system has no "configure" step. ``INSTALL_COMMAND`` will generally be empty for ESP-IDF builds.
|
||||
- Setting ``BUILD_IN_SOURCE`` means the build directory is the same as the source directory. Otherwise you can set ``BUILD_DIR``.
|
||||
- Consult the ExternalProject_ documentation for more details about ``ExternalProject_Add()``
|
||||
- Consult the ExternalProject_ documentation for more details about ``externalproject_add()``
|
||||
|
||||
- The second set of commands adds a library target, which points to the "imported" library file built by the external system. Some properties need to be set in order to add include directories and tell CMake where this file is.
|
||||
- Finally, the generated library is added to `ADDITIONAL_MAKE_CLEAN_FILES`_. This means ``make clean`` will delete this library. (Note that the other object files from the build won't be deleted.)
|
||||
@ -606,8 +606,8 @@ CMake has some unusual behaviour around external project builds:
|
||||
- `ADDITIONAL_MAKE_CLEAN_FILES`_ only works when "make" is used as the build system. If Ninja_ or an IDE build system is used, it won't delete these files when cleaning.
|
||||
- However, the ExternalProject_ configure & build commands will *always* be re-run after a clean is run.
|
||||
- Therefore, there are two alternative recommended ways to configure the external build command:
|
||||
1. Have the external ``BUILD_COMMAND`` run a full clean compile of all sources. The build command will be run if any of the dependencies passed to ``ExternalProject_Add`` with ``DEPENDS`` have changed, or if this is a clean build (ie any of ``idf.py clean``, ``ninja clean``, or ``make clean`` was run.)
|
||||
2. Have the external ``BUILD_COMMAND`` be an incremental build command. Pass the parameter ``BUILD_ALWAYS 1`` to ``ExternalProject_Add``. This means the external project will be built each time a build is run, regardless of dependencies. This is only recommended if the external project has correct incremental build behaviour, and doesn't take too long to run.
|
||||
1. Have the external ``BUILD_COMMAND`` run a full clean compile of all sources. The build command will be run if any of the dependencies passed to ``externalproject_add`` with ``DEPENDS`` have changed, or if this is a clean build (ie any of ``idf.py clean``, ``ninja clean``, or ``make clean`` was run.)
|
||||
2. Have the external ``BUILD_COMMAND`` be an incremental build command. Pass the parameter ``BUILD_ALWAYS 1`` to ``externalproject_add``. This means the external project will be built each time a build is run, regardless of dependencies. This is only recommended if the external project has correct incremental build behaviour, and doesn't take too long to run.
|
||||
|
||||
The best of these approaches for building an external project will depend on the project itself, its build system, and whether you anticipate needing to frequently recompile the project.
|
||||
|
||||
|
@ -170,6 +170,19 @@ To re-format a file, run::
|
||||
tools/format.sh components/my_component/file.c
|
||||
|
||||
|
||||
CMake Code Style
|
||||
----------------
|
||||
|
||||
- Indent with four spaces.
|
||||
- Maximum line length 120 characters. When splitting lines, try to
|
||||
focus on readability where possible (for example, by pairing up
|
||||
keyword/argument pairs on individual lines).
|
||||
- Don't put anything in the optional parentheses after ``endforeach()``, ``endif()``, etc.
|
||||
- Use lowercase (``with_underscores``) for command, function, and macro names.
|
||||
- For locally scoped variables, use lowercase (``with_underscores``).
|
||||
- For globally scoped variables, use uppercase (``WITH_UNDERSCORES``).
|
||||
- Otherwise follow the defaults of the cmake-lint_ project.
|
||||
|
||||
Configuring the code style for a project using EditorConfig
|
||||
-----------------------------------------------------------
|
||||
|
||||
@ -194,4 +207,3 @@ Language features
|
||||
To be written.
|
||||
|
||||
.. _cmake-lint: https://github.com/richq/cmake-lint
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
# The following five lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
# The following five 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(MAIN_SRCS main/hello_world_main.c)
|
||||
|
@ -36,15 +36,16 @@ function(components_find_all component_dirs filter_names component_paths compone
|
||||
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.")
|
||||
message(WARNING "Component ${legacy_component} contains old-style component.mk but no CMakeLists.txt. "
|
||||
"Component will be skipped.")
|
||||
endif()
|
||||
endif()
|
||||
endif(component)
|
||||
|
||||
endforeach(dir ${component_dirs})
|
||||
endforeach()
|
||||
|
||||
set(${component_paths} ${paths} PARENT_SCOPE)
|
||||
set(${component_names} ${names} PARENT_SCOPE)
|
||||
endfunction(components_find_all)
|
||||
endfunction()
|
||||
|
||||
|
||||
# Add a component to the build, using the COMPONENT variables defined
|
||||
@ -70,8 +71,8 @@ function(register_component)
|
||||
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)
|
||||
message(FATAL_ERROR "${CMAKE_CURRENT_LIST_FILE}: COMPONENT_SRCDIRS entry '${dir}' has no source files")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
@ -100,7 +101,8 @@ function(register_component)
|
||||
foreach(include_dir ${COMPONENT_ADD_INCLUDEDIRS})
|
||||
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")
|
||||
message(FATAL_ERROR "${CMAKE_CURRENT_LIST_FILE}: "
|
||||
"COMPONENT_ADD_INCLUDEDIRS entry '${include_dir}' not found")
|
||||
endif()
|
||||
target_include_directories(${component} ${include_type} ${abs_dir})
|
||||
endforeach()
|
||||
@ -108,24 +110,26 @@ function(register_component)
|
||||
# add private includes
|
||||
foreach(include_dir ${COMPONENT_PRIV_INCLUDEDIRS})
|
||||
if(${include_type} STREQUAL INTERFACE)
|
||||
message(FATAL_ERROR "${CMAKE_CURRENT_LIST_FILE} sets no component source files but sets COMPONENT_PRIV_INCLUDEDIRS")
|
||||
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")
|
||||
message(FATAL_ERROR "${CMAKE_CURRENT_LIST_FILE}: "
|
||||
"COMPONENT_PRIV_INCLUDEDIRS entry '${include_dir}' does not exist")
|
||||
endif()
|
||||
target_include_directories(${component} PRIVATE ${abs_dir})
|
||||
endforeach()
|
||||
|
||||
endfunction(register_component)
|
||||
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(register_config_only_component)
|
||||
endfunction()
|
||||
|
||||
function(components_finish_registration)
|
||||
# each component should see the include directories of each other
|
||||
@ -148,8 +152,8 @@ function(components_finish_registration)
|
||||
$<TARGET_PROPERTY:${b},INTERFACE_COMPILE_OPTIONS>)
|
||||
endif()
|
||||
endforeach(b)
|
||||
endif(${a_type} STREQUAL STATIC_LIBRARY OR ${a_type} STREQUAL EXECUTABLE)
|
||||
endif(NOT a_imported)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(${a_type} MATCHES .+_LIBRARY)
|
||||
set(COMPONENT_LIBRARIES "${COMPONENT_LIBRARIES};${a}")
|
||||
@ -171,4 +175,4 @@ function(components_finish_registration)
|
||||
|
||||
message(STATUS "Component libraries: ${COMPONENT_LIBRARIES}")
|
||||
|
||||
endfunction(components_finish_registration)
|
||||
endfunction()
|
||||
|
@ -5,7 +5,8 @@ set(ctng_version_warning "Check Getting Started documentation or proceed at own
|
||||
|
||||
function(gcc_version_check expected_gcc_version)
|
||||
if(NOT "${CMAKE_C_COMPILER_VERSION}" STREQUAL "${expected_gcc_version}")
|
||||
message(WARNING "Xtensa toolchain ${CMAKE_C_COMPILER} version ${CMAKE_C_COMPILER_VERSION} is not the supported version ${expected_gcc_version}. ${ctng_version_warning}")
|
||||
message(WARNING "Xtensa toolchain ${CMAKE_C_COMPILER} version ${CMAKE_C_COMPILER_VERSION} "
|
||||
"is not the supported version ${expected_gcc_version}. ${ctng_version_warning}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
@ -1,12 +1,14 @@
|
||||
find_package(Git)
|
||||
|
||||
if(NOT GIT_FOUND)
|
||||
message(WARNING "Git executable was not found. Git submodule checks will not be executed. If you have any build issues at all, start by adding git executable to the PATH and rerun cmake to not see this warning again.")
|
||||
message(WARNING "Git executable was not found. Git submodule checks will not be executed. "
|
||||
"If you have any build issues at all, start by adding git executable to the PATH and "
|
||||
"rerun cmake to not see this warning again.")
|
||||
|
||||
function(git_submodule_check root_path)
|
||||
# no-op
|
||||
endfunction()
|
||||
else(NOT GIT_FOUND)
|
||||
else()
|
||||
|
||||
function(git_submodule_check root_path)
|
||||
|
||||
@ -36,26 +38,24 @@ else(NOT GIT_FOUND)
|
||||
)
|
||||
if(git_result)
|
||||
message(FATAL_ERROR "Git submodule init failed for ${submodule_path}")
|
||||
endif(git_result)
|
||||
endif()
|
||||
|
||||
elseif(NOT "${status}" STREQUAL " ")
|
||||
message(WARNING "Git submodule ${submodule_path} is out of date. Run 'git submodule update --init --recursive' to fix.")
|
||||
message(WARNING "Git submodule ${submodule_path} is out of date. "
|
||||
"Run 'git submodule update --init --recursive' to fix.")
|
||||
endif()
|
||||
|
||||
# Force a re-run of cmake if the submodule's .git file changes or is changed (ie accidental deinit)
|
||||
get_filename_component(submodule_abs_path ${submodule_path} ABSOLUTE BASE_DIR ${root_path})
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${submodule_abs_path}/.git)
|
||||
# same if the HEAD file in the submodule's directory changes (ie commit changes). This will at least prit the 'out of date' warning
|
||||
# same if the HEAD file in the submodule's directory changes (ie commit changes).
|
||||
# This will at least print the 'out of date' warning
|
||||
set(submodule_head "${root_path}/.git/modules/${submodule_path}/HEAD")
|
||||
if(EXISTS "${submodule_head}")
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${submodule_head})
|
||||
endif()
|
||||
|
||||
endforeach()
|
||||
endfunction(git_submodule_check)
|
||||
|
||||
endif(NOT GIT_FOUND)
|
||||
|
||||
|
||||
|
||||
endfunction()
|
||||
|
||||
endif()
|
||||
|
@ -62,8 +62,19 @@ function(idf_set_global_compiler_options)
|
||||
add_compile_options(-ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib)
|
||||
|
||||
# Default warnings configuration
|
||||
add_compile_options(-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)
|
||||
add_c_compile_options(-Wno-old-style-declaration)
|
||||
add_compile_options(
|
||||
-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)
|
||||
add_c_compile_options(
|
||||
-Wno-old-style-declaration
|
||||
)
|
||||
|
||||
# Stack protection
|
||||
if(NOT BOOTLOADER_BUILD)
|
||||
@ -93,7 +104,7 @@ function(idf_set_global_compiler_options)
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
|
||||
endif()
|
||||
|
||||
endfunction(idf_set_global_compiler_options)
|
||||
endfunction()
|
||||
|
||||
|
||||
# Verify the IDF environment is configured correctly (environment, toolchain, etc)
|
||||
@ -129,10 +140,7 @@ function(idf_add_executable)
|
||||
add_executable(${exe_target} "${MAIN_SRCS}")
|
||||
|
||||
add_map_file(${exe_target})
|
||||
|
||||
add_flasher_argfile(${exe_target})
|
||||
|
||||
endfunction(idf_add_executable)
|
||||
endfunction()
|
||||
|
||||
|
||||
# add_map_file
|
||||
@ -142,7 +150,9 @@ function(add_map_file exe_target)
|
||||
get_filename_component(basename ${exe_target} NAME_WE)
|
||||
set(mapfile "${basename}.map")
|
||||
target_link_libraries(${exe_target} "-Wl,--gc-sections -Wl,--cref -Wl,--Map=${mapfile} -Wl,--start-group")
|
||||
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/${mapfile}")
|
||||
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
|
||||
ADDITIONAL_MAKE_CLEAN_FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${mapfile}")
|
||||
|
||||
# add size targets, depend on map file, run idf_size.py
|
||||
add_custom_target(size
|
||||
@ -158,14 +168,7 @@ function(add_map_file exe_target)
|
||||
COMMAND ${PYTHON} ${IDF_PATH}/tools/idf_size.py --archives ${mapfile}
|
||||
)
|
||||
|
||||
endfunction(add_map_file)
|
||||
|
||||
# add_flasher_argfile
|
||||
#
|
||||
# Add argument file(s) for flashing the app, and for flashing the whole system
|
||||
function(add_flasher_argfile)
|
||||
|
||||
endfunction(add_flasher_argfile)
|
||||
endfunction()
|
||||
|
||||
# component_compile_options
|
||||
#
|
||||
|
@ -16,7 +16,7 @@ endmacro()
|
||||
# Use the existing Makefile to build mconf (out of tree) when needed
|
||||
#
|
||||
# TODO: Download(?) a prebuilt mingw mconf on Windows
|
||||
ExternalProject_Add(mconf
|
||||
externalproject_add(mconf
|
||||
SOURCE_DIR ${IDF_PATH}/tools/kconfig
|
||||
CONFIGURE_COMMAND ""
|
||||
BINARY_DIR "kconfig_bin"
|
||||
@ -46,7 +46,7 @@ function(kconfig_process_config)
|
||||
set(kconfigs_projbuild "${kconfigs_projbuild} ${kconfig}")
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${kconfig})
|
||||
endif()
|
||||
endforeach(dir ${COMPONENT_PATHS})
|
||||
endforeach()
|
||||
|
||||
if(EXISTS ${SDKCONFIG_DEFAULTS})
|
||||
set(defaults_arg --defaults "${SDKCONFIG_DEFAULTS}")
|
||||
@ -64,7 +64,8 @@ function(kconfig_process_config)
|
||||
# Generate the menuconfig target (uses C-based mconf tool)
|
||||
add_custom_target(menuconfig
|
||||
DEPENDS mconf
|
||||
COMMAND ${confgen_basecommand} --output config ${SDKCONFIG} # create any missing config file, with defaults if necessary
|
||||
# create any missing config file, with defaults if necessary
|
||||
COMMAND ${confgen_basecommand} --output config ${SDKCONFIG}
|
||||
COMMAND ${CMAKE_COMMAND} -E env
|
||||
"COMPONENT_KCONFIGS=${kconfigs}"
|
||||
"COMPONENT_KCONFIGS_PROJBUILD=${kconfigs_projbuild}"
|
||||
@ -98,6 +99,8 @@ function(kconfig_process_config)
|
||||
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")
|
||||
|
||||
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${SDKCONFIG_HEADER}" "${SDKCONFIG_CMAKE}")
|
||||
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
|
||||
ADDITIONAL_MAKE_CLEAN_FILES
|
||||
"${SDKCONFIG_HEADER}" "${SDKCONFIG_CMAKE}")
|
||||
|
||||
endfunction()
|
||||
|
@ -14,7 +14,10 @@ endif()
|
||||
#
|
||||
# Load cmake modules
|
||||
#
|
||||
set(CMAKE_MODULE_PATH "${IDF_PATH}/tools/cmake" "${IDF_PATH}/tools/cmake/third_party" ${CMAKE_MODULE_PATH})
|
||||
set(CMAKE_MODULE_PATH
|
||||
"${IDF_PATH}/tools/cmake"
|
||||
"${IDF_PATH}/tools/cmake/third_party"
|
||||
${CMAKE_MODULE_PATH})
|
||||
include(GetGitRevisionDescription)
|
||||
include(utilities)
|
||||
include(components)
|
||||
@ -29,20 +32,23 @@ set_default(PYTHON "python")
|
||||
# This macro wraps the cmake 'project' command to add
|
||||
# all of the IDF-specific functionality required
|
||||
#
|
||||
# Implementation Note: This macro wraps 'project' on purpose, because cmake has some
|
||||
# backwards-compatible magic where if you don't call "project" in the top-level
|
||||
# CMakeLists file, it will call it implicitly. However, the implict project will not
|
||||
# have CMAKE_TOOLCHAIN_FILE set and therefore tries to create a native build project.
|
||||
# Implementation Note: This macro wraps 'project' on purpose, because cmake has
|
||||
# some backwards-compatible magic where if you don't call "project" in the
|
||||
# top-level CMakeLists file, it will call it implicitly. However, the implicit
|
||||
# project will not have CMAKE_TOOLCHAIN_FILE set and therefore tries to
|
||||
# create a native build project.
|
||||
#
|
||||
# Therefore, to keep all the IDF "build magic", the cleanest way is to keep the
|
||||
# top-level "project" call but customize it to do what we want in the IDF build...
|
||||
# top-level "project" call but customize it to do what we want in the IDF build.
|
||||
#
|
||||
macro(project name)
|
||||
# Set global variables used by rest of the build
|
||||
idf_set_global_variables()
|
||||
|
||||
# Search COMPONENT_DIRS for COMPONENTS, make a list of full paths to each component in COMPONENT_PATHS
|
||||
components_find_all("${COMPONENT_DIRS}" "${COMPONENTS}" COMPONENT_PATHS COMPONENTS)
|
||||
# Search COMPONENT_DIRS for COMPONENTS, make a list of full paths to each
|
||||
# component in COMPONENT_PATHS
|
||||
components_find_all("${COMPONENT_DIRS}" "${COMPONENTS}"
|
||||
COMPONENT_PATHS COMPONENTS)
|
||||
|
||||
# Print list of components
|
||||
string(REPLACE ";" " " COMPONENTS_SPACES "${COMPONENTS}")
|
||||
@ -110,4 +116,4 @@ macro(project name)
|
||||
#
|
||||
components_finish_registration()
|
||||
|
||||
endmacro(project)
|
||||
endmacro()
|
||||
|
32
tools/cmake/run_cmake_lint.sh
Executable file
32
tools/cmake/run_cmake_lint.sh
Executable file
@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Run cmakelint on all cmake files in IDF_PATH (except third party)
|
||||
#
|
||||
# cmakelint: https://github.com/richq/cmake-lint
|
||||
#
|
||||
# NOTE: This script makes use of features in (currently unreleased)
|
||||
# cmakelint >1.4. Install directly from github as follows:
|
||||
#
|
||||
# pip install https://github.com/richq/cmake-lint/archive/058c6c0ed2536.zip
|
||||
#
|
||||
|
||||
if [ -z "${IDF_PATH}" ]; then
|
||||
echo "IDF_PATH variable needs to be set"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# exclusions include some third-party directories which contain upstream
|
||||
# CMakeLists files
|
||||
find ${IDF_PATH} \
|
||||
-name build -prune \
|
||||
-o -name third_party -prune \
|
||||
\
|
||||
-o -name 'nghttp2' -prune \
|
||||
-o -name 'cJSON' -prune \
|
||||
-o -name 'Findsodium.cmake' -prune \
|
||||
\
|
||||
-o -name CMakeLists.txt -print0 \
|
||||
-o -name '*.cmake' -print0 \
|
||||
| xargs -0 cmakelint --linelength=120 --spaces=4
|
||||
|
||||
|
@ -126,7 +126,7 @@ macro(include_if_exists path)
|
||||
if(EXISTS "${path}")
|
||||
include("${path}")
|
||||
endif()
|
||||
endmacro(include_if_exists)
|
||||
endmacro()
|
||||
|
||||
# Append a single line to the file specified
|
||||
# The line ending is determined by the host OS
|
||||
@ -145,4 +145,3 @@ function(file_append_line file line)
|
||||
endif()
|
||||
file(APPEND "${file}" "${line}${line_ending}")
|
||||
endfunction()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user