cmake: Move global IDF-specific compiler/linker options out of the toolchain file

Should restore compatibility with cmake pre-v3.7
This commit is contained in:
Angus Gratton 2018-01-16 11:16:14 +11:00 committed by Angus Gratton
parent f04525095f
commit 067a19ad88
4 changed files with 92 additions and 8 deletions

View file

@ -34,6 +34,7 @@ include(components)
include(kconfig)
include(crosstool_version_check)
include(git_submodules)
include(idf_functions)
#
# Warn if the toolchain version doesn't match
@ -61,9 +62,7 @@ include(${SDKCONFIG_CMAKE})
#
# Add some idf-wide definitions
#
add_definitions(-DESP_PLATFORM)
add_definitions(-DHAVE_CONFIG_H)
idf_set_global_compiler_options()
git_describe(GIT_REVISION)
add_definitions(-DIDF_VER=\"${GIT_REVISION}\")

View file

@ -4,8 +4,4 @@ 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")
set(CMAKE_EXE_LINKER_FLAGS "-nostdlib" CACHE STRING "Linker Base Flags")

View file

@ -0,0 +1,67 @@
# Some IDF-specific functions and functions
# 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)
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)
# 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()
endif()
if(CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED)
add_definitions(-DNDEBUG)
endif()
# Always generate debug symbols (even in Release mode, these don't
# go itno ther final binary
add_compile_options(-ggdb)
endfunction()
# Override add_executable to add IDF-specific
# linker flags & map file to all built executables
function(add_executable target)
get_filename_component(basename ${target} NAME_WE)
set(mapfile "${basename}.map")
_add_executable(${ARGV})
target_link_libraries(${target} "-Wl,--gc-sections -Wl,--cref -Wl,--Map=${mapfile} -Wl,--start-group")
endfunction()

View file

@ -72,3 +72,25 @@ function(move_if_different source destination)
endif()
endfunction()
# add_compile_options variant for C++ code only
#
# This adds global options, set target properties for
# component-specific flags
function(add_cxx_compile_options)
foreach(option ${ARGV})
# note: the Visual Studio Generator doesn't support this...
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:${option}>)
endforeach()
endfunction()
# add_compile_options variant for C code only
#
# This adds global options, set target properties for
# component-specific flags
function(add_c_compile_options)
foreach(option ${ARGV})
# note: the Visual Studio Generator doesn't support this...
add_compile_options($<$<COMPILE_LANGUAGE:C>:${option}>)
endforeach()
endfunction()