From f5a240649f9ddb922febcd4ecdecb4bf9e6f5d67 Mon Sep 17 00:00:00 2001 From: Martchus Date: Fri, 17 Nov 2017 22:04:01 +0100 Subject: [PATCH] Separate RapidJSON specific parts So when extending this for further applications of reflection, the JSON-specific parts can be made optional. --- CMakeLists.txt | 6 ++++++ generator/CMakeLists.txt | 12 ++++++++++-- lib/CMakeLists.txt | 27 ++++++++++++++++----------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c5e42b..1434226 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,12 @@ if(BUNDLED_CPP_UTILITIES_PATH) set(CPP_UTILITIES_INCLUDE_DIRS "${CPP_UTILITIES_SOURCE_DIR}/..") endif() +# find RapidJSON +find_package(RapidJSON) +if(NOT RapidJSON_FOUND) + message(FATAL_ERROR "Unable to find RapidJSON. Since this is the only supported reflection application at this time, it makes no sense to continue.") +endif() + # add header-only library containing JsonSerializable and helper for using RapidJSON add_subdirectory(lib) # allow inclusion of CMake modules from that lib in other parts of the project diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index 9102176..e855092 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -26,14 +26,22 @@ set(SRC_FILES main.cpp ) set(TEST_HEADER_FILES - tests/structs.h tests/helper.h ) set(TEST_SRC_FILES tests/cppunit.cpp - tests/jsongenerator.cpp ) +# add JSON-specific test cases +if(RapidJSON_FOUND) + list(APPEND TEST_HEADER_FILES + tests/structs.h + ) + list(APPEND TEST_SRC_FILES + tests/jsongenerator.cpp + ) +endif() + # link against c++utilities use_cpp_utilities() diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 4613b9f..3e1da3c 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -5,11 +5,6 @@ set(META_PROJECT_TYPE library) # add project files set(HEADER_FILES - json/reflector.h - json/reflector-boosthana.h - json/reflector-chronoutilities.h - json/serializable.h - json/errorhandling.h ) set(SRC_FILES ) @@ -17,9 +12,6 @@ set(TEST_HEADER_FILES ) set(TEST_SRC_FILES tests/cppunit.cpp - tests/jsonreflector.cpp - tests/jsonreflector-boosthana.cpp - tests/jsonreflector-chronoutilities.cpp ) set(CMAKE_MODULE_FILES cmake/modules/ReflectionGenerator.cmake @@ -28,17 +20,30 @@ set(DOC_FILES README.md ) +# add JSON-specific sources +if(RapidJSON_FOUND) + list(APPEND HEADER_FILES + json/reflector.h + json/reflector-boosthana.h + json/reflector-chronoutilities.h + json/serializable.h + json/errorhandling.h + ) + list(APPEND TEST_SRC_FILES + tests/jsonreflector.cpp + tests/jsonreflector-boosthana.cpp + tests/jsonreflector-chronoutilities.cpp + ) +endif() + # add (only) the include dirs for c++utilities because we're not depending on the actual library list(APPEND PUBLIC_SHARED_INCLUDE_DIRS "${CPP_UTILITIES_INCLUDE_DIRS}") list(APPEND PUBLIC_STATIC_INCLUDE_DIRS "${CPP_UTILITIES_INCLUDE_DIRS}") # find RapidJSON, also add only the include dirs because RapidJSON is a header-only library -find_package(RapidJSON) if(RapidJSON_FOUND) list(APPEND PUBLIC_SHARED_INCLUDE_DIRS ${RAPIDJSON_INCLUDE_DIRS}) list(APPEND PUBLIC_STATIC_INCLUDE_DIRS ${RAPIDJSON_INCLUDE_DIRS}) -else() - message(FATAL_ERROR "Unable to find RapidJSON. Since this is the only reflection application supported at this time it makes no sense to continue.") endif() # include modules to apply configuration