2023-07-23 21:08:09 +02:00
|
|
|
cmake_minimum_required(VERSION 3.17.0 FATAL_ERROR)
|
2017-10-18 23:07:17 +02:00
|
|
|
|
|
|
|
# metadata
|
2017-10-25 17:41:19 +02:00
|
|
|
set(META_PROJECT_NAME reflective_rapidjson_generator)
|
2017-10-18 23:07:17 +02:00
|
|
|
set(META_PROJECT_TYPE application)
|
|
|
|
set(LINK_TESTS_AGAINST_APP_TARGET ON)
|
|
|
|
|
|
|
|
# add project files
|
|
|
|
set(HEADER_FILES
|
2017-10-25 15:38:45 +02:00
|
|
|
codegenerator.h
|
2018-06-23 18:04:30 +02:00
|
|
|
serializationcodegenerator.h
|
2017-10-28 16:31:07 +02:00
|
|
|
jsonserializationcodegenerator.h
|
2018-06-23 17:25:30 +02:00
|
|
|
binaryserializationcodegenerator.h
|
2017-10-25 15:38:45 +02:00
|
|
|
codefactory.h
|
2017-10-21 00:32:42 +02:00
|
|
|
frontendaction.h
|
|
|
|
consumer.h
|
|
|
|
visitor.h
|
2019-02-09 21:25:11 +01:00
|
|
|
clangversionabstraction.h)
|
2017-10-18 23:07:17 +02:00
|
|
|
set(SRC_FILES
|
2017-10-25 15:38:45 +02:00
|
|
|
codegenerator.cpp
|
2018-06-23 18:04:30 +02:00
|
|
|
serializationcodegenerator.cpp
|
2017-10-28 16:31:07 +02:00
|
|
|
jsonserializationcodegenerator.cpp
|
2018-06-23 17:25:30 +02:00
|
|
|
binaryserializationcodegenerator.cpp
|
2017-10-25 15:38:45 +02:00
|
|
|
codefactory.cpp
|
2017-10-21 00:32:42 +02:00
|
|
|
frontendaction.cpp
|
|
|
|
consumer.cpp
|
|
|
|
clangversionabstraction.cpp
|
|
|
|
visitor.cpp
|
2019-02-09 21:25:11 +01:00
|
|
|
main.cpp)
|
|
|
|
set(TEST_HEADER_FILES tests/helper.h)
|
|
|
|
set(TEST_SRC_FILES tests/binarygenerator.cpp)
|
2017-10-18 23:07:17 +02:00
|
|
|
|
2017-11-17 22:04:01 +01:00
|
|
|
# add JSON-specific test cases
|
2019-02-09 21:25:11 +01:00
|
|
|
if (RapidJSON_FOUND)
|
|
|
|
list(APPEND TEST_HEADER_FILES tests/structs.h tests/morestructs.h)
|
|
|
|
list(APPEND TEST_SRC_FILES tests/jsongenerator.cpp)
|
|
|
|
endif ()
|
2017-11-17 22:04:01 +01:00
|
|
|
|
2017-11-17 21:21:34 +01:00
|
|
|
# link against c++utilities
|
2017-10-18 23:07:17 +02:00
|
|
|
use_cpp_utilities()
|
|
|
|
|
2019-11-14 17:18:49 +01:00
|
|
|
# find Clang for LibTooling
|
2017-10-18 23:07:17 +02:00
|
|
|
find_package(Clang REQUIRED)
|
2019-11-14 17:18:49 +01:00
|
|
|
if (TARGET clang-cpp)
|
|
|
|
list(APPEND PRIVATE_LIBRARIES clang-cpp LLVM)
|
|
|
|
else ()
|
|
|
|
list(
|
2020-01-26 20:42:03 +01:00
|
|
|
APPEND
|
|
|
|
PRIVATE_LIBRARIES
|
|
|
|
clangTooling
|
|
|
|
clangFrontend
|
|
|
|
clangSerialization
|
|
|
|
clangSema
|
|
|
|
clangAST
|
|
|
|
clangLex
|
|
|
|
clangBasic
|
|
|
|
LLVM)
|
2019-11-14 17:18:49 +01:00
|
|
|
endif ()
|
2017-10-21 00:32:42 +02:00
|
|
|
|
2017-10-28 18:24:12 +02:00
|
|
|
# also add reflective_rapidjson which is header-only but might pull additional include dirs for RapidJSON
|
2020-01-31 19:27:15 +01:00
|
|
|
list(APPEND PRIVATE_LIBRARIES "${REFLECTIVE_RAPIDJSON_TARGET_NAME}")
|
2017-10-18 23:07:17 +02:00
|
|
|
|
2022-05-12 20:23:33 +02:00
|
|
|
# avoid warning "'this' pointer is null" from GCC 12 about code included from libclang
|
|
|
|
list(APPEND META_PRIVATE_COMPILE_OPTIONS "-Wno-error=nonnull")
|
|
|
|
|
2017-11-03 22:41:51 +01:00
|
|
|
# include modules to apply configuration
|
|
|
|
include(BasicConfig)
|
|
|
|
include(WindowsResources)
|
|
|
|
include(AppTarget)
|
2017-10-18 23:07:17 +02:00
|
|
|
include(TestTarget)
|
|
|
|
include(ShellCompletion)
|
2017-10-23 00:41:10 +02:00
|
|
|
include(Doxygen)
|
2017-11-17 22:01:18 +01:00
|
|
|
|
2018-01-20 19:46:17 +01:00
|
|
|
# trigger code generator for tests because the tests already contain structs to be (de)serialized
|
2020-01-31 19:27:15 +01:00
|
|
|
if (TARGET "${META_TARGET_NAME}_tests")
|
2018-01-20 19:46:17 +01:00
|
|
|
include(ReflectionGenerator)
|
2019-02-09 21:25:11 +01:00
|
|
|
# cmake-format: off
|
2018-01-20 19:46:17 +01:00
|
|
|
add_reflection_generator_invocation(
|
|
|
|
INPUT_FILES
|
|
|
|
tests/structs.h # used by test cases
|
|
|
|
tests/morestructs.h # used by test cases
|
2019-01-13 22:27:35 +01:00
|
|
|
visitor.cpp # arbitrarily chosen source file (just for testing the "no relevant structs/classes" case)
|
2018-01-20 19:46:17 +01:00
|
|
|
GENERATORS
|
|
|
|
json
|
2018-06-23 17:25:30 +02:00
|
|
|
binary
|
2018-01-20 19:46:17 +01:00
|
|
|
OUTPUT_LISTS
|
|
|
|
TEST_GENERATED_HEADER_FILES
|
2018-06-26 00:07:59 +02:00
|
|
|
CLANG_OPTIONS
|
|
|
|
-std=c++17
|
2018-01-20 19:46:17 +01:00
|
|
|
CLANG_OPTIONS_FROM_TARGETS
|
2020-01-31 19:27:15 +01:00
|
|
|
"${META_TARGET_NAME}_tests"
|
2018-01-20 19:46:17 +01:00
|
|
|
JSON_CLASSES
|
2019-06-14 19:16:51 +02:00
|
|
|
OtherNotJsonSerializable # test specifying classes for JSON (de)serialization manually
|
|
|
|
SomeOtherClassName # specifying a class that does not exist should not cause any problems
|
2018-01-20 19:46:17 +01:00
|
|
|
JSON_VISIBILITY
|
2019-06-14 19:16:51 +02:00
|
|
|
CPP_UTILITIES_GENERIC_LIB_EXPORT # not required, just to test setting visibility
|
2018-01-20 19:46:17 +01:00
|
|
|
)
|
2019-02-09 21:25:11 +01:00
|
|
|
# cmake-format: on
|
2018-01-20 19:46:17 +01:00
|
|
|
list(APPEND TEST_HEADER_FILES ${TEST_GENERATED_HEADER_FILES})
|
2020-01-31 19:27:15 +01:00
|
|
|
target_sources("${META_TARGET_NAME}_tests" PRIVATE ${TEST_GENERATED_HEADER_FILES})
|
2019-02-09 21:25:11 +01:00
|
|
|
endif ()
|
2018-01-20 19:46:17 +01:00
|
|
|
|
2017-11-17 22:01:18 +01:00
|
|
|
# add paths for include dirs of c++utilities and RapidJSON to config header so test cases can use it
|
|
|
|
set(META_CUSTOM_CONFIG "#define CPP_UTILITIES_INCLUDE_DIRS \"${CPP_UTILITIES_INCLUDE_DIRS}\"\n")
|
2019-02-09 21:25:11 +01:00
|
|
|
if (RapidJSON_FOUND)
|
2019-08-09 17:51:38 +02:00
|
|
|
# add include dirs either from RapidJSON_INCLUDE_DIRS or RAPIDJSON_INCLUDE_DIRS
|
|
|
|
if (RapidJSON_INCLUDE_DIRS)
|
|
|
|
set(RAPIDJSON_INCLUDE_DIRS ${RapidJSON_INCLUDE_DIRS})
|
|
|
|
endif ()
|
|
|
|
if (RAPIDJSON_INCLUDE_DIRS)
|
|
|
|
string(APPEND META_CUSTOM_CONFIG "#define RAPIDJSON_INCLUDE_DIRS \"${RAPIDJSON_INCLUDE_DIRS}\"\n")
|
|
|
|
endif ()
|
2019-02-09 21:25:11 +01:00
|
|
|
endif ()
|
2017-11-17 22:01:18 +01:00
|
|
|
|
2018-02-03 15:44:10 +01:00
|
|
|
# add path of Clang's resource dir to config header so test cases can use it
|
2019-02-09 21:25:11 +01:00
|
|
|
string(APPEND META_CUSTOM_CONFIG
|
|
|
|
"#define REFLECTION_GENERATOR_CLANG_RESOURCE_DIR \"${REFLECTION_GENERATOR_CLANG_RESOURCE_DIR}\"\n")
|
2018-02-03 15:44:10 +01:00
|
|
|
|
2017-11-17 22:01:18 +01:00
|
|
|
# make config header
|
2017-10-18 23:07:17 +02:00
|
|
|
include(ConfigHeader)
|