From 4ac44bb578ad108e34339be1cacfffe6f286e8ce Mon Sep 17 00:00:00 2001 From: mhubii Date: Wed, 11 Sep 2024 18:08:20 +0200 Subject: [PATCH] added protobuf as individual target --- CMakeLists.txt | 92 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bae0d15..30affae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,14 +72,27 @@ file(GLOB_RECURSE NANOPB_SOURCES RELATIVE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/nanopb-${NANOPB_VERSION}/*.c ) +file(GLOB_RECURSE PROTOBUF_SOURCES RELATIVE ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/protobuf/*.cpp + ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/protobuf/*.c + ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/protobuf_gen/*.pb.c +) + file(GLOB_RECURSE FRI_SOURCES RELATIVE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/base/*.cpp ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/client_lbr/*.cpp ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/client_trafo/*.cpp ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/connection/*.cpp - ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/protobuf/*.cpp - ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/protobuf/*.c - ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/protobuf_gen/*.pb.c +) + +# add nanopb library target under common namespace +add_library(nanopb SHARED + ${NANOPB_SOURCES} +) + +# add protocol buffers and utilities under common namespace +add_library(protobuf SHARED + ${PROTOBUF_SOURCES} ) # add FRI library target @@ -87,13 +100,23 @@ add_library(FRIClient SHARED ${FRI_SOURCES} ) -# add nanopb library target under common namespace -add_library(nanopb STATIC - ${NANOPB_SOURCES} +add_library(FRIClient::nanopb ALIAS nanopb) # alias for anyone adding this as a submodule +add_library(FRIClient::protobuf ALIAS protobuf) # alias for anyone adding this as a submodule +add_library(FRIClient::FRIClient ALIAS FRIClient) # alias for anyone adding this as a submodule + +target_include_directories(nanopb + PUBLIC + $ + $ ) -add_library(FRIClient::FRIClient ALIAS FRIClient) # alias for anyone adding this as a submodule -add_library(FRIClient::nanopb ALIAS nanopb) # alias for anyone adding this as a submodule +target_include_directories(protobuf + PUBLIC + $ + $ + $ + $ +) target_include_directories(FRIClient PUBLIC @@ -101,23 +124,21 @@ target_include_directories(FRIClient $ PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/base - ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/protobuf_gen - ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/protobuf ) -target_include_directories(nanopb - PUBLIC - $ - $ +target_link_libraries(protobuf + PRIVATE + nanopb ) target_link_libraries(FRIClient PRIVATE nanopb + protobuf ) if(MSVC) - target_compile_options(FRIClient + target_compile_options(nanopb PRIVATE -DPB_SYSTEM_HEADER="pb_syshdr_win.h" -DPB_FIELD_16BIT @@ -125,12 +146,19 @@ if(MSVC) -DHAVE_STDINT_H -DHAVE_STDBOOL_H ) -else() + target_compile_options(protobuf + PRIVATE + -DPB_FIELD_16BIT + ) target_compile_options(FRIClient + PRIVATE + -DWIN32 + ) +else() + target_compile_options(nanopb PRIVATE -Wall -O2 - -DHAVE_SOCKLEN_T -DPB_SYSTEM_HEADER="pb_syshdr.h" -DPB_FIELD_16BIT -DHAVE_STDINT_H @@ -138,6 +166,18 @@ else() -DHAVE_STDBOOL_H -DHAVE_STDLIB_H -DHAVE_STRING_H + ) + target_compile_options(protobuf + PRIVATE + -Wall + -O2 + -DPB_FIELD_16BIT + ) + target_compile_options(FRIClient + PRIVATE + -Wall + -O2 + -DHAVE_SOCKLEN_T ) endif() @@ -152,15 +192,24 @@ write_basic_package_version_file( COMPATIBILITY SameMajorVersion ) -install(TARGETS FRIClient nanopb +install(TARGETS nanopb protobuf FRIClient EXPORT FRIClientTargets LIBRARY DESTINATION lib INCLUDES DESTINATION include ) install( - DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/include/ + DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/protobuf_gen/ + DESTINATION include + FILES_MATCHING + PATTERN *.h +) + +install( + DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/src/protobuf/ DESTINATION include + FILES_MATCHING + PATTERN *.h ) install( @@ -170,6 +219,11 @@ install( PATTERN *.h ) +install( + DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/include/ + DESTINATION include +) + install(EXPORT FRIClientTargets FILE FRIClientConfig.cmake NAMESPACE FRIClient::