@@ -50,7 +50,7 @@ option(BUILD_SHARED_BINARIES "Link binaries to the shared libjsonnet instead of
5050option (BUILD_MAN_PAGES "Build manpages." ON )
5151option (USE_SYSTEM_GTEST "Use system-provided gtest library" OFF )
5252option (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 )
7070endif ()
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 )
166178endfunction ()
167179
0 commit comments