[cmake] add all important cflags in the toolchain file, remove platform.cmake (#4112)

This is important for allowing cmake to properly configure itself,
knowing what cflags will be passed. Also I removed all of the
public modifications of CMAKE_CXX_FLAGS, to better control where
the flags are actually applied.

The linker file is an exception to the toolchain file, as it
depends on symbols that are declared in the startup file
(startup-gcc.c for cc2538). Therefore it has been added as a
PUBLIC requirement for the cc2538 platform layer.
This commit is contained in:
Ciaran Woodward
2019-11-26 00:53:35 +08:00
committed by Jonathan Hui
parent ac903c3673
commit 96be52fd38
7 changed files with 24 additions and 89 deletions
+1 -2
View File
@@ -56,10 +56,9 @@ endif()
list(APPEND OT_PUBLIC_INCLUDES ${PROJECT_SOURCE_DIR}/etc/cmake)
list(APPEND OT_PUBLIC_INCLUDES ${PROJECT_SOURCE_DIR}/include)
if(NOT OT_PLATFORM MATCHES "none")
list(APPEND OT_PRIVATE_INCLUDES ${PROJECT_SOURCE_DIR}/examples/platforms/${OT_PLATFORM})
include("${PROJECT_SOURCE_DIR}/examples/platforms/${OT_PLATFORM}/platform.cmake")
add_subdirectory("${PROJECT_SOURCE_DIR}/examples/platforms/${OT_PLATFORM}")
endif()
list(APPEND OT_PRIVATE_DEFINES ${OT_PLATFORM_DEFINES})
+1 -1
View File
@@ -32,4 +32,4 @@ check_function_exists("strlcat" HAVE_STRLCAT)
check_function_exists("strlcpy" HAVE_STRLCPY)
check_function_exists("strnlen" HAVE_STRNLEN)
configure_file(${OT_ROOT_DIR}/etc/cmake/openthread-config-generic.h.in ${OT_ROOT_DIR}/etc/cmake/openthread-config-generic.h)
configure_file(${PROJECT_SOURCE_DIR}/etc/cmake/openthread-config-generic.h.in ${PROJECT_SOURCE_DIR}/etc/cmake/openthread-config-generic.h)
+10
View File
@@ -26,6 +26,15 @@
# POSSIBILITY OF SUCH DAMAGE.
#
set(OT_PLATFORM_LIB "openthread-cc2538" PARENT_SCOPE)
list(APPEND OT_PLATFORM_DEFINES
"OPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"openthread-core-cc2538-config.h\""
"OPENTHREAD_CORE_CONFIG_PLATFORM_CHECK_FILE=\"openthread-core-cc2538-config-check.h\""
"OPENTHREAD_CONFIG_NCP_UART_ENABLE=1"
)
set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE)
add_library(openthread-cc2538
alarm.c
diag.c
@@ -41,6 +50,7 @@ add_library(openthread-cc2538
)
target_link_libraries(openthread-cc2538 PRIVATE openthread-platform-utils)
target_link_options(openthread-cc2538 PUBLIC -T${PROJECT_SOURCE_DIR}/examples/platforms/cc2538/cc2538.ld)
target_compile_definitions(openthread-cc2538 PUBLIC ${OT_PLATFORM_DEFINES})
@@ -34,12 +34,12 @@ set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_ASM_COMPILER arm-none-eabi-as)
set(CMAKE_RANLIB arm-none-eabi-ranlib)
set(COMMON_C_FLAGS "-mthumb -fno-builtin -Wall -fdata-sections -ffunction-sections -mabi=aapcs")
set(COMMON_C_FLAGS "-mthumb -fno-builtin -Wall -fdata-sections -ffunction-sections -mabi=aapcs -mcpu=cortex-m3 -mfloat-abi=soft")
set(CMAKE_C_FLAGS "${COMMON_C_FLAGS} -std=gnu99")
set(CMAKE_CXX_FLAGS "${COMMON_C_FLAGS} -fno-exceptions -fno-rtti")
set(CMAKE_ASM_FLAGS "${COMMON_C_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections -specs=nano.specs -specs=nosys.specs -mthumb -mabi=aapcs -Wl,-Map=${CMAKE_PROJECT_NAME}.map")
set(CMAKE_EXE_LINKER_FLAGS "${COMMON_C_FLAGS} -Wl,--gc-sections -specs=nano.specs -specs=nosys.specs -Wl,-Map=${CMAKE_PROJECT_NAME}.map -nostartfiles")
set(CMAKE_C_FLAGS_DEBUG "-Og -g")
set(CMAKE_CXX_FLAGS_DEBUG "-Og -g")
-43
View File
@@ -1,43 +0,0 @@
#
# Copyright (c) 2019, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
list(APPEND OT_PLATFORM_DEFINES
"OPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"openthread-core-cc2538-config.h\""
"OPENTHREAD_CORE_CONFIG_PLATFORM_CHECK_FILE=\"openthread-core-cc2538-config-check.h\""
"OPENTHREAD_CONFIG_NCP_UART_ENABLE=1"
)
set(common_c_flags "-mcpu=cortex-m3 -mfloat-abi=soft")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${common_c_flags}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${common_c_flags}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${common_c_flags} -nostartfiles -T${OT_ROOT_DIR}/examples/platforms/cc2538/cc2538.ld")
set(OT_PLATFORM_LIB "openthread-cc2538")
add_subdirectory("${OT_ROOT_DIR}/examples/platforms/cc2538")
+10 -1
View File
@@ -26,7 +26,15 @@
# POSSIBILITY OF SUCH DAMAGE.
#
find_library(LIBRT rt)
set(OT_PLATFORM_LIB "openthread-posix" PARENT_SCOPE)
list(APPEND OT_PLATFORM_DEFINES
"OPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"openthread-core-posix-config.h\""
"OPENTHREAD_EXAMPLES_POSIX=1"
"OPENTHREAD_POSIX=1"
"OPENTHREAD_CONFIG_NCP_UART_ENABLE=1"
)
set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE)
add_library(openthread-posix
alarm.c
@@ -44,6 +52,7 @@ add_library(openthread-posix
$<TARGET_OBJECTS:openthread-platform-utils>
)
find_library(LIBRT rt)
if(LIBRT)
target_link_libraries(openthread-posix PRIVATE ${LIBRT})
endif()
-40
View File
@@ -1,40 +0,0 @@
#
# Copyright (c) 2019, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
list(APPEND OT_PLATFORM_DEFINES
"OPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"openthread-core-posix-config.h\""
"OPENTHREAD_EXAMPLES_POSIX=1"
"OPENTHREAD_CONFIG_NCP_UART_ENABLE=1"
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENTHREAD_POSIX=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENTHREAD_EXAMPLES_POSIX=1")
set(OT_PLATFORM_LIB "openthread-posix")
add_subdirectory("${OT_ROOT_DIR}/examples/platforms/posix")