diff --git a/CMakeLists.txt b/CMakeLists.txt index 921457b89..3578fa6c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/etc/cmake/checks.cmake b/etc/cmake/checks.cmake index 727721cdf..82f367572 100644 --- a/etc/cmake/checks.cmake +++ b/etc/cmake/checks.cmake @@ -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) diff --git a/examples/platforms/cc2538/CMakeLists.txt b/examples/platforms/cc2538/CMakeLists.txt index 9b928c037..83aa2d42f 100644 --- a/examples/platforms/cc2538/CMakeLists.txt +++ b/examples/platforms/cc2538/CMakeLists.txt @@ -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}) diff --git a/examples/platforms/cc2538/arm-none-eabi.cmake b/examples/platforms/cc2538/arm-none-eabi.cmake index 173166d8f..678ab49ba 100644 --- a/examples/platforms/cc2538/arm-none-eabi.cmake +++ b/examples/platforms/cc2538/arm-none-eabi.cmake @@ -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") diff --git a/examples/platforms/cc2538/platform.cmake b/examples/platforms/cc2538/platform.cmake deleted file mode 100644 index f505e4efb..000000000 --- a/examples/platforms/cc2538/platform.cmake +++ /dev/null @@ -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") diff --git a/examples/platforms/posix/CMakeLists.txt b/examples/platforms/posix/CMakeLists.txt index 76bad0e1f..1de46f514 100644 --- a/examples/platforms/posix/CMakeLists.txt +++ b/examples/platforms/posix/CMakeLists.txt @@ -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 $ ) +find_library(LIBRT rt) if(LIBRT) target_link_libraries(openthread-posix PRIVATE ${LIBRT}) endif() diff --git a/examples/platforms/posix/platform.cmake b/examples/platforms/posix/platform.cmake deleted file mode 100644 index 0377b83d2..000000000 --- a/examples/platforms/posix/platform.cmake +++ /dev/null @@ -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")