Skip to content

Commit be24192

Browse files
committed
build system: support building examples
CMakeLists.txt and Makefile have been updated to support building examples. The Makefile now includes a variable `SCYLLA_EXAMPLES_TO_RUN`, which lists the examples that are expected to run successfully. Those examples will be built when the `build-examples` target is invoked. CMakeLists.txt has been modified to conditionally add example subdirectories based on the `CASS_EXAMPLES_WHITELIST` variable, which is populated from the `SCYLLA_EXAMPLES_TO_RUN` variable in the Makefile. What is now possible after this commit is to build specific examples using the `build-examples` target in the Makefile. Also, it's possible to conveniently override the list of examples to build: `make run-examples SCYLLA_EXAMPLES_TO_RUN="basic callbacks"`
1 parent 4794cca commit be24192

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

CMakeLists.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ if(CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_UNIT_TESTS)
6969
set(CASS_USE_LIBUV ON)
7070
endif()
7171

72+
if(CASS_BUILD_EXAMPLES)
73+
set(CASS_USE_LIBUV ON) # Some examples require libuv, e.g. "callbacks".
74+
endif()
75+
7276
# Determine which driver target should be used as a dependency
7377
set(PROJECT_LIB_NAME_TARGET scylla-cpp-driver)
7478
if(CASS_USE_STATIC_LIBS OR
@@ -236,7 +240,22 @@ add_subdirectory(scylla-rust-wrapper)
236240
add_subdirectory(src)
237241

238242
if(CASS_BUILD_EXAMPLES)
239-
add_subdirectory(examples)
243+
message(STATUS "Using CASS_EXAMPLES_WHITELIST: ${CASS_EXAMPLES_WHITELIST}")
244+
245+
# Get all example directories
246+
file(GLOB EXAMPLE_DIRS "${CASS_ROOT_DIR}/examples/*")
247+
248+
foreach(EXAMPLE_DIR ${EXAMPLE_DIRS})
249+
get_filename_component(EXAMPLE_NAME ${EXAMPLE_DIR} NAME)
250+
251+
# Check whitelist
252+
if(IS_DIRECTORY ${EXAMPLE_DIR})
253+
if(CASS_EXAMPLES_WHITELIST STREQUAL "" OR EXAMPLE_NAME IN_LIST CASS_EXAMPLES_WHITELIST)
254+
message(STATUS "Adding example subdirectory ${EXAMPLE_DIR}, example name ${EXAMPLE_NAME}")
255+
add_subdirectory(${EXAMPLE_DIR})
256+
endif()
257+
endif()
258+
endforeach()
240259
endif()
241260

242261
if(CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_TESTS)

Makefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,38 @@ CASSANDRA_NO_VALGRIND_TEST_FILTER := $(subst ${SPACE},${EMPTY},AsyncTests.Integr
120120
:HeartbeatTests.Integration_Cassandra_HeartbeatFailed)
121121
endif
122122

123+
ifndef SCYLLA_EXAMPLES_TO_RUN
124+
SCYLLA_EXAMPLES_TO_RUN := \
125+
async \
126+
basic \
127+
batch \
128+
bind_by_name \
129+
collections \
130+
concurrent_executions \
131+
date_time \
132+
duration \
133+
maps \
134+
named_parameters \
135+
paging \
136+
prepared \
137+
simple \
138+
ssl \
139+
tracing \
140+
tuple \
141+
udt \
142+
uuids \
143+
144+
# auth <- unimplemented `cass_cluster_set_authenticator_callbacks()`
145+
# callbacks <- panics due to bug in future management - attempting to block in async context
146+
# execution_profiles <- unimplemented `cass_statement_set_keyspace()`
147+
# host_listener <- unimplemented `cass_cluster_set_host_listener_callback()`
148+
# logging <- unimplemented `cass_cluster_set_host_listener_callback()`
149+
# perf <- unimplemented `cass_cluster_set_num_threads_io()`, `cass_cluster_set_queue_size_io()`
150+
# schema_meta <- unimplemented multiple schema-related functions
151+
# cloud <- out of interest for us, not related to ScyllaDB
152+
# dse <- out of interest for us, not related to ScyllaDB
153+
endif
154+
123155
ifndef CCM_COMMIT_ID
124156
export CCM_COMMIT_ID := master
125157
endif
@@ -206,6 +238,16 @@ build-integration-test-bin-if-missing:
206238
cmake -DCASS_BUILD_INTEGRATION_TESTS=ON -DCMAKE_BUILD_TYPE=Release .. && (make -j 4 || make);\
207239
}
208240

241+
SCYLLA_EXAMPLES_TO_RUN_SEMICOLON_SEPARATED := $(subst ${SPACE},;,${SCYLLA_EXAMPLES_TO_RUN})
242+
243+
build-examples:
244+
@{\
245+
echo "Building examples to ${EXAMPLES_DIR}";\
246+
mkdir "${BUILD_DIR}" >/dev/null 2>&1 || true;\
247+
cd "${BUILD_DIR}";\
248+
cmake -DCASS_EXAMPLES_WHITELIST="${SCYLLA_EXAMPLES_TO_RUN_SEMICOLON_SEPARATED}" -DCASS_BUILD_EXAMPLES=on -DCMAKE_BUILD_TYPE=Release .. && (make -j 4 || make);\
249+
}
250+
209251
_update-rust-tooling:
210252
@echo "Run rustup update"
211253
@rustup update

0 commit comments

Comments
 (0)