reflective-rapidjson/generator/CMakeLists.txt

106 lines
3.6 KiB
CMake
Raw Normal View History

cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
# metadata
2017-10-25 17:41:19 +02:00
set(META_PROJECT_NAME reflective_rapidjson_generator)
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
serializationcodegenerator.h
jsonserializationcodegenerator.h
binaryserializationcodegenerator.h
2017-10-25 15:38:45 +02:00
codefactory.h
frontendaction.h
consumer.h
visitor.h
2019-02-09 21:25:11 +01:00
clangversionabstraction.h)
set(SRC_FILES
2017-10-25 15:38:45 +02:00
codegenerator.cpp
serializationcodegenerator.cpp
jsonserializationcodegenerator.cpp
binaryserializationcodegenerator.cpp
2017-10-25 15:38:45 +02:00
codefactory.cpp
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)
# 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 ()
# link against c++utilities
use_cpp_utilities()
2017-10-28 18:24:12 +02:00
# find Clang for LibTooling; adding clangTooling should be sufficient as it pulls all transitive dependencies
find_package(Clang REQUIRED)
2019-02-09 21:25:11 +01:00
list(APPEND PRIVATE_LIBRARIES
clangTooling
clangFrontend
2019-03-27 14:41:57 +01:00
clangSerialization
clangSema
2019-02-09 21:25:11 +01:00
clangAST
clangLex
clangBasic
LLVM)
2017-10-28 18:24:12 +02:00
# also add reflective_rapidjson which is header-only but might pull additional include dirs for RapidJSON
list(APPEND PRIVATE_LIBRARIES reflective_rapidjson)
# include modules to apply configuration
include(BasicConfig)
include(WindowsResources)
include(AppTarget)
include(TestTarget)
include(ShellCompletion)
include(Doxygen)
# trigger code generator for tests because the tests already contain structs to be (de)serialized
2019-02-09 21:25:11 +01:00
if (TARGET reflective_rapidjson_generator_tests)
include(ReflectionGenerator)
2019-02-09 21:25:11 +01:00
# cmake-format: off
add_reflection_generator_invocation(
INPUT_FILES
tests/structs.h # used by test cases
tests/morestructs.h # used by test cases
visitor.cpp # arbitrarily chosen source file (just for testing the "no relevant structs/classes" case)
GENERATORS
json
binary
OUTPUT_LISTS
TEST_GENERATED_HEADER_FILES
2018-06-26 00:07:59 +02:00
CLANG_OPTIONS
-std=c++17
CLANG_OPTIONS_FROM_TARGETS
reflective_rapidjson_generator_tests
JSON_CLASSES
OtherNotJsonSerializable # test specifying classes for JSON (de)serialization manually
SomeOtherClassName # specifying a class that does not exist should not cause any problems
JSON_VISIBILITY
LIB_EXPORT # not required, just to test setting visibility
)
2019-02-09 21:25:11 +01:00
# cmake-format: on
list(APPEND TEST_HEADER_FILES ${TEST_GENERATED_HEADER_FILES})
target_sources(reflective_rapidjson_generator_tests PRIVATE ${TEST_GENERATED_HEADER_FILES})
2019-02-09 21:25:11 +01:00
endif ()
# 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)
string(APPEND META_CUSTOM_CONFIG "#define RAPIDJSON_INCLUDE_DIRS \"${RAPIDJSON_INCLUDE_DIRS}\"\n")
2019-02-09 21:25:11 +01:00
endif ()
# 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")
# make config header
include(ConfigHeader)