2016-04-25 07:36:05 +00:00
|
|
|
cmake_minimum_required(VERSION 3.0)
|
2015-04-26 20:47:40 +00:00
|
|
|
|
2016-04-25 08:23:14 +00:00
|
|
|
# define the project
|
|
|
|
project(json VERSION 2.0.0 LANGUAGES CXX)
|
2015-04-26 20:47:40 +00:00
|
|
|
|
2016-05-08 15:30:24 +00:00
|
|
|
option(BuildTests "Build the unit tests" ON)
|
|
|
|
|
2016-04-25 08:23:14 +00:00
|
|
|
# define project variables
|
2016-04-25 07:36:05 +00:00
|
|
|
set(JSON_TARGET_NAME ${PROJECT_NAME})
|
|
|
|
set(JSON_PACKAGE_NAME ${JSON_TARGET_NAME})
|
|
|
|
set(JSON_TARGETS_FILENAME "${JSON_PACKAGE_NAME}Targets.cmake")
|
2016-04-25 08:23:14 +00:00
|
|
|
set(JSON_CONFIG_FILENAME "${JSON_PACKAGE_NAME}Config.cmake")
|
|
|
|
set(JSON_CONFIGVERSION_FILENAME "${JSON_PACKAGE_NAME}ConfigVersion.cmake")
|
|
|
|
set(JSON_CONFIG_DESTINATION "cmake")
|
|
|
|
set(JSON_INCLUDE_DESTINATION "include/nlohmann")
|
2015-04-26 20:47:40 +00:00
|
|
|
|
2016-04-25 08:23:14 +00:00
|
|
|
# create and configure the library target
|
2016-04-25 07:36:05 +00:00
|
|
|
add_library(${JSON_TARGET_NAME} INTERFACE)
|
|
|
|
target_include_directories(${JSON_TARGET_NAME} INTERFACE
|
2016-04-25 08:23:14 +00:00
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
|
|
|
|
$<INSTALL_INTERFACE:${JSON_INCLUDE_DESTINATION}>)
|
2016-04-25 07:36:05 +00:00
|
|
|
|
2016-04-25 08:23:14 +00:00
|
|
|
# create and configure the unit test target
|
2016-05-08 15:30:24 +00:00
|
|
|
if (BuildTests)
|
2016-05-11 00:12:56 +00:00
|
|
|
add_executable(json_unit
|
2016-05-08 15:30:24 +00:00
|
|
|
"test/catch.hpp"
|
|
|
|
"test/unit.cpp"
|
|
|
|
)
|
2016-05-11 00:12:56 +00:00
|
|
|
set_target_properties(json_unit PROPERTIES
|
2016-05-08 15:30:24 +00:00
|
|
|
CXX_STANDARD 11
|
|
|
|
CXX_STANDARD_REQUIRED ON
|
|
|
|
COMPILE_DEFINITIONS "$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>"
|
|
|
|
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>")
|
2016-05-11 00:12:56 +00:00
|
|
|
target_include_directories(json_unit PRIVATE "test")
|
|
|
|
target_link_libraries(json_unit ${JSON_TARGET_NAME})
|
2016-05-08 15:30:24 +00:00
|
|
|
endif()
|
2016-04-25 07:36:05 +00:00
|
|
|
|
2016-04-25 08:23:14 +00:00
|
|
|
# generate a config and config version file for the package
|
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
configure_package_config_file("cmake/config.cmake.in"
|
2016-04-25 09:55:03 +00:00
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}"
|
2016-04-25 08:23:14 +00:00
|
|
|
INSTALL_DESTINATION ${JSON_CONFIG_DESTINATION})
|
2016-04-25 09:55:03 +00:00
|
|
|
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}"
|
2016-04-25 08:23:14 +00:00
|
|
|
VERSION ${PROJECT_VERSION}
|
|
|
|
COMPATIBILITY SameMajorVersion)
|
|
|
|
|
|
|
|
# export the library target and store build directory in package registry
|
2016-04-25 07:36:05 +00:00
|
|
|
export(TARGETS ${JSON_TARGET_NAME}
|
2016-04-25 09:55:03 +00:00
|
|
|
FILE "${CMAKE_CURRENT_BINARY_DIR}/${JSON_TARGETS_FILENAME}")
|
2016-04-25 07:36:05 +00:00
|
|
|
export(PACKAGE ${JSON_PACKAGE_NAME})
|
2016-04-25 08:23:14 +00:00
|
|
|
|
|
|
|
# install library target and config files
|
|
|
|
install(TARGETS ${JSON_TARGET_NAME}
|
|
|
|
EXPORT ${JSON_PACKAGE_NAME})
|
|
|
|
install(FILES "src/json.hpp"
|
|
|
|
DESTINATION ${JSON_INCLUDE_DESTINATION})
|
|
|
|
install(EXPORT ${JSON_PACKAGE_NAME}
|
|
|
|
FILE ${JSON_TARGETS_FILENAME}
|
|
|
|
DESTINATION ${JSON_CONFIG_DESTINATION})
|
2016-04-25 09:55:03 +00:00
|
|
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}"
|
2016-04-25 08:23:14 +00:00
|
|
|
DESTINATION ${JSON_CONFIG_DESTINATION})
|