Skip to content

Commit 3f32c12

Browse files
committed
use helper function to link viam api
1 parent 7ece1c8 commit 3f32c12

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

src/viam/cmake/viamcppsdk_utils.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ function(viamcppsdk_add_boost_test SOURCE_FILE_NAME)
1717
COMMAND ${TEST_EXECUTABLE_NAME} --catch_system_error=yes)
1818
endforeach()
1919
endfunction()
20+
21+
function(viamcppsdk_link_viam_api TARGET_LIBRARY)
22+
if (BUILD_SHARED_LIBS)
23+
target_link_libraries(${TARGET_LIBRARY} ${ARGV1} viam-cpp-sdk::viamapi)
24+
else()
25+
target_link_libraries(${TARGET_LIBRARY} ${ARGV1} "$<LINK_LIBRARY:WHOLE_ARCHIVE,viam-cpp-sdk::viamapi>")
26+
endif()
27+
endfunction()

src/viam/examples/modules/complex/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ target_include_directories(complex_module_sources
106106
)
107107
target_link_libraries(complex_module_sources
108108
viam-cpp-sdk::viamsdk
109-
viam-cpp-sdk::viamapi
110109
)
111110

111+
viamcppsdk_link_viam_api(complex_module_sources)
112+
112113
add_executable(complex_module)
113114
target_sources(complex_module
114115
PRIVATE

src/viam/sdk/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,7 @@ target_link_directories(viamsdk
233233
"$<INSTALL_INTERFACE:${VIAMCPPSDK_PROTOBUF_LIBRARY_DIRS}>"
234234
)
235235

236-
if (BUILD_SHARED_LIBS)
237-
target_link_libraries(viamsdk PRIVATE viam-cpp-sdk::viamapi)
238-
else()
239-
target_link_libraries(viamsdk PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,viam-cpp-sdk::viamapi>")
240-
endif()
236+
viamcppsdk_link_viam_api(viamsdk PRIVATE)
241237

242238
target_link_libraries(viamsdk
243239
PUBLIC ${VIAMCPPSDK_GRPCXX_LIBRARIES}

src/viam/sdk/tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ target_link_libraries(viamsdk_test
4949
PUBLIC viam-cpp-sdk::viamapi
5050
)
5151

52+
viamcppsdk_link_viam_api(viamsdk_test PUBLIC)
53+
5254
viamcppsdk_add_boost_test(test_arm.cpp)
5355
viamcppsdk_add_boost_test(test_base.cpp)
5456
viamcppsdk_add_boost_test(test_board.cpp)

0 commit comments

Comments
 (0)