Skip to content

Commit 86d426d

Browse files
committed
Improve C++ build system
1 parent 659efa6 commit 86d426d

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

cpp/CMakeLists.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# RCDB_TEST_CONNECTION="sqlite:///<path-to>.sqlite" ./build/test_rcdb_cpp
88
# Create the test database with: rcdb -c sqlite:///<path-to>.sqlite db init --add-cpp-tests --confirm
99

10-
cmake_minimum_required(VERSION 3.5)
10+
cmake_minimum_required(VERSION 3.10)
1111
project(rcdb_cpp)
1212

1313
option(WITH_MYSQL "Compile with MySQL support" OFF)
@@ -95,18 +95,26 @@ if(WITH_SQLITE)
9595
list(APPEND TEST_SOURCE_FILES tests/test_sqlite_unity.cpp)
9696
endif()
9797

98+
# Read examples and tests build with either backend (SQLite is the default).
9899
add_executable(test_rcdb_cpp ${TEST_SOURCE_FILES})
99100
add_executable(examples_simple examples/simple.cpp)
100101
add_executable(examples_trigger_params examples/get_trigger_params.cpp)
101102
add_executable(examples_fadc_masks examples/get_fadc_masks.cpp)
102-
add_executable(examples_write_conditions examples/write_conditions.cpp)
103-
add_executable(examples_write_array_to_json examples/write_array_to_json.cpp)
104-
add_executable(examples_write_objects_to_json examples/write_objects_to_json.cpp)
105103

106104
target_link_libraries(test_rcdb_cpp ${DB_REQIRED_LIBRARIES} dl pthread sqlite3)
107105
target_link_libraries(examples_trigger_params ${DB_REQIRED_LIBRARIES} dl pthread)
108106
target_link_libraries(examples_simple ${DB_REQIRED_LIBRARIES} dl pthread)
109107
target_link_libraries(examples_fadc_masks ${DB_REQIRED_LIBRARIES} dl pthread)
110-
target_link_libraries(examples_write_conditions ${DB_REQIRED_LIBRARIES} dl pthread)
111-
target_link_libraries(examples_write_array_to_json ${DB_REQIRED_LIBRARIES} dl pthread)
112-
target_link_libraries(examples_write_objects_to_json ${DB_REQIRED_LIBRARIES} dl pthread)
108+
109+
# Writing to RCDB from C++ goes through WritingConnection, which is MySQL-only
110+
# (the SQLite provider is read-only). So the write examples are built only when
111+
# MySQL support is enabled.
112+
if(WITH_MYSQL)
113+
add_executable(examples_write_conditions examples/write_conditions.cpp)
114+
add_executable(examples_write_array_to_json examples/write_array_to_json.cpp)
115+
add_executable(examples_write_objects_to_json examples/write_objects_to_json.cpp)
116+
117+
target_link_libraries(examples_write_conditions ${DB_REQIRED_LIBRARIES} dl pthread)
118+
target_link_libraries(examples_write_array_to_json ${DB_REQIRED_LIBRARIES} dl pthread)
119+
target_link_libraries(examples_write_objects_to_json ${DB_REQIRED_LIBRARIES} dl pthread)
120+
endif()

cpp/examples/write_objects_to_json.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <iostream>
88

99
#include "RCDB/WritingConnection.h"
10+
#include "RCDB/StringUtils.h"
1011
#include <tao/json.hpp>
1112

1213
using namespace tao;

docs/Cpp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ targets (e.g. `examples_trigger_params`). There is no separate install step or c
146146
* Getting RCDB stored files contents
147147
* Working with config file parser
148148
* [get_fadc_masks.cpp](https://github.com/JeffersonLab/rcdb/blob/main/cpp/examples/get_fadc_masks.cpp) (target `examples_fadc_masks`) - Reading FADC masks
149+
150+
Writing to RCDB from C++ goes through `WritingConnection`, which is **MySQL-only** (the
151+
SQLite provider is read-only). The following write examples are therefore built only when
152+
configured with `-DWITH_MYSQL=ON`:
153+
149154
* [write_conditions.cpp](https://github.com/JeffersonLab/rcdb/blob/main/cpp/examples/write_conditions.cpp) (target `examples_write_conditions`) - Writing conditions to RCDB from C++. It includes:
150155
* Using WritingConnection
151156
* Adding condition values of different types

0 commit comments

Comments
 (0)