-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
138 lines (119 loc) · 3.58 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
cmake_minimum_required (VERSION 3.10)
project (json
VERSION 0.1.1
DESCRIPTION "JSON implemented in terms of C++17 variant."
LANGUAGES CXX)
set(JSON_TESTING ON CACHE BOOL "Compile and/or run self-tests")
set(JSON_INSTALL ON CACHE BOOL "Install the library")
set(JSON_IGNORE_CONAN OFF CACHE BOOL "Ignore conanbuildinfo")
set(PROJECT_VERSION_SHORT "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
set(PROJECT_VERSION_STABILITY "")
if (NOT JSON_IGNORE_CONAN)
if (EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
elseif(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
message(FATAL_ERROR "Missing file\n ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake\nRun `conan install .. --build missing` before cmake")
endif()
endif()
if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if (JSON_TESTING)
if (NOT TARGET GTest::gtest_main)
find_package(GTest REQUIRED CONFIG HINTS ${PROJECT_BINARY_DIR})
endif()
endif()
if (MSVC)
set(ADDITIONAL_WALL_FLAGS
/permissive-
/D_CRT_SECURE_NO_WARNINGS
/Zc:__cplusplus
/W4
/w14242
/w14254
/w14263
/w14265
/w14287
/we4289
/w14296
/w14311
/w14545
/w14546
/w14547
/w14549
/w14555
/w14619
/w14640
/w14826
/w14905
/w14906
/w14928
/w14946)
else()
set(ADDITIONAL_WALL_FLAGS
-Wall -Wextra
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-align
-Wunused
-Woverloaded-virtual
-Wpedantic
-Wconversion
-Wsign-conversion
-Wnull-dereference
-Wdouble-promotion
-Wformat=2
)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
list(APPEND ADDITIONAL_WALL_FLAGS -fcolor-diagnostics) # -Wlifetime
else()
list(APPEND ADDITIONAL_WALL_FLAGS
-fdiagnostics-color
-Wmisleading-indentation
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
-Wuseless-cast
)
endif()
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_library(json STATIC
src/json.cpp
include/json/json.hpp
include/json/serdes.hpp)
set_target_properties(json PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})
target_include_directories(json PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_options(json PRIVATE ${ADDITIONAL_WALL_FLAGS})
if (MSVC)
target_sources(json PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/vs/u8string.natvis)
endif()
##################################################################
## INSTALL
##################################################################
if (JSON_INSTALL)
install(TARGETS json)
install(DIRECTORY include/json DESTINATION include)
endif()
##################################################################
## TESTING
##################################################################
if (JSON_TESTING)
set(COVERALLS_PREFIX JSON_)
set(JSON_COVERALLS_DIRS src include)
find_package(Python3 COMPONENTS Interpreter REQUIRED)
include(tools/coveralls/Coveralls.cmake)
enable_testing()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/tests)
file(GLOB TEST_SRCS tests/*.cc)
add_executable(json-test ${TEST_SRCS})
target_compile_options(json-test PRIVATE ${ADDITIONAL_WALL_FLAGS})
target_link_libraries(json-test PRIVATE json GTest::gtest_main)
add_test(NAME json COMMAND json-test --gtest_output=xml:testing-results/json-${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}-${CMAKE_BUILD_TYPE}.xml)
endif()