[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.
This commit is contained in:
Ciaran Woodward
2019-11-26 00:53:35 +08:00
committed by Jonathan Hui
parent 3807daa68a
commit 24bd599b45
5 changed files with 11 additions and 6 deletions
-2
View File
@@ -48,7 +48,6 @@ target_link_libraries(ot-cli-ftd
openthread-cli-ftd openthread-cli-ftd
${OT_PLATFORM_LIB} ${OT_PLATFORM_LIB}
openthread-ftd openthread-ftd
openthread-platform-utils
${OT_PLATFORM_LIB} ${OT_PLATFORM_LIB}
mbedcrypto mbedcrypto
) )
@@ -57,7 +56,6 @@ target_link_libraries(ot-cli-mtd
openthread-cli-mtd openthread-cli-mtd
${OT_PLATFORM_LIB} ${OT_PLATFORM_LIB}
openthread-mtd openthread-mtd
openthread-platform-utils
${OT_PLATFORM_LIB} ${OT_PLATFORM_LIB}
mbedcrypto mbedcrypto
) )
-3
View File
@@ -53,7 +53,6 @@ target_link_libraries(ot-ncp-ftd
openthread-ncp-ftd openthread-ncp-ftd
${OT_PLATFORM_LIB} ${OT_PLATFORM_LIB}
openthread-ftd openthread-ftd
openthread-platform-utils
${OT_PLATFORM_LIB} ${OT_PLATFORM_LIB}
mbedcrypto mbedcrypto
) )
@@ -62,7 +61,6 @@ target_link_libraries(ot-ncp-mtd
openthread-ncp-mtd openthread-ncp-mtd
${OT_PLATFORM_LIB} ${OT_PLATFORM_LIB}
openthread-mtd openthread-mtd
openthread-platform-utils
${OT_PLATFORM_LIB} ${OT_PLATFORM_LIB}
mbedcrypto mbedcrypto
) )
@@ -71,6 +69,5 @@ target_link_libraries(ot-rcp
openthread-rcp openthread-rcp
${OT_PLATFORM_LIB} ${OT_PLATFORM_LIB}
openthread-radio openthread-radio
openthread-platform-utils
${OT_PLATFORM_LIB} ${OT_PLATFORM_LIB}
) )
+3
View File
@@ -37,8 +37,11 @@ add_library(openthread-cc2538
system.c system.c
logging.c logging.c
uart.c uart.c
$<TARGET_OBJECTS:openthread-platform-utils>
) )
target_link_libraries(openthread-cc2538 PRIVATE openthread-platform-utils)
target_include_directories(openthread-cc2538 PRIVATE target_include_directories(openthread-cc2538 PRIVATE
${OT_PUBLIC_INCLUDES} ${OT_PUBLIC_INCLUDES}
${OT_PRIVATE_INCLUDES} ${OT_PRIVATE_INCLUDES}
+3
View File
@@ -41,12 +41,15 @@ add_library(openthread-posix
uart-posix.c uart-posix.c
sim/alarm-sim.c sim/alarm-sim.c
sim/platform-sim.c sim/platform-sim.c
$<TARGET_OBJECTS:openthread-platform-utils>
) )
if(LIBRT) if(LIBRT)
target_link_libraries(openthread-posix PRIVATE ${LIBRT}) target_link_libraries(openthread-posix PRIVATE ${LIBRT})
endif() endif()
target_link_libraries(openthread-posix PRIVATE openthread-platform-utils)
target_include_directories(openthread-posix PRIVATE target_include_directories(openthread-posix PRIVATE
${OT_PUBLIC_INCLUDES} ${OT_PUBLIC_INCLUDES}
${OT_PRIVATE_INCLUDES} ${OT_PRIVATE_INCLUDES}
+5 -1
View File
@@ -26,7 +26,7 @@
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
# #
add_library(openthread-platform-utils add_library(openthread-platform-utils OBJECT
debug_uart.c debug_uart.c
logging_rtt.c logging_rtt.c
mac_frame.cpp mac_frame.cpp
@@ -47,3 +47,7 @@ target_include_directories(openthread-platform-utils PRIVATE
${OT_ROOT_DIR}/src/core ${OT_ROOT_DIR}/src/core
${OT_ROOT_DIR}/third_party/jlink/SEGGER_RTT_V640/RTT ${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_OBJECTS:openthread-platform-utils>)
target_link_libraries(openthread-platform-utils-static PUBLIC openthread-platform-utils)