cannam@150: cmake_minimum_required(VERSION 2.8) cannam@242: if (CMAKE_VERSION VERSION_LESS "3") cannam@242: project(json11 CXX) cannam@242: else() cannam@242: cmake_policy(SET CMP0048 NEW) cannam@242: project(json11 VERSION 1.0.0 LANGUAGES CXX) cannam@242: endif() cannam@150: cannam@150: enable_testing() cannam@150: cannam@242: option(JSON11_BUILD_TESTS "Build unit tests" OFF) cannam@242: option(JSON11_ENABLE_DR1467_CANARY "Enable canary test for DR 1467" OFF) cannam@150: cannam@242: if(CMAKE_VERSION VERSION_LESS "3") cannam@242: add_definitions(-std=c++11) cannam@242: else() cannam@242: set(CMAKE_CXX_STANDARD 11) cannam@242: set(CMAKE_CXX_STANDARD_REQUIRED ON) cannam@242: endif() cannam@150: cannam@242: if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) cannam@242: set(CMAKE_INSTALL_PREFIX /usr) cannam@242: endif() cannam@150: cannam@242: add_library(json11 json11.cpp) cannam@242: target_include_directories(json11 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) cannam@242: target_compile_options(json11 cannam@242: PRIVATE -fPIC -fno-rtti -fno-exceptions -Wall) cannam@150: cannam@242: # Set warning flags, which may vary per platform cannam@242: include(CheckCXXCompilerFlag) cannam@242: set(_possible_warnings_flags /W4 /WX -Wextra -Werror) cannam@242: foreach(_warning_flag in ${_possible_warnings_flags}) cannam@242: CHECK_CXX_COMPILER_FLAG(_warning_flag _flag_supported) cannam@242: if(${_flag_supported}) cannam@242: target_compile_options(json11 PRIVATE ${_warning_flag}) cannam@242: endif() cannam@242: endforeach() cannam@242: cannam@242: configure_file("json11.pc.in" "json11.pc" @ONLY) cannam@242: cannam@242: if (JSON11_BUILD_TESTS) cannam@242: cannam@242: # enable test for DR1467, described here: https://llvm.org/bugs/show_bug.cgi?id=23812 cannam@242: if(JSON11_ENABLE_DR1467_CANARY) cannam@242: add_definitions(-D JSON11_ENABLE_DR1467_CANARY=1) cannam@242: else() cannam@242: add_definitions(-D JSON11_ENABLE_DR1467_CANARY=0) cannam@242: endif() cannam@242: cannam@242: add_executable(json11_test test.cpp) cannam@242: target_link_libraries(json11_test json11) cannam@242: endif() cannam@242: cannam@242: install(TARGETS json11 DESTINATION lib/${CMAKE_LIBRARY_ARCHITECTURE}) cannam@242: install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/json11.hpp" DESTINATION include/${CMAKE_LIBRARY_ARCHITECTURE}) cannam@242: install(FILES "${CMAKE_CURRENT_BINARY_DIR}/json11.pc" DESTINATION lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig)