Skip to content

Commit b8e063f

Browse files
authored
cleanup: simplify examples/ CMake files (#11932)
Always `add_subdirectory(examples)` and let that directory decide what it can build.
1 parent 02bc62b commit b8e063f

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,7 @@ endif ()
240240
add_subdirectory(google/cloud)
241241
google_cloud_cpp_enable_features()
242242

243-
# The examples are more readable if we use exceptions for error handling. We had
244-
# to tradeoff readability vs. "making them compile everywhere".
245-
if (GOOGLE_CLOUD_CPP_ENABLE_EXAMPLES
246-
AND bigtable IN_LIST GOOGLE_CLOUD_CPP_ENABLE
247-
AND iam IN_LIST GOOGLE_CLOUD_CPP_ENABLE
248-
AND spanner IN_LIST GOOGLE_CLOUD_CPP_ENABLE
249-
AND storage IN_LIST GOOGLE_CLOUD_CPP_ENABLE)
250-
add_subdirectory(examples)
251-
endif ()
243+
add_subdirectory(examples)
252244

253245
# Obsolete / retired flags and options. Removing them just cleans up a bit of
254246
# our code at the cost of breaking customers, while putting them here makes them

examples/CMakeLists.txt

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,29 @@
1414
# limitations under the License.
1515
# ~~~
1616

17+
# The examples are more readable if we use exceptions for error handling. We had
18+
# to tradeoff readability vs. "making them compile everywhere".
19+
if (NOT GOOGLE_CLOUD_CPP_ENABLE_EXAMPLES)
20+
return()
21+
endif ()
22+
1723
# Pick the right MSVC runtime libraries.
1824
include(SelectMSVCRuntime)
1925

20-
add_executable(gcs2cbt gcs2cbt.cc)
21-
target_link_libraries(gcs2cbt google-cloud-cpp::bigtable
22-
google-cloud-cpp::storage google-cloud-cpp::grpc_utils)
23-
google_cloud_cpp_add_common_options(gcs2cbt)
26+
if (bigtable IN_LIST GOOGLE_CLOUD_CPP_ENABLE AND storage IN_LIST
27+
GOOGLE_CLOUD_CPP_ENABLE)
28+
add_executable(gcs2cbt gcs2cbt.cc)
29+
target_link_libraries(
30+
gcs2cbt google-cloud-cpp::bigtable google-cloud-cpp::storage
31+
google-cloud-cpp::grpc_utils)
32+
google_cloud_cpp_add_common_options(gcs2cbt)
33+
endif ()
2434

25-
if (BUILD_TESTING)
26-
include(FindCurlWithTargets)
27-
include(FindgRPC)
35+
include(FindCurlWithTargets)
36+
include(FindgRPC)
2837

38+
if (spanner IN_LIST GOOGLE_CLOUD_CPP_ENABLE AND iam IN_LIST
39+
GOOGLE_CLOUD_CPP_ENABLE)
2940
google_cloud_cpp_grpcpp_library(
3041
hello_world_protos "hello_world_grpc/hello_world.proto"
3142
PROTO_PATH_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR})
@@ -38,11 +49,19 @@ if (BUILD_TESTING)
3849
PRIVATE hello_world_protos google_cloud_cpp_testing
3950
google-cloud-cpp::iam google-cloud-cpp::spanner CURL::libcurl)
4051
google_cloud_cpp_add_common_options(grpc_credential_types)
52+
endif ()
4153

42-
foreach (test gcs2cbt grpc_credential_types)
43-
add_test(NAME ${test} COMMAND ${test})
44-
set_tests_properties(
45-
${test} PROPERTIES LABELS
46-
"integration-test;integration-test-production")
47-
endforeach ()
54+
# Label all the binaries as "tests", so they run in our CI builds.
55+
if (NOT BUILD_TESTING)
56+
return()
4857
endif ()
58+
59+
foreach (test gcs2cbt grpc_credential_types)
60+
if (NOT TARGET "${test}")
61+
continue()
62+
endif ()
63+
add_test(NAME ${test} COMMAND ${test})
64+
set_tests_properties(
65+
${test} PROPERTIES LABELS
66+
"integration-test;integration-test-production")
67+
endforeach ()

0 commit comments

Comments
 (0)