From 2a1f77d08426357e9255f94acadc509d0b4d27ec Mon Sep 17 00:00:00 2001 From: Patrick Boettcher Date: Tue, 27 Feb 2018 11:12:21 +0100 Subject: [PATCH] cmake: allow the building of shared or static libraries Alternative for #15 --- CMakeLists.txt | 10 ++++++---- README.md | 10 ++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dce992f..2da3c4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ if(NOT TARGET json-hpp) endif() # and one for the validator -add_library(json-schema-validator SHARED +add_library(json-schema-validator src/json-schema-draft4.json.cpp src/json-uri.cpp src/json-validator.cpp) @@ -49,9 +49,11 @@ endif() target_link_libraries(json-schema-validator PUBLIC json-hpp) -target_compile_definitions(json-schema-validator - PRIVATE - -DJSON_SCHEMA_VALIDATOR_EXPORTS) +if(BUILD_SHARED_LIBS) + target_compile_definitions(json-schema-validator + PRIVATE + -DJSON_SCHEMA_VALIDATOR_EXPORTS) +endif() # regex with boost if gcc < 4.9 - default is std::regex if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") diff --git a/README.md b/README.md index c604c0d..ac55838 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,16 @@ enable_testing() # if you want to inherit tests add_subdirectory(path-to-this-project json-schema-validator) ``` +### Building a shared library + +By default a static library is built. Shared libraries are generated by using +the `BUILD_SHARED_LIBS`-cmake variable: + +In your initial call to cmake simply add: +```bash +cmake -DBUILD_SHARED_LIBS=ON +``` + ## Code See also `app/json-schema-validate.cpp`.