cannam@150
|
1 cmake_minimum_required(VERSION 2.8)
|
cannam@242
|
2 if (CMAKE_VERSION VERSION_LESS "3")
|
cannam@242
|
3 project(json11 CXX)
|
cannam@242
|
4 else()
|
cannam@242
|
5 cmake_policy(SET CMP0048 NEW)
|
cannam@242
|
6 project(json11 VERSION 1.0.0 LANGUAGES CXX)
|
cannam@242
|
7 endif()
|
cannam@150
|
8
|
cannam@150
|
9 enable_testing()
|
cannam@150
|
10
|
cannam@242
|
11 option(JSON11_BUILD_TESTS "Build unit tests" OFF)
|
cannam@242
|
12 option(JSON11_ENABLE_DR1467_CANARY "Enable canary test for DR 1467" OFF)
|
cannam@150
|
13
|
cannam@242
|
14 if(CMAKE_VERSION VERSION_LESS "3")
|
cannam@242
|
15 add_definitions(-std=c++11)
|
cannam@242
|
16 else()
|
cannam@242
|
17 set(CMAKE_CXX_STANDARD 11)
|
cannam@242
|
18 set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
cannam@242
|
19 endif()
|
cannam@150
|
20
|
cannam@242
|
21 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
cannam@242
|
22 set(CMAKE_INSTALL_PREFIX /usr)
|
cannam@242
|
23 endif()
|
cannam@150
|
24
|
cannam@242
|
25 add_library(json11 json11.cpp)
|
cannam@242
|
26 target_include_directories(json11 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
cannam@242
|
27 target_compile_options(json11
|
cannam@242
|
28 PRIVATE -fPIC -fno-rtti -fno-exceptions -Wall)
|
cannam@150
|
29
|
cannam@242
|
30 # Set warning flags, which may vary per platform
|
cannam@242
|
31 include(CheckCXXCompilerFlag)
|
cannam@242
|
32 set(_possible_warnings_flags /W4 /WX -Wextra -Werror)
|
cannam@242
|
33 foreach(_warning_flag in ${_possible_warnings_flags})
|
cannam@242
|
34 CHECK_CXX_COMPILER_FLAG(_warning_flag _flag_supported)
|
cannam@242
|
35 if(${_flag_supported})
|
cannam@242
|
36 target_compile_options(json11 PRIVATE ${_warning_flag})
|
cannam@242
|
37 endif()
|
cannam@242
|
38 endforeach()
|
cannam@242
|
39
|
cannam@242
|
40 configure_file("json11.pc.in" "json11.pc" @ONLY)
|
cannam@242
|
41
|
cannam@242
|
42 if (JSON11_BUILD_TESTS)
|
cannam@242
|
43
|
cannam@242
|
44 # enable test for DR1467, described here: https://llvm.org/bugs/show_bug.cgi?id=23812
|
cannam@242
|
45 if(JSON11_ENABLE_DR1467_CANARY)
|
cannam@242
|
46 add_definitions(-D JSON11_ENABLE_DR1467_CANARY=1)
|
cannam@242
|
47 else()
|
cannam@242
|
48 add_definitions(-D JSON11_ENABLE_DR1467_CANARY=0)
|
cannam@242
|
49 endif()
|
cannam@242
|
50
|
cannam@242
|
51 add_executable(json11_test test.cpp)
|
cannam@242
|
52 target_link_libraries(json11_test json11)
|
cannam@242
|
53 endif()
|
cannam@242
|
54
|
cannam@242
|
55 install(TARGETS json11 DESTINATION lib/${CMAKE_LIBRARY_ARCHITECTURE})
|
cannam@242
|
56 install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/json11.hpp" DESTINATION include/${CMAKE_LIBRARY_ARCHITECTURE})
|
cannam@242
|
57 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/json11.pc" DESTINATION lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig)
|