Skip to content

Commit 4fedc5f

Browse files
committed
cmake/add_obx_schema: support for CXX_STANDARD and EXTRA_OPTIONS
1 parent 969ff1b commit 4fedc5f

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

cmake/FindObjectBoxGenerator.cmake

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ adds them as sources to the target for compilation::
4242
TARGET <target>
4343
SCHEMA_FILES <schemafile>..
4444
[INSOURCE]
45+
[CXX_STANDARD 11|14]
46+
[EXTRA_OPTIONS <options>..]
4547
)
4648
4749
ObjectBox schema files have the filename pattern ``<name>.fbs``
@@ -56,6 +58,12 @@ In additon the generator also creates and updates the files
5658
``objectbox-model.h`` and ``objectbox-model.json`` next to the
5759
generated C++ source/header files.
5860
61+
The option ``CXX_STANDARD`` may be set to ``11`` or ``14`` (default) to specify
62+
the base-line C++ language standard the code generator supports for generated
63+
code.
64+
65+
The option ``EXTRA_OPTIONS`` may pass additional arguments when invoking the code generator (e.g. "-empty-string-as-null -optional std::shared_ptr")
66+
5967
.. _ObjectBox: https://objectbox.io
6068
6169
.. _ObjectBoxGenerator: https://github.com/objectbox/objectbox-generator
@@ -181,8 +189,8 @@ endif()
181189
function (add_obx_schema)
182190

183191
set(options INSOURCE)
184-
set(oneValueArgs TARGET)
185-
set(multiValueArgs SCHEMA_FILES)
192+
set(oneValueArgs TARGET;CXX_STANDARD)
193+
set(multiValueArgs SCHEMA_FILES;EXTRA_OPTIONS)
186194
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
187195

188196
if (ARG_INSOURCE)
@@ -193,6 +201,17 @@ function (add_obx_schema)
193201

194202
set(sources)
195203

204+
set(lang -cpp)
205+
if(ARG_CXX_STANDARD)
206+
if(ARG_CXX_STANDARD EQUAL 11)
207+
set(lang -cpp${ARG_CXX_STANDARD})
208+
elseif(ARG_CXX_STANDARD EQUAL 14)
209+
set(lang -cpp)
210+
else()
211+
message(WARNING "ObjectBoxGenerator: CXX_STANDARD ${ARG_CXX_STANDARD} not supported, available are: 11 and 14. Defaults to 14.")
212+
endif()
213+
endif()
214+
196215
foreach(SCHEMA_FILE ${ARG_SCHEMA_FILES})
197216

198217
# 3.20: cmake_path(ABSOLUTE_PATH SCHEMA_FILE OUTPUT_VARIABLE schema_filepath)
@@ -212,7 +231,7 @@ function (add_obx_schema)
212231
${cppfile}
213232
${hppfile}
214233
COMMAND
215-
${ObjectBoxGenerator_EXECUTABLE} ARGS -out ${out_dir} -cpp ${schema_filepath}
234+
${ObjectBoxGenerator_EXECUTABLE} ARGS -out ${out_dir} ${lang} ${ARG_EXTRA_OPTIONS} ${schema_filepath}
216235
BYPRODUCTS
217236
${out_dir}/objectbox-model.h
218237
${out_dir}/objectbox-model.json

0 commit comments

Comments
 (0)