Skip to content

RSDK-9707: Make API a private dependency of SDK #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
])
Expand Down
8 changes: 8 additions & 0 deletions src/viam/cmake/viamcppsdk_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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} "$<LINK_LIBRARY:WHOLE_ARCHIVE,viam-cpp-sdk::viamapi>")
endif()
endfunction()
2 changes: 2 additions & 0 deletions src/viam/examples/modules/complex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ target_link_libraries(complex_module_sources
viam-cpp-sdk::viamsdk
)

viamcppsdk_link_viam_api(complex_module_sources)

add_executable(complex_module)
target_sources(complex_module
PRIVATE
Expand Down
8 changes: 2 additions & 6 deletions src/viam/sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

"$<BUILD_INTERFACE:$<TARGET_PROPERTY:viam-cpp-sdk::viamapi,INTERFACE_INCLUDE_DIRECTORIES>>"
)

Expand Down Expand Up @@ -233,11 +233,7 @@ target_link_directories(viamsdk
"$<INSTALL_INTERFACE:${VIAMCPPSDK_PROTOBUF_LIBRARY_DIRS}>"
)

if (BUILD_SHARED_LIBS)
target_link_libraries(viamsdk PUBLIC viam-cpp-sdk::viamapi)
else()
target_link_libraries(viamsdk PUBLIC "$<LINK_LIBRARY:WHOLE_ARCHIVE,viam-cpp-sdk::viamapi>")
endif()
viamcppsdk_link_viam_api(viamsdk PRIVATE)

target_link_libraries(viamsdk
PUBLIC ${VIAMCPPSDK_GRPCXX_LIBRARIES}
Expand Down
7 changes: 7 additions & 0 deletions src/viam/sdk/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ target_sources(viamsdk_test
test_utils.cpp
)

target_include_directories(viamsdk_test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a goal to eventually make the tests not know about viamapi either, or, considered harmless?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doable but considered harmless!

PUBLIC
"$<BUILD_INTERFACE:$<TARGET_PROPERTY:viam-cpp-sdk::viamapi,INTERFACE_INCLUDE_DIRECTORIES>>"
)

target_link_libraries(viamsdk_test
PUBLIC viam-cpp-sdk::viamsdk
)

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)
Expand Down
Loading