This commit is contained in:
Damien Buhl 2015-11-16 09:28:40 +00:00
commit b26db497f3
2 changed files with 62 additions and 13 deletions

View File

@ -1,25 +1,50 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 3.0.0)
project(json CXX) project(json
LANGUAGES CXX
VERSION "1.0.0")
add_executable(json_unit add_executable(json_unit
src/json.hpp test/catch.hpp test/unit.cpp src/json.hpp test/catch.hpp test/unit.cpp
) )
if(MSVC) if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
"/EHsc"
)
STRING(REPLACE "/O2" "/Od" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}) elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "-std=c++11")
add_definitions(-D_SCL_SECURE_NO_WARNINGS) elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
else(MSVC) set(CMAKE_CXX_FLAGS "/EHsc")
set(CMAKE_CXX_FLAGS
"-std=c++11 -stdlib=libc++" STRING(REPLACE "/O2" "/Od" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
)
endif(MSVC) # See https://msdn.microsoft.com/fr-fr/library/aa985974.aspx?f=255&MSPPError=-2147217396
# Avoid warnings for unsafe STL methods call
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
endif()
include_directories( include_directories(
src test src test
) )
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/src/ DESTINATION include/nlohmann
FILES_MATCHING PATTERN "*.[ih]pp")
include(CMakePackageConfigHelpers)
set(INCLUDE_INSTALL_DIR include/)
set(DEFINITIONS "${CMAKE_CXX_FLAGS}")
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/modules/nlohmann-json-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/nlohmann-json-config.cmake
INSTALL_DESTINATION lib/cmake/nlohmann-json-${json_VERSION}
PATH_VARS INCLUDE_INSTALL_DIR)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/nlohmann-json-config-version.cmake
COMPATIBILITY AnyNewerVersion)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/nlohmann-json-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/nlohmann-json-config-version.cmake
DESTINATION lib/cmake/nlohmann-json-${json_VERSION})

View File

@ -0,0 +1,24 @@
# It can be used as :
#
# find_package(nlohmann-json)
# target_link_libraries(program nlohmann-json::nlohmann-json)
#
# It also defines
# - ${NLOHMANN_JSON_INCLUDE_DIRS}
# - ${NLOHMANN_JSON_DEFINITIONS}
#
set(NLOHMANN_JSON_VERSION @json_VERSION@)
@PACKAGE_INIT@
set_and_check(NLOHMANN_JSON_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@")
set(NLOHMANN_JSON_DEFINITIONS "@CMAKE_CXX_FLAGS@")
check_required_components(nlohmann_json)
if (NOT TARGET "nlohmann-json::nlohmann-json")
add_library("nlohmann-json::nlohmann-json" INTERFACE IMPORTED)
set_target_properties("nlohmann-json::nlohmann-json"
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${NLOHMANN_JSON_INCLUDE_DIRS}"
INTERFACE_COMPILE_OPTIONS ${NLOHMANN_JSON_DEFINITIONS})
endif()