2018-01-15 19:16:14 -05:00
|
|
|
# Some IDF-specific functions and functions
|
|
|
|
|
2018-01-16 22:01:57 -05:00
|
|
|
include(crosstool_version_check)
|
|
|
|
|
2018-02-14 22:38:58 -05:00
|
|
|
#
|
|
|
|
# Set some variables used by rest of the build
|
|
|
|
#
|
|
|
|
# Note at the time this macro is expanded, the config is not yet
|
|
|
|
# loaded and the toolchain and project are not yet set
|
|
|
|
#
|
2018-01-16 22:01:57 -05:00
|
|
|
macro(idf_set_global_variables)
|
2018-02-26 23:45:30 -05:00
|
|
|
# Note that CONFIG_xxx is not available when this function is called
|
2018-01-16 22:01:57 -05:00
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
set_default(EXTRA_COMPONENT_DIRS "")
|
2018-01-16 22:01:57 -05:00
|
|
|
|
2018-03-22 02:27:10 -04:00
|
|
|
# Commmon components, required by every component in the build
|
|
|
|
#
|
|
|
|
set_default(COMPONENT_REQUIRES_COMMON "cxx esp32 newlib freertos heap log soc")
|
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
# 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}")
|
2018-01-16 22:01:57 -05:00
|
|
|
|
2018-09-10 21:44:12 -04:00
|
|
|
if(MAIN_SRCS)
|
|
|
|
message(WARNING "main is now a component, use of MAIN_SRCS is deprecated")
|
|
|
|
set_default(COMPONENT_DIRS "${PROJECT_PATH}/components ${EXTRA_COMPONENT_DIRS} \
|
|
|
|
${IDF_PATH}/components")
|
|
|
|
else()
|
|
|
|
set_default(COMPONENT_DIRS "${PROJECT_PATH}/components ${EXTRA_COMPONENT_DIRS} \
|
|
|
|
${IDF_PATH}/components ${PROJECT_PATH}/main")
|
|
|
|
endif()
|
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
spaces2list(COMPONENT_DIRS)
|
2018-01-16 22:01:57 -05:00
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
spaces2list(COMPONENTS)
|
2018-01-16 22:01:57 -05:00
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
# Tell cmake to drop executables in the top-level build dir
|
|
|
|
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}")
|
2018-01-18 23:47:49 -05:00
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
# path to idf.py tool
|
|
|
|
set(IDFTOOL ${PYTHON} "${IDF_PATH}/tools/idf.py")
|
2018-09-18 01:07:21 -04:00
|
|
|
|
|
|
|
# Temporary trick to support both gcc5 and gcc8 builds
|
|
|
|
if(CMAKE_C_COMPILER_VERSION VERSION_EQUAL 5.2.0)
|
|
|
|
set(GCC_NOT_5_2_0 0)
|
|
|
|
else()
|
|
|
|
set(GCC_NOT_5_2_0 1)
|
|
|
|
endif()
|
2018-01-16 22:01:57 -05:00
|
|
|
endmacro()
|
2018-01-15 19:16:14 -05:00
|
|
|
|
|
|
|
# Add all the IDF global compiler & preprocessor options
|
|
|
|
# (applied to all components). Some are config-dependent
|
|
|
|
#
|
|
|
|
# If you only want to set options for a particular component,
|
|
|
|
# don't call or edit this function. TODO DESCRIBE WHAT TO DO INSTEAD
|
|
|
|
#
|
|
|
|
function(idf_set_global_compiler_options)
|
2018-02-26 23:45:30 -05:00
|
|
|
add_definitions(-DESP_PLATFORM)
|
|
|
|
add_definitions(-DHAVE_CONFIG_H)
|
|
|
|
|
|
|
|
if(CONFIG_OPTIMIZATION_LEVEL_RELEASE)
|
|
|
|
add_compile_options(-Os)
|
|
|
|
else()
|
|
|
|
add_compile_options(-Og)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_c_compile_options(-std=gnu99)
|
|
|
|
|
|
|
|
add_cxx_compile_options(-std=gnu++11 -fno-rtti)
|
|
|
|
|
|
|
|
if(CONFIG_CXX_EXCEPTIONS)
|
|
|
|
add_cxx_compile_options(-fexceptions)
|
|
|
|
else()
|
|
|
|
add_cxx_compile_options(-fno-exceptions)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Default compiler configuration
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2018-09-18 01:07:21 -04:00
|
|
|
if(CONFIG_DISABLE_GCC8_WARNINGS)
|
|
|
|
add_compile_options(
|
|
|
|
-Wno-parentheses
|
|
|
|
-Wno-sizeof-pointer-memaccess
|
|
|
|
-Wno-clobbered
|
|
|
|
)
|
|
|
|
|
|
|
|
# doesn't use GCC_NOT_5_2_0 because idf_set_global_variables was not called before
|
|
|
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_EQUAL 5.2.0)
|
|
|
|
add_compile_options(
|
|
|
|
-Wno-format-overflow
|
|
|
|
-Wno-stringop-truncation
|
|
|
|
-Wno-misleading-indentation
|
|
|
|
-Wno-cast-function-type
|
|
|
|
-Wno-implicit-fallthrough
|
|
|
|
-Wno-unused-const-variable
|
|
|
|
-Wno-switch-unreachable
|
|
|
|
-Wno-format-truncation
|
|
|
|
-Wno-memset-elt-size
|
|
|
|
-Wno-int-in-bool-context
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
# Stack protection
|
|
|
|
if(NOT BOOTLOADER_BUILD)
|
|
|
|
if(CONFIG_STACK_CHECK_NORM)
|
|
|
|
add_compile_options(-fstack-protector)
|
|
|
|
elseif(CONFIG_STACK_CHECK_STRONG)
|
|
|
|
add_compile_options(-fstack-protector-strong)
|
|
|
|
elseif(CONFIG_STACK_CHECK_ALL)
|
|
|
|
add_compile_options(-fstack-protector-all)
|
|
|
|
endif()
|
2018-01-15 19:16:14 -05:00
|
|
|
endif()
|
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
if(CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED)
|
|
|
|
add_definitions(-DNDEBUG)
|
|
|
|
endif()
|
2018-01-15 19:16:14 -05:00
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
# Always generate debug symbols (even in Release mode, these don't
|
|
|
|
# go into the final binary so have no impact on size)
|
|
|
|
add_compile_options(-ggdb)
|
2018-01-15 19:16:14 -05:00
|
|
|
|
2018-02-26 21:32:52 -05:00
|
|
|
# Enable ccache if it's on the path
|
2018-03-19 21:27:00 -04:00
|
|
|
if(NOT CCACHE_DISABLE)
|
|
|
|
find_program(CCACHE_FOUND ccache)
|
|
|
|
if(CCACHE_FOUND)
|
|
|
|
message(STATUS "ccache will be used for faster builds")
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
|
|
|
|
endif()
|
2018-02-26 21:32:52 -05:00
|
|
|
endif()
|
|
|
|
|
2018-09-18 01:07:21 -04:00
|
|
|
# Temporary trick to support both gcc5 and gcc8 builds
|
|
|
|
add_definitions(-DGCC_NOT_5_2_0=${GCC_NOT_5_2_0})
|
2018-02-26 23:45:30 -05:00
|
|
|
endfunction()
|
2018-01-15 19:16:14 -05:00
|
|
|
|
2018-01-16 22:01:57 -05:00
|
|
|
|
|
|
|
# Verify the IDF environment is configured correctly (environment, toolchain, etc)
|
|
|
|
function(idf_verify_environment)
|
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
if(NOT CMAKE_PROJECT_NAME)
|
|
|
|
message(FATAL_ERROR "Internal error, IDF project.cmake should have set this variable already")
|
|
|
|
endif()
|
2018-01-18 23:47:49 -05:00
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
# Check toolchain is configured properly in cmake
|
|
|
|
if(NOT ( ${CMAKE_SYSTEM_NAME} STREQUAL "Generic" AND ${CMAKE_C_COMPILER} MATCHES xtensa))
|
2018-06-15 00:59:45 -04:00
|
|
|
message(FATAL_ERROR "Internal error, toolchain has not been set correctly by project "
|
|
|
|
"(or an invalid CMakeCache.txt file has been generated somehow)")
|
2018-02-26 23:45:30 -05:00
|
|
|
endif()
|
2018-01-16 22:01:57 -05:00
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
#
|
|
|
|
# Warn if the toolchain version doesn't match
|
|
|
|
#
|
|
|
|
# TODO: make these platform-specific for diff toolchains
|
2018-09-18 01:07:21 -04:00
|
|
|
get_expected_ctng_version(expected_toolchain expected_gcc)
|
|
|
|
gcc_version_check("${expected_gcc}")
|
|
|
|
crosstool_version_check("${expected_toolchain}")
|
2018-01-16 22:01:57 -05:00
|
|
|
|
2018-01-17 00:25:14 -05:00
|
|
|
endfunction()
|
2018-01-18 23:47:49 -05:00
|
|
|
|
|
|
|
# idf_add_executable
|
|
|
|
#
|
|
|
|
# Calls add_executable to add the final project executable
|
|
|
|
# Adds .map & .bin file targets
|
|
|
|
# Sets up flash-related targets
|
|
|
|
function(idf_add_executable)
|
2018-02-26 23:45:30 -05:00
|
|
|
set(exe_target ${PROJECT_NAME}.elf)
|
2018-01-21 22:32:02 -05:00
|
|
|
|
2018-09-10 21:44:12 -04:00
|
|
|
if(MAIN_SRCS)
|
|
|
|
spaces2list(MAIN_SRCS)
|
|
|
|
add_executable(${exe_target} ${MAIN_SRCS})
|
|
|
|
else()
|
|
|
|
# Create a dummy file to work around CMake requirement of having a source
|
|
|
|
# file while adding an executable
|
|
|
|
add_executable(${exe_target} "${CMAKE_CURRENT_BINARY_DIR}/dummy_main_src.c")
|
2018-11-14 06:45:14 -05:00
|
|
|
add_custom_command(OUTPUT dummy_main_src.c
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E touch dummy_main_src.c
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
VERBATIM)
|
2018-09-10 21:44:12 -04:00
|
|
|
|
|
|
|
add_custom_target(dummy_main_src DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/dummy_main_src.c)
|
|
|
|
|
|
|
|
add_dependencies(${exe_target} dummy_main_src)
|
|
|
|
endif()
|
2018-01-23 01:08:28 -05:00
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
add_map_file(${exe_target})
|
|
|
|
endfunction()
|
2018-01-18 23:47:49 -05:00
|
|
|
|
|
|
|
|
|
|
|
# add_map_file
|
|
|
|
#
|
|
|
|
# Set linker args for 'exe_target' to generate a linker Map file
|
|
|
|
function(add_map_file exe_target)
|
2018-02-26 23:45:30 -05:00
|
|
|
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}")
|
|
|
|
|
|
|
|
# add size targets, depend on map file, run idf_size.py
|
|
|
|
add_custom_target(size
|
|
|
|
DEPENDS ${exe_target}
|
|
|
|
COMMAND ${PYTHON} ${IDF_PATH}/tools/idf_size.py ${mapfile}
|
|
|
|
)
|
|
|
|
add_custom_target(size-files
|
|
|
|
DEPENDS ${exe_target}
|
|
|
|
COMMAND ${PYTHON} ${IDF_PATH}/tools/idf_size.py --files ${mapfile}
|
|
|
|
)
|
|
|
|
add_custom_target(size-components
|
|
|
|
DEPENDS ${exe_target}
|
|
|
|
COMMAND ${PYTHON} ${IDF_PATH}/tools/idf_size.py --archives ${mapfile}
|
|
|
|
)
|
2018-01-23 01:08:28 -05:00
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
endfunction()
|
2018-02-21 23:05:05 -05:00
|
|
|
|
|
|
|
# component_compile_options
|
|
|
|
#
|
|
|
|
# Wrapper around target_compile_options that passes the component name
|
|
|
|
function(component_compile_options)
|
2018-02-26 23:45:30 -05:00
|
|
|
target_compile_options(${COMPONENT_NAME} PRIVATE ${ARGV})
|
2018-02-21 23:05:05 -05:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# component_compile_definitions
|
|
|
|
#
|
|
|
|
# Wrapper around target_compile_definitions that passes the component name
|
|
|
|
function(component_compile_definitions)
|
2018-02-26 23:45:30 -05:00
|
|
|
target_compile_definitions(${COMPONENT_NAME} PRIVATE ${ARGV})
|
2018-02-21 23:05:05 -05:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# idf_get_git_revision
|
|
|
|
#
|
|
|
|
# Set global IDF_VER to the git revision of ESP-IDF.
|
|
|
|
#
|
|
|
|
# Running git_describe() here automatically triggers rebuilds
|
|
|
|
# if the ESP-IDF git version changes
|
|
|
|
function(idf_get_git_revision)
|
2018-09-14 07:32:37 -04:00
|
|
|
if(EXISTS "${IDF_PATH}/version.txt")
|
|
|
|
file(STRINGS "${IDF_PATH}/version.txt" IDF_VER)
|
|
|
|
else()
|
|
|
|
git_describe(IDF_VER "${IDF_PATH}")
|
|
|
|
endif()
|
2018-02-26 23:45:30 -05:00
|
|
|
add_definitions(-DIDF_VER=\"${IDF_VER}\")
|
|
|
|
git_submodule_check("${IDF_PATH}")
|
|
|
|
set(IDF_VER ${IDF_VER} PARENT_SCOPE)
|
2018-08-26 22:48:16 -04:00
|
|
|
endfunction()
|