Skip to content

Commit 8951f32

Browse files
committed
feat: permit use of system rapidyaml
Signed-off-by: Pat Riehecky <[email protected]>
1 parent 1b19a35 commit 8951f32

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ option(BUILD_SHARED_BINARIES "Link binaries to the shared libjsonnet instead of
5050
option(BUILD_MAN_PAGES "Build manpages." ON)
5151
option(USE_SYSTEM_GTEST "Use system-provided gtest library" OFF)
5252
option(USE_SYSTEM_JSON "Use the system-provided json library" OFF)
53-
# TODO: Support using a system Rapid YAML install.
53+
option(USE_SYSTEM_RAPIDYAML "Use the system-provided rapidyaml library" OFF)
5454

5555
#### Compute derived values from user-configurable state.
5656
#
@@ -69,6 +69,10 @@ if(USE_SYSTEM_JSON)
6969
find_package(nlohmann_json 3.6.1 REQUIRED)
7070
endif()
7171

72+
if(USE_SYSTEM_RAPIDYAML)
73+
find_package(ryml REQUIRED)
74+
endif()
75+
7276
#### Utility function to configure a target with our preferred C and C++ compilation flags.
7377
#
7478

@@ -108,9 +112,6 @@ function(configure_jsonnet_obj_target LIB_TARGET_NAME)
108112
third_party/md5/md5.h
109113
third_party/md5/md5.cpp
110114

111-
third_party/rapidyaml/rapidyaml-0.10.0.hpp
112-
third_party/rapidyaml/rapidyaml.cpp
113-
114115
core/static_error.h
115116
core/desugarer.h
116117
core/unicode.h
@@ -155,13 +156,24 @@ function(configure_jsonnet_obj_target LIB_TARGET_NAME)
155156
SYSTEM PRIVATE third_party/json)
156157
endif()
157158

159+
if(USE_SYSTEM_RAPIDYAML)
160+
target_link_libraries(${LIB_TARGET_NAME} PRIVATE ryml::ryml)
161+
target_compile_definitions(${LIB_TARGET_NAME} PRIVATE USE_SYSTEM_RAPIDYAML)
162+
else()
163+
target_sources(${LIB_TARGET_NAME}
164+
PRIVATE
165+
third_party/rapidyaml/rapidyaml-0.10.0.hpp
166+
third_party/rapidyaml/rapidyaml.cpp
167+
)
168+
endif()
169+
158170
target_include_directories(${LIB_TARGET_NAME}
159171
PUBLIC
160172
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
161173
$<INSTALL_INTERFACE:include>
162174
PRIVATE
163175
third_party/md5
164-
third_party/rapidyaml
176+
$<$<NOT:$<BOOL:${USE_SYSTEM_RAPIDYAML}>>:${CMAKE_CURRENT_SOURCE_DIR}/third_party/rapidyaml>
165177
)
166178
endfunction()
167179

core/vm.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ limitations under the License.
2929
#include <nlohmann/json.hpp>
3030
#include "md5.h"
3131
#include "parser.h"
32+
#ifdef USE_SYSTEM_RAPIDYAML
33+
#include <ryml.hpp>
34+
#else
3235
#include "rapidyaml-0.10.0.hpp"
36+
#endif
3337
#include "state.h"
3438
#include "static_analysis.h"
3539
#include "static_error.h"

0 commit comments

Comments
 (0)