Skip to content

Commit

Permalink
cmake/add_obx_schema: support for CXX_STANDARD and EXTRA_OPTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-obx committed Jul 19, 2024
1 parent 969ff1b commit 4fedc5f
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions cmake/FindObjectBoxGenerator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ adds them as sources to the target for compilation::
TARGET <target>
SCHEMA_FILES <schemafile>..
[INSOURCE]
[CXX_STANDARD 11|14]
[EXTRA_OPTIONS <options>..]
)
ObjectBox schema files have the filename pattern ``<name>.fbs``
Expand All @@ -56,6 +58,12 @@ In additon the generator also creates and updates the files
``objectbox-model.h`` and ``objectbox-model.json`` next to the
generated C++ source/header files.
The option ``CXX_STANDARD`` may be set to ``11`` or ``14`` (default) to specify
the base-line C++ language standard the code generator supports for generated
code.
The option ``EXTRA_OPTIONS`` may pass additional arguments when invoking the code generator (e.g. "-empty-string-as-null -optional std::shared_ptr")
.. _ObjectBox: https://objectbox.io
.. _ObjectBoxGenerator: https://github.com/objectbox/objectbox-generator
Expand Down Expand Up @@ -181,8 +189,8 @@ endif()
function (add_obx_schema)

set(options INSOURCE)
set(oneValueArgs TARGET)
set(multiValueArgs SCHEMA_FILES)
set(oneValueArgs TARGET;CXX_STANDARD)
set(multiValueArgs SCHEMA_FILES;EXTRA_OPTIONS)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if (ARG_INSOURCE)
Expand All @@ -193,6 +201,17 @@ function (add_obx_schema)

set(sources)

set(lang -cpp)
if(ARG_CXX_STANDARD)
if(ARG_CXX_STANDARD EQUAL 11)
set(lang -cpp${ARG_CXX_STANDARD})
elseif(ARG_CXX_STANDARD EQUAL 14)
set(lang -cpp)
else()
message(WARNING "ObjectBoxGenerator: CXX_STANDARD ${ARG_CXX_STANDARD} not supported, available are: 11 and 14. Defaults to 14.")
endif()
endif()

foreach(SCHEMA_FILE ${ARG_SCHEMA_FILES})

# 3.20: cmake_path(ABSOLUTE_PATH SCHEMA_FILE OUTPUT_VARIABLE schema_filepath)
Expand All @@ -212,7 +231,7 @@ function (add_obx_schema)
${cppfile}
${hppfile}
COMMAND
${ObjectBoxGenerator_EXECUTABLE} ARGS -out ${out_dir} -cpp ${schema_filepath}
${ObjectBoxGenerator_EXECUTABLE} ARGS -out ${out_dir} ${lang} ${ARG_EXTRA_OPTIONS} ${schema_filepath}
BYPRODUCTS
${out_dir}/objectbox-model.h
${out_dir}/objectbox-model.json
Expand Down

0 comments on commit 4fedc5f

Please sign in to comment.