2018-02-15 03:38:58 +00:00
|
|
|
#
|
2018-11-11 07:36:10 +00:00
|
|
|
# Load cmake modules
|
2018-02-15 03:38:58 +00:00
|
|
|
#
|
2018-01-17 03:01:57 +00:00
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
get_property(__idf_environment_set GLOBAL PROPERTY __IDF_ENVIRONMENT_SET)
|
|
|
|
|
|
|
|
if(NOT __idf_environment_set)
|
2018-11-29 06:51:21 +00:00
|
|
|
|
|
|
|
# Set IDF_PATH, as nothing else will work without this.
|
|
|
|
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 relative to tools/cmake directory if it's not set.
|
|
|
|
get_filename_component(IDF_PATH "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE)
|
|
|
|
endif()
|
|
|
|
file(TO_CMAKE_PATH "${IDF_PATH}" IDF_PATH)
|
|
|
|
set(ENV{IDF_PATH} ${IDF_PATH})
|
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
set(CMAKE_MODULE_PATH
|
|
|
|
"${IDF_PATH}/tools/cmake"
|
|
|
|
"${IDF_PATH}/tools/cmake/third_party"
|
|
|
|
${CMAKE_MODULE_PATH})
|
|
|
|
include(utilities)
|
|
|
|
include(components)
|
|
|
|
include(kconfig)
|
|
|
|
include(targets)
|
|
|
|
include(git_submodules)
|
|
|
|
include(GetGitRevisionDescription)
|
|
|
|
include(crosstool_version_check)
|
|
|
|
include(ldgen)
|
|
|
|
|
|
|
|
set_default(PYTHON "python")
|
|
|
|
|
|
|
|
if(NOT PYTHON_DEPS_CHECKED AND NOT BOOTLOADER_BUILD)
|
|
|
|
message(STATUS "Checking Python dependencies...")
|
|
|
|
execute_process(COMMAND "${PYTHON}" "${IDF_PATH}/tools/check_python_dependencies.py"
|
|
|
|
RESULT_VARIABLE result)
|
|
|
|
if(NOT result EQUAL 0)
|
|
|
|
message(FATAL_ERROR "Some Python dependencies must be installed. Check above message for details.")
|
|
|
|
endif()
|
|
|
|
endif()
|
2018-03-22 06:27:10 +00:00
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
idf_set_target()
|
2018-01-17 03:01:57 +00:00
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
set_property(GLOBAL APPEND PROPERTY __IDF_COMPONENTS_PREFIX "idf_component")
|
|
|
|
set_property(GLOBAL PROPERTY __IDF_ENVIRONMENT_SET 1)
|
|
|
|
endif()
|
2018-09-11 01:44:12 +00:00
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
macro(idf_set_variables)
|
|
|
|
set_default(IDF_BUILD_ARTIFACTS OFF)
|
2018-01-17 03:01:57 +00:00
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
if(IDF_BUILD_ARTIFACTS)
|
|
|
|
if(NOT IDF_BUILD_ARTIFACTS_DIR OR NOT IDF_PROJECT_EXECUTABLE)
|
|
|
|
message(FATAL_ERROR "IDF_BUILD_ARTIFACTS and IDF_PROJECT_EXECUTABLE needs to be specified \
|
|
|
|
if IDF_BUILD_ARTIFACTS is ON.")
|
|
|
|
endif()
|
|
|
|
endif()
|
2018-01-17 03:01:57 +00:00
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
set_default(IDF_COMPONENT_DIRS "${IDF_EXTRA_COMPONENT_DIRS} ${IDF_PATH}/components")
|
|
|
|
set_default(IDF_COMPONENTS "")
|
|
|
|
set_default(IDF_COMPONENT_REQUIRES_COMMON "cxx ${IDF_TARGET} newlib freertos heap log soc")
|
2018-01-19 04:47:49 +00:00
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
set(IDF_PROJECT_PATH "${CMAKE_SOURCE_DIR}")
|
2018-09-18 05:07:21 +00:00
|
|
|
|
2018-11-28 23:39:11 +00:00
|
|
|
set(ESP_PLATFORM 1 CACHE BOOL INTERNAL)
|
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
spaces2list(IDF_COMPONENT_DIRS)
|
|
|
|
spaces2list(IDF_COMPONENTS)
|
|
|
|
spaces2list(IDF_COMPONENT_REQUIRES_COMMON)
|
2018-01-17 03:01:57 +00:00
|
|
|
endmacro()
|
2018-01-16 00:16:14 +00: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
|
|
|
|
#
|
2018-11-11 07:36:10 +00:00
|
|
|
function(idf_set_global_compile_options)
|
|
|
|
# Temporary trick to support both gcc5 and gcc8 builds
|
|
|
|
if(CMAKE_C_COMPILER_VERSION VERSION_EQUAL 5.2.0)
|
2018-12-05 12:03:25 +00:00
|
|
|
set(GCC_NOT_5_2_0 0 CACHE STRING "GCC is 5.2.0 version")
|
2018-11-11 07:36:10 +00:00
|
|
|
else()
|
2018-12-05 12:03:25 +00:00
|
|
|
set(GCC_NOT_5_2_0 1 CACHE STRING "GCC is not 5.2.0 version")
|
2018-11-11 07:36:10 +00:00
|
|
|
endif()
|
2018-12-05 12:03:25 +00:00
|
|
|
list(APPEND compile_definitions "GCC_NOT_5_2_0=${GCC_NOT_5_2_0}")
|
2018-11-11 07:36:10 +00:00
|
|
|
|
|
|
|
list(APPEND compile_definitions "ESP_PLATFORM" "HAVE_CONFIG_H")
|
|
|
|
|
|
|
|
list(APPEND compile_options "${CMAKE_C_FLAGS}")
|
|
|
|
list(APPEND c_compile_options "${CMAKE_C_FLAGS}")
|
|
|
|
list(APPEND cxx_compile_options "${CMAKE_CXX_FLAGS}")
|
2018-02-27 04:45:30 +00:00
|
|
|
|
|
|
|
if(CONFIG_OPTIMIZATION_LEVEL_RELEASE)
|
2018-11-11 07:36:10 +00:00
|
|
|
list(APPEND compile_options "-Os")
|
2018-02-27 04:45:30 +00:00
|
|
|
else()
|
2018-11-11 07:36:10 +00:00
|
|
|
list(APPEND compile_options "-Og")
|
2018-02-27 04:45:30 +00:00
|
|
|
endif()
|
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
list(APPEND c_compile_options "-std=gnu99")
|
|
|
|
list(APPEND cxx_compile_options "-std=gnu++11" "-fno-rtti")
|
2018-02-27 04:45:30 +00:00
|
|
|
|
|
|
|
if(CONFIG_CXX_EXCEPTIONS)
|
2018-11-11 07:36:10 +00:00
|
|
|
list(APPEND cxx_compile_options "-fexceptions")
|
2018-02-27 04:45:30 +00:00
|
|
|
else()
|
2018-11-11 07:36:10 +00:00
|
|
|
list(APPEND cxx_compile_options "-fno-exceptions")
|
2018-02-27 04:45:30 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Default compiler configuration
|
2018-11-11 07:36:10 +00:00
|
|
|
list(APPEND compile_options "-ffunction-sections"
|
|
|
|
"-fdata-sections"
|
|
|
|
"-fstrict-volatile-bitfields"
|
|
|
|
"-nostdlib")
|
|
|
|
|
|
|
|
list(APPEND 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")
|
|
|
|
|
|
|
|
list(APPEND c_compile_options "-Wno-old-style-declaration")
|
2018-02-27 04:45:30 +00:00
|
|
|
|
2018-09-18 05:07:21 +00:00
|
|
|
if(CONFIG_DISABLE_GCC8_WARNINGS)
|
2018-11-11 07:36:10 +00:00
|
|
|
list(APPEND compile_options
|
|
|
|
"-Wno-parentheses"
|
|
|
|
"-Wno-sizeof-pointer-memaccess"
|
|
|
|
"-Wno-clobbered"
|
2018-09-18 05:07:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# 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)
|
2018-11-11 07:36:10 +00:00
|
|
|
list(APPEND 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"
|
2018-09-18 05:07:21 +00:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2018-02-27 04:45:30 +00:00
|
|
|
# Stack protection
|
|
|
|
if(NOT BOOTLOADER_BUILD)
|
|
|
|
if(CONFIG_STACK_CHECK_NORM)
|
2018-11-11 07:36:10 +00:00
|
|
|
list(APPEND compile_options "-fstack-protector")
|
2018-02-27 04:45:30 +00:00
|
|
|
elseif(CONFIG_STACK_CHECK_STRONG)
|
2018-11-11 07:36:10 +00:00
|
|
|
list(APPEND compile_options "-fstack-protector-strong")
|
2018-02-27 04:45:30 +00:00
|
|
|
elseif(CONFIG_STACK_CHECK_ALL)
|
2018-11-11 07:36:10 +00:00
|
|
|
list(APPEND compile_options "-fstack-protector-all")
|
2018-02-27 04:45:30 +00:00
|
|
|
endif()
|
2018-01-16 00:16:14 +00:00
|
|
|
endif()
|
|
|
|
|
2018-02-27 04:45:30 +00:00
|
|
|
if(CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED)
|
2018-11-11 07:36:10 +00:00
|
|
|
list(APPEND compile_definitions "NDEBUG")
|
2018-02-27 04:45:30 +00:00
|
|
|
endif()
|
2018-01-16 00:16:14 +00:00
|
|
|
|
2018-02-27 04:45:30 +00:00
|
|
|
# Always generate debug symbols (even in Release mode, these don't
|
|
|
|
# go into the final binary so have no impact on size)
|
2018-11-11 07:36:10 +00:00
|
|
|
list(APPEND compile_options "-ggdb")
|
2018-02-27 02:32:52 +00:00
|
|
|
|
2018-11-27 14:46:50 +00:00
|
|
|
# Use EXTRA_CFLAGS, EXTRA_CXXFLAGS and EXTRA_CPPFLAGS to add more priority options to the compiler
|
|
|
|
# EXTRA_CPPFLAGS is used for both C and C++
|
|
|
|
# Unlike environments' CFLAGS/CXXFLAGS/CPPFLAGS which work for both host and target build,
|
|
|
|
# these works only for target build
|
|
|
|
set(EXTRA_CFLAGS "$ENV{EXTRA_CFLAGS}")
|
|
|
|
set(EXTRA_CXXFLAGS "$ENV{EXTRA_CXXFLAGS}")
|
|
|
|
set(EXTRA_CPPFLAGS "$ENV{EXTRA_CPPFLAGS}")
|
|
|
|
spaces2list(EXTRA_CFLAGS)
|
|
|
|
spaces2list(EXTRA_CXXFLAGS)
|
|
|
|
spaces2list(EXTRA_CPPFLAGS)
|
|
|
|
list(APPEND c_compile_options ${EXTRA_CFLAGS})
|
|
|
|
list(APPEND cxx_compile_options ${EXTRA_CXXFLAGS})
|
|
|
|
list(APPEND compile_options ${EXTRA_CPPFLAGS})
|
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
set_default(IDF_COMPILE_DEFINITIONS "${compile_definitions}")
|
|
|
|
set_default(IDF_COMPILE_OPTIONS "${compile_options}")
|
|
|
|
set_default(IDF_C_COMPILE_OPTIONS "${c_compile_options}")
|
|
|
|
set_default(IDF_CXX_COMPILE_OPTIONS "${cxx_compile_options}")
|
|
|
|
set_default(IDF_INCLUDE_DIRECTORIES "${CONFIG_DIR}")
|
|
|
|
|
|
|
|
set(IDF_COMPILE_DEFINITIONS ${IDF_COMPILE_DEFINITIONS} PARENT_SCOPE)
|
|
|
|
set(IDF_COMPILE_OPTIONS ${IDF_COMPILE_OPTIONS} PARENT_SCOPE)
|
|
|
|
set(IDF_C_COMPILE_OPTIONS ${IDF_C_COMPILE_OPTIONS} PARENT_SCOPE)
|
|
|
|
set(IDF_CXX_COMPILE_OPTIONS ${IDF_CXX_COMPILE_OPTIONS} PARENT_SCOPE)
|
|
|
|
set(IDF_INCLUDE_DIRECTORIES ${CONFIG_DIR} PARENT_SCOPE)
|
2018-02-27 04:45:30 +00:00
|
|
|
endfunction()
|
2018-01-16 00:16:14 +00:00
|
|
|
|
2018-01-17 03:01:57 +00:00
|
|
|
# Verify the IDF environment is configured correctly (environment, toolchain, etc)
|
|
|
|
function(idf_verify_environment)
|
2018-02-27 04:45:30 +00:00
|
|
|
if(NOT CMAKE_PROJECT_NAME)
|
|
|
|
message(FATAL_ERROR "Internal error, IDF project.cmake should have set this variable already")
|
|
|
|
endif()
|
2018-01-19 04:47:49 +00:00
|
|
|
|
2018-02-27 04:45:30 +00:00
|
|
|
# Check toolchain is configured properly in cmake
|
|
|
|
if(NOT ( ${CMAKE_SYSTEM_NAME} STREQUAL "Generic" AND ${CMAKE_C_COMPILER} MATCHES xtensa))
|
2018-06-15 04:59:45 +00: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-27 04:45:30 +00:00
|
|
|
endif()
|
2018-01-17 03:01:57 +00:00
|
|
|
|
2018-02-27 04:45:30 +00:00
|
|
|
#
|
|
|
|
# Warn if the toolchain version doesn't match
|
|
|
|
#
|
|
|
|
# TODO: make these platform-specific for diff toolchains
|
2018-09-18 05:07:21 +00:00
|
|
|
get_expected_ctng_version(expected_toolchain expected_gcc)
|
|
|
|
gcc_version_check("${expected_gcc}")
|
|
|
|
crosstool_version_check("${expected_toolchain}")
|
2018-02-22 04:05:05 +00: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-10-05 12:29:07 +00:00
|
|
|
git_describe(IDF_VER_GIT "${IDF_PATH}")
|
2018-09-14 11:32:37 +00:00
|
|
|
if(EXISTS "${IDF_PATH}/version.txt")
|
|
|
|
file(STRINGS "${IDF_PATH}/version.txt" IDF_VER)
|
2018-10-05 12:29:07 +00:00
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${IDF_PATH}/version.txt")
|
2018-09-14 11:32:37 +00:00
|
|
|
else()
|
2018-10-05 12:29:07 +00:00
|
|
|
set(IDF_VER ${IDF_VER_GIT})
|
2018-09-14 11:32:37 +00:00
|
|
|
endif()
|
2018-10-05 12:29:07 +00:00
|
|
|
message(STATUS "IDF_VER: ${IDF_VER}")
|
2018-02-27 04:45:30 +00:00
|
|
|
add_definitions(-DIDF_VER=\"${IDF_VER}\")
|
|
|
|
git_submodule_check("${IDF_PATH}")
|
|
|
|
set(IDF_VER ${IDF_VER} PARENT_SCOPE)
|
2018-11-11 07:36:10 +00:00
|
|
|
endfunction()
|
|
|
|
|
2018-10-05 12:29:07 +00:00
|
|
|
# app_get_revision
|
|
|
|
#
|
|
|
|
# Set global PROJECT_VER
|
|
|
|
#
|
|
|
|
# If PROJECT_VER variable set in project CMakeLists.txt file, its value will be used.
|
|
|
|
# Else, if the _project_path/version.txt exists, its contents will be used as PROJECT_VER.
|
|
|
|
# Else, if the project is located inside a Git repository, the output of git describe will be used.
|
2018-12-13 05:48:34 +00:00
|
|
|
# Otherwise, PROJECT_VER will be "1".
|
2018-10-05 12:29:07 +00:00
|
|
|
function(app_get_revision _project_path)
|
|
|
|
if(NOT DEFINED PROJECT_VER)
|
|
|
|
if(EXISTS "${_project_path}/version.txt")
|
|
|
|
file(STRINGS "${_project_path}/version.txt" PROJECT_VER)
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${_project_path}/version.txt")
|
|
|
|
else()
|
2018-12-13 05:48:34 +00:00
|
|
|
git_describe(PROJECT_VER_GIT "${_project_path}")
|
|
|
|
if(PROJECT_VER_GIT)
|
|
|
|
set(PROJECT_VER ${PROJECT_VER_GIT})
|
|
|
|
else()
|
|
|
|
message(STATUS "Project is not inside a git repository, \
|
|
|
|
will not use 'git describe' to determine PROJECT_VER.")
|
|
|
|
set(PROJECT_VER "1")
|
|
|
|
endif()
|
2018-10-05 12:29:07 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
message(STATUS "Project version: ${PROJECT_VER}")
|
|
|
|
set(PROJECT_VER ${PROJECT_VER} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
2018-11-11 07:36:10 +00:00
|
|
|
# idf_link_components
|
|
|
|
#
|
|
|
|
# Link library components to the target
|
|
|
|
function(idf_link_components target components)
|
|
|
|
foreach(component ${components})
|
|
|
|
component_get_target(component_target ${component})
|
|
|
|
|
|
|
|
# Add each component library's link-time dependencies (which are otherwise ignored) to the executable
|
|
|
|
# LINK_DEPENDS in order to trigger a re-link when needed (on Ninja/Makefile generators at least).
|
|
|
|
# (maybe this should probably be something CMake does, but it doesn't do it...)
|
|
|
|
if(TARGET ${component_target})
|
|
|
|
get_target_property(type ${component_target} TYPE)
|
|
|
|
get_target_property(imported ${component_target} IMPORTED)
|
|
|
|
if(NOT imported)
|
|
|
|
if(${type} STREQUAL STATIC_LIBRARY OR ${type} STREQUAL EXECUTABLE)
|
|
|
|
get_target_property(link_depends "${component_target}" LINK_DEPENDS)
|
|
|
|
if(link_depends)
|
|
|
|
set_property(TARGET ${target} APPEND PROPERTY LINK_DEPENDS "${link_depends}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(${type} MATCHES .+_LIBRARY)
|
|
|
|
list(APPEND libraries ${component_target})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if(libraries)
|
2018-12-03 23:47:00 +00:00
|
|
|
# gc-sections is necessary for linking some IDF binary libraries
|
|
|
|
# (and without it, IDF apps are much larger than they should be)
|
|
|
|
target_link_libraries(${target} "-Wl,--gc-sections")
|
2018-11-11 07:36:10 +00:00
|
|
|
target_link_libraries(${target} "-Wl,--start-group")
|
|
|
|
target_link_libraries(${target} ${libraries})
|
|
|
|
message(STATUS "Component libraries: ${IDF_COMPONENT_LIBRARIES}")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# idf_import_components
|
|
|
|
#
|
|
|
|
# Adds ESP-IDF as a subdirectory to the current project and imports the components
|
|
|
|
function(idf_import_components var idf_path build_path)
|
|
|
|
add_subdirectory(${idf_path} ${build_path})
|
|
|
|
set(${var} ${BUILD_COMPONENTS} PARENT_SCOPE)
|
2018-12-03 23:47:00 +00:00
|
|
|
endfunction()
|