Skip to content

Commit b7856f4

Browse files
committed
support building examples straight from CMake
After the previous commit, the examples could be built using `make`. This commit adds support for building examples straight from CMake, by running `cmake -DCASS_BUILD_EXAMPLES=on -DCMAKE_BUILD_TYPE=Release ..` in the `build` directory. As here it's `CMake` that parses Makefile, not `make` that runs `CMake`, we need to extract the list of examples to run from the Makefile. This is done by running `make -p -n` and extracting the value of `SCYLLA_EXAMPLES_TO_RUN` variable.
1 parent be24192 commit b7856f4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ add_subdirectory(scylla-rust-wrapper)
240240
add_subdirectory(src)
241241

242242
if(CASS_BUILD_EXAMPLES)
243+
if(NOT DEFINED CASS_EXAMPLES_WHITELIST) # If someone runs CMake straight, not from the Makefile.
244+
execute_process(
245+
COMMAND make -f ../Makefile -p -n # Print the makefile's variables without executing it.
246+
COMMAND grep -E "^SCYLLA_EXAMPLES_TO_RUN :=" # Find the list of examples to run.
247+
COMMAND awk -F ":= " "{print $2}" # Extract the value after the ":=", which is a whitespace-separated list.
248+
OUTPUT_VARIABLE SCYLLA_EXAMPLES_TO_RUN
249+
OUTPUT_STRIP_TRAILING_WHITESPACE
250+
)
251+
string(REPLACE " " ";" CASS_EXAMPLES_WHITELIST ${SCYLLA_EXAMPLES_TO_RUN})
252+
endif()
243253
message(STATUS "Using CASS_EXAMPLES_WHITELIST: ${CASS_EXAMPLES_WHITELIST}")
244254

245255
# Get all example directories

0 commit comments

Comments
 (0)