Add CMake options to disable extras and support install

Description:
- Adds support for the following CMake options:
- BUILD_TESTS (default: ON)
- BUILD_EXAMPLES (default: ON)
- CMAKE_INSTALL_PREFIX (both static and shared)
This commit is contained in:
Bryan Gillespie 2018-05-11 11:16:27 -04:00 committed by Patrick Boettcher
parent 16aa1c05c7
commit e3d42e65c2

View File

@ -2,6 +2,9 @@ project(json-schema-validator CXX)
cmake_minimum_required(VERSION 3.2)
option(BUILD_TESTS "Build tests" ON)
option(BUILD_EXAMPLES "Build examples" ON)
# if used as a subdirectory just define a json-hpp-target as add_library(json-hpp INTERFACE)
# and associate the path to json.hpp via target_include_directories()
if(NOT TARGET json-hpp)
@ -33,6 +36,14 @@ add_library(json-schema-validator
src/json-uri.cpp
src/json-validator.cpp)
install(TARGETS json-schema-validator
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(DIRECTORY src/
DESTINATION include
FILES_MATCHING PATTERN "*.h*")
target_include_directories(json-schema-validator
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src)
@ -80,10 +91,14 @@ if(NOT TARGET json-hpp) # if used as a subdirectory do not install json-schema.h
)
endif()
# simple json-schema-validator-executable
add_executable(json-schema-validate app/json-schema-validate.cpp)
target_link_libraries(json-schema-validate json-schema-validator)
if (BUILD_EXAMPLES)
# simple json-schema-validator-executable
add_executable(json-schema-validate app/json-schema-validate.cpp)
target_link_libraries(json-schema-validate json-schema-validator)
endif()
# test-zone
enable_testing()
add_subdirectory(test)
if (BUILD_TESTS)
# test-zone
enable_testing()
add_subdirectory(test)
endif()