cmake: allow the building of shared or static libraries

Alternative for #15
This commit is contained in:
Patrick Boettcher 2018-02-27 11:12:21 +01:00
parent 6f69d01b58
commit 2a1f77d084
2 changed files with 16 additions and 4 deletions

View File

@ -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")

View File

@ -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`.