From 24bd599b45853cecd1b35cf4fbea20b23ce62999 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Tue, 19 Nov 2019 13:28:42 +0000 Subject: [PATCH] [cmake] fix platform-utils for cmake (#4112) platform-utils has a dependency on the core ot library, which was causing the build to fail. I have resolved this by making platform-utils an 'object library', which means the object files will always be used by the linker, preventing the 'smart linker' errors that occur with ld and cyclic dependencies. I also provided a static (.a) implementation of the library in case any non-cmake project wanted to consume the results (at which point that project can deal with the dependency as it wishes). So now it is up to the 'platform layer' to include the 'platform utils' objects inside its own library if it requires them. I have implemented this for the current cmake example platforms. --- examples/apps/cli/CMakeLists.txt | 2 -- examples/apps/ncp/CMakeLists.txt | 3 --- examples/platforms/cc2538/CMakeLists.txt | 3 +++ examples/platforms/posix/CMakeLists.txt | 3 +++ examples/platforms/utils/CMakeLists.txt | 6 +++++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/apps/cli/CMakeLists.txt b/examples/apps/cli/CMakeLists.txt index d4bd9f377..9f756883f 100644 --- a/examples/apps/cli/CMakeLists.txt +++ b/examples/apps/cli/CMakeLists.txt @@ -48,7 +48,6 @@ target_link_libraries(ot-cli-ftd openthread-cli-ftd ${OT_PLATFORM_LIB} openthread-ftd - openthread-platform-utils ${OT_PLATFORM_LIB} mbedcrypto ) @@ -57,7 +56,6 @@ target_link_libraries(ot-cli-mtd openthread-cli-mtd ${OT_PLATFORM_LIB} openthread-mtd - openthread-platform-utils ${OT_PLATFORM_LIB} mbedcrypto ) diff --git a/examples/apps/ncp/CMakeLists.txt b/examples/apps/ncp/CMakeLists.txt index b966d0b20..5ac8658ac 100644 --- a/examples/apps/ncp/CMakeLists.txt +++ b/examples/apps/ncp/CMakeLists.txt @@ -53,7 +53,6 @@ target_link_libraries(ot-ncp-ftd openthread-ncp-ftd ${OT_PLATFORM_LIB} openthread-ftd - openthread-platform-utils ${OT_PLATFORM_LIB} mbedcrypto ) @@ -62,7 +61,6 @@ target_link_libraries(ot-ncp-mtd openthread-ncp-mtd ${OT_PLATFORM_LIB} openthread-mtd - openthread-platform-utils ${OT_PLATFORM_LIB} mbedcrypto ) @@ -71,6 +69,5 @@ target_link_libraries(ot-rcp openthread-rcp ${OT_PLATFORM_LIB} openthread-radio - openthread-platform-utils ${OT_PLATFORM_LIB} ) diff --git a/examples/platforms/cc2538/CMakeLists.txt b/examples/platforms/cc2538/CMakeLists.txt index e1db93fbc..3a59d40c4 100644 --- a/examples/platforms/cc2538/CMakeLists.txt +++ b/examples/platforms/cc2538/CMakeLists.txt @@ -37,8 +37,11 @@ add_library(openthread-cc2538 system.c logging.c uart.c + $ ) +target_link_libraries(openthread-cc2538 PRIVATE openthread-platform-utils) + target_include_directories(openthread-cc2538 PRIVATE ${OT_PUBLIC_INCLUDES} ${OT_PRIVATE_INCLUDES} diff --git a/examples/platforms/posix/CMakeLists.txt b/examples/platforms/posix/CMakeLists.txt index 3ac789a1c..a21d83b8f 100644 --- a/examples/platforms/posix/CMakeLists.txt +++ b/examples/platforms/posix/CMakeLists.txt @@ -41,12 +41,15 @@ add_library(openthread-posix uart-posix.c sim/alarm-sim.c sim/platform-sim.c + $ ) if(LIBRT) target_link_libraries(openthread-posix PRIVATE ${LIBRT}) endif() +target_link_libraries(openthread-posix PRIVATE openthread-platform-utils) + target_include_directories(openthread-posix PRIVATE ${OT_PUBLIC_INCLUDES} ${OT_PRIVATE_INCLUDES} diff --git a/examples/platforms/utils/CMakeLists.txt b/examples/platforms/utils/CMakeLists.txt index b99dac922..2adb8525c 100644 --- a/examples/platforms/utils/CMakeLists.txt +++ b/examples/platforms/utils/CMakeLists.txt @@ -26,7 +26,7 @@ # POSSIBILITY OF SUCH DAMAGE. # -add_library(openthread-platform-utils +add_library(openthread-platform-utils OBJECT debug_uart.c logging_rtt.c mac_frame.cpp @@ -47,3 +47,7 @@ target_include_directories(openthread-platform-utils PRIVATE ${OT_ROOT_DIR}/src/core ${OT_ROOT_DIR}/third_party/jlink/SEGGER_RTT_V640/RTT ) + +# Provide a static library implementation of platform-utils for non-cmake platforms +add_library(openthread-platform-utils-static $) +target_link_libraries(openthread-platform-utils-static PUBLIC openthread-platform-utils)