From cf3256a7ef40f5ff3d9ac8d667aa0d888f12bbdb Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Tue, 14 Jan 2025 10:29:38 -0500 Subject: [PATCH 1/5] make viamapi a private dep of sdk --- src/viam/examples/modules/complex/CMakeLists.txt | 1 + src/viam/sdk/CMakeLists.txt | 6 +++--- src/viam/sdk/tests/CMakeLists.txt | 6 ++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/viam/examples/modules/complex/CMakeLists.txt b/src/viam/examples/modules/complex/CMakeLists.txt index 6ac850332..ceaea9b3d 100644 --- a/src/viam/examples/modules/complex/CMakeLists.txt +++ b/src/viam/examples/modules/complex/CMakeLists.txt @@ -106,6 +106,7 @@ target_include_directories(complex_module_sources ) target_link_libraries(complex_module_sources viam-cpp-sdk::viamsdk + viam-cpp-sdk::viamapi ) add_executable(complex_module) diff --git a/src/viam/sdk/CMakeLists.txt b/src/viam/sdk/CMakeLists.txt index fe4d864ab..180db219f 100644 --- a/src/viam/sdk/CMakeLists.txt +++ b/src/viam/sdk/CMakeLists.txt @@ -15,7 +15,7 @@ add_library(viam-cpp-sdk::viamsdk ALIAS viamsdk) # `BASE_DIRS` below, because otherwise we will pull in the static # versions of the proto files even if we are generating dynamically. target_include_directories(viamsdk - PUBLIC + PRIVATE "$>" ) @@ -234,9 +234,9 @@ target_link_directories(viamsdk ) if (BUILD_SHARED_LIBS) - target_link_libraries(viamsdk PUBLIC viam-cpp-sdk::viamapi) + target_link_libraries(viamsdk PRIVATE viam-cpp-sdk::viamapi) else() - target_link_libraries(viamsdk PUBLIC "$") + target_link_libraries(viamsdk PRIVATE "$") endif() target_link_libraries(viamsdk diff --git a/src/viam/sdk/tests/CMakeLists.txt b/src/viam/sdk/tests/CMakeLists.txt index 8c16e0fdc..afa6c0573 100644 --- a/src/viam/sdk/tests/CMakeLists.txt +++ b/src/viam/sdk/tests/CMakeLists.txt @@ -39,8 +39,14 @@ target_sources(viamsdk_test test_utils.cpp ) +target_include_directories(viamsdk_test + PUBLIC + "$>" +) + target_link_libraries(viamsdk_test PUBLIC viam-cpp-sdk::viamsdk + PUBLIC viam-cpp-sdk::viamapi ) viamcppsdk_add_boost_test(test_arm.cpp) From 7ece1c8fa87c325f9ae474f3d69667250fb2179c Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Tue, 14 Jan 2025 10:34:04 -0500 Subject: [PATCH 2/5] re-group requires --- conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index b388f67db..b4fc51bbf 100644 --- a/conanfile.py +++ b/conanfile.py @@ -112,13 +112,13 @@ def package_info(self): self.cpp_info.components["viamapi"].sharedlinkflags.append(whole_archive) self.cpp_info.components["viamsdk"].requires.extend([ - "viamapi", "boost::headers", "boost::log", "grpc::grpc++_reflection", "protobuf::libprotobuf", "xtensor::xtensor", + "viamapi", "viam_rust_utils", "abseil::absl_strings", ]) From 3f32c12999a0fb8ed083544e613247ecbd6ed436 Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Tue, 14 Jan 2025 12:10:12 -0500 Subject: [PATCH 3/5] use helper function to link viam api --- src/viam/cmake/viamcppsdk_utils.cmake | 8 ++++++++ src/viam/examples/modules/complex/CMakeLists.txt | 3 ++- src/viam/sdk/CMakeLists.txt | 6 +----- src/viam/sdk/tests/CMakeLists.txt | 2 ++ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/viam/cmake/viamcppsdk_utils.cmake b/src/viam/cmake/viamcppsdk_utils.cmake index 15ef6d223..82957747d 100644 --- a/src/viam/cmake/viamcppsdk_utils.cmake +++ b/src/viam/cmake/viamcppsdk_utils.cmake @@ -17,3 +17,11 @@ function(viamcppsdk_add_boost_test SOURCE_FILE_NAME) COMMAND ${TEST_EXECUTABLE_NAME} --catch_system_error=yes) endforeach() endfunction() + +function(viamcppsdk_link_viam_api TARGET_LIBRARY) + if (BUILD_SHARED_LIBS) + target_link_libraries(${TARGET_LIBRARY} ${ARGV1} viam-cpp-sdk::viamapi) + else() + target_link_libraries(${TARGET_LIBRARY} ${ARGV1} "$") + endif() +endfunction() diff --git a/src/viam/examples/modules/complex/CMakeLists.txt b/src/viam/examples/modules/complex/CMakeLists.txt index ceaea9b3d..d8ad9bc5f 100644 --- a/src/viam/examples/modules/complex/CMakeLists.txt +++ b/src/viam/examples/modules/complex/CMakeLists.txt @@ -106,9 +106,10 @@ target_include_directories(complex_module_sources ) target_link_libraries(complex_module_sources viam-cpp-sdk::viamsdk - viam-cpp-sdk::viamapi ) +viamcppsdk_link_viam_api(complex_module_sources) + add_executable(complex_module) target_sources(complex_module PRIVATE diff --git a/src/viam/sdk/CMakeLists.txt b/src/viam/sdk/CMakeLists.txt index 180db219f..f1438fcfe 100644 --- a/src/viam/sdk/CMakeLists.txt +++ b/src/viam/sdk/CMakeLists.txt @@ -233,11 +233,7 @@ target_link_directories(viamsdk "$" ) -if (BUILD_SHARED_LIBS) - target_link_libraries(viamsdk PRIVATE viam-cpp-sdk::viamapi) -else() - target_link_libraries(viamsdk PRIVATE "$") -endif() +viamcppsdk_link_viam_api(viamsdk PRIVATE) target_link_libraries(viamsdk PUBLIC ${VIAMCPPSDK_GRPCXX_LIBRARIES} diff --git a/src/viam/sdk/tests/CMakeLists.txt b/src/viam/sdk/tests/CMakeLists.txt index afa6c0573..93d3fe14e 100644 --- a/src/viam/sdk/tests/CMakeLists.txt +++ b/src/viam/sdk/tests/CMakeLists.txt @@ -49,6 +49,8 @@ target_link_libraries(viamsdk_test PUBLIC viam-cpp-sdk::viamapi ) +viamcppsdk_link_viam_api(viamsdk_test PUBLIC) + viamcppsdk_add_boost_test(test_arm.cpp) viamcppsdk_add_boost_test(test_base.cpp) viamcppsdk_add_boost_test(test_board.cpp) From e9bbc32a15468204f3213d5bf49513d123b7ba8e Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Tue, 14 Jan 2025 12:14:26 -0500 Subject: [PATCH 4/5] remove duplicate link --- src/viam/sdk/tests/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/viam/sdk/tests/CMakeLists.txt b/src/viam/sdk/tests/CMakeLists.txt index 93d3fe14e..422b91f4a 100644 --- a/src/viam/sdk/tests/CMakeLists.txt +++ b/src/viam/sdk/tests/CMakeLists.txt @@ -46,7 +46,6 @@ target_include_directories(viamsdk_test target_link_libraries(viamsdk_test PUBLIC viam-cpp-sdk::viamsdk - PUBLIC viam-cpp-sdk::viamapi ) viamcppsdk_link_viam_api(viamsdk_test PUBLIC) From d940b1ace7949deffc9dd57dc702fa52cf386f0c Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Tue, 14 Jan 2025 13:52:58 -0500 Subject: [PATCH 5/5] include utils unconditionally --- CMakeLists.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf2a4a395..86793541a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,10 +194,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/src/viam/cmake ) -if (VIAMCPPSDK_BUILD_TESTS OR VIAMCPPSDK_BUILD_EXAMPLES) - # We maybe could include this unconditionally, but technically only tests or examples need it - include(viamcppsdk_utils) -endif() + +include(viamcppsdk_utils)