@@ -47,6 +47,16 @@ project(viam-cpp-sdk
4747 LANGUAGES CXX
4848)
4949
50+ # Detect if we're building as a standalone module
51+ # vs being included via FetchContent by a downstream consumer
52+ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
53+ set (VIAMCPPSDK_STANDALONE_BUILD ON )
54+ message (STATUS "viam-cpp-sdk: Standalone build mode" )
55+ else ()
56+ set (VIAMCPPSDK_STANDALONE_BUILD OFF )
57+ message (STATUS "viam-cpp-sdk: FetchContent mode (included by parent project)" )
58+ endif ()
59+
5060
5161# Configure cmake-level options:
5262
@@ -113,7 +123,7 @@ option(VIAMCPPSDK_USE_LOCAL_PROTOS "Generate protos against sibling `api` direct
113123# This causes the SDK's internal code to compile with `-Wall` and
114124# `-Werror` flags.
115125#
116- option (VIAMCPPSDK_USE_WALL_WERROR "Build with -Wall and -Werror flags" ON )
126+ option (VIAMCPPSDK_USE_WALL_WERROR "Build with -Wall and -Werror flags" ${VIAMCPPSDK_STANDALONE_BUILD} )
117127
118128
119129# - `VIAMCPPSDK_SANITIZED_BUILD`
@@ -141,11 +151,15 @@ option(VIAMCPPSDK_CLANG_TIDY "Run the clang-tidy linter" OFF)
141151#
142152option (VIAMCPPSDK_OPENTELEMETRY_TRACING "Compile OpenTelemetry tracing into all gRPC calls" OFF )
143153
144- # The following options are only defined if this project is not being included as a subproject
145- if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR )
146- option (VIAMCPPSDK_BUILD_EXAMPLES "Build the example executables" ON )
147- option (VIAMCPPSDK_BUILD_TESTS "Build the example executables" ON )
148- endif ()
154+ # - `VIAMCPPSDK_BUILD_EXAMPLES `
155+ #
156+ # Defaults to ON for standalone builds, OFF for FetchContent consumers.
157+ option (VIAMCPPSDK_BUILD_EXAMPLES "Build the example executables" ${VIAMCPPSDK_STANDALONE_BUILD} )
158+
159+ # - `VIAMCPPSDK_BUILD_TESTS `
160+ #
161+ # Defaults to ON for standalone builds, OFF for FetchContent consumers.
162+ option (VIAMCPPSDK_BUILD_TESTS "Build the example executables" ${VIAMCPPSDK_STANDALONE_BUILD} )
149163
150164
151165# Enforce known toolchains and toolchain minima unless asked not to.
0 commit comments