This repository has been archived by the owner on Apr 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
207 lines (182 loc) · 6.66 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Autogenerated by `mkbuild`; DO NOT EDIT!
cmake_minimum_required(VERSION 3.12.0)
project("mkjson")
include(CheckIncludeFileCXX)
include(CheckLibraryExists)
include(CheckCXXCompilerFlag)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
list(APPEND CMAKE_REQUIRED_LIBRARIES Threads::Threads)
if(("${WIN32}"))
list(APPEND CMAKE_REQUIRED_LIBRARIES ws2_32 crypt32)
if(("${MINGW}"))
list(APPEND CMAKE_REQUIRED_LIBRARIES -static-libgcc -static-libstdc++)
endif()
endif()
enable_testing()
if(("${WIN32}"))
if(("${CMAKE_SIZEOF_VOID_P}" EQUAL 4))
SET(MK_WIN32_ARCH "x86")
elseif(("${CMAKE_SIZEOF_VOID_P}" EQUAL 8))
SET(MK_WIN32_ARCH "x64")
else()
message(FATAL_ERROR "Neither 32 not 64 bit")
endif()
endif()
#
# json.hpp
#
message(STATUS "mkdirAll: ${CMAKE_BINARY_DIR}/.mkbuild/include")
execute_process(COMMAND
${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/.mkbuild/include"
RESULT_VARIABLE FAILURE_1157)
if("${FAILURE_1157}")
message(FATAL_ERROR "${FAILURE_1157}")
endif()
message(STATUS "download: https://raw.githubusercontent.com/nlohmann/json/v3.5.0/single_include/nlohmann/json.hpp")
file(DOWNLOAD https://raw.githubusercontent.com/nlohmann/json/v3.5.0/single_include/nlohmann/json.hpp
"${CMAKE_BINARY_DIR}/.mkbuild/include/json.hpp"
EXPECTED_HASH SHA256=8a6dbf3bf01156f438d0ca7e78c2971bca50eec4ca6f0cf59adf3464c43bb9d5
TLS_VERIFY ON)
LIST(APPEND CMAKE_REQUIRED_INCLUDES "${CMAKE_BINARY_DIR}/.mkbuild/include")
CHECK_INCLUDE_FILE_CXX("json.hpp" MK_HAVE_HEADER_1709)
if(NOT ("${MK_HAVE_HEADER_1709}"))
message(FATAL_ERROR "cannot find: json.hpp")
endif()
#
# catch.hpp
#
message(STATUS "mkdirAll: ${CMAKE_BINARY_DIR}/.mkbuild/include")
execute_process(COMMAND
${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/.mkbuild/include"
RESULT_VARIABLE FAILURE_2037)
if("${FAILURE_2037}")
message(FATAL_ERROR "${FAILURE_2037}")
endif()
message(STATUS "download: https://github.com/catchorg/Catch2/releases/download/v2.3.0/catch.hpp")
file(DOWNLOAD https://github.com/catchorg/Catch2/releases/download/v2.3.0/catch.hpp
"${CMAKE_BINARY_DIR}/.mkbuild/include/catch.hpp"
EXPECTED_HASH SHA256=5eb8532fd5ec0d28433eba8a749102fd1f98078c5ebf35ad607fb2455a000004
TLS_VERIFY ON)
LIST(APPEND CMAKE_REQUIRED_INCLUDES "${CMAKE_BINARY_DIR}/.mkbuild/include")
CHECK_INCLUDE_FILE_CXX("catch.hpp" MK_HAVE_HEADER_2554)
if(NOT ("${MK_HAVE_HEADER_2554}"))
message(FATAL_ERROR "cannot find: catch.hpp")
endif()
#
# mkdata.hpp
#
message(STATUS "mkdirAll: ${CMAKE_BINARY_DIR}/.mkbuild/include")
execute_process(COMMAND
${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/.mkbuild/include"
RESULT_VARIABLE FAILURE_2885)
if("${FAILURE_2885}")
message(FATAL_ERROR "${FAILURE_2885}")
endif()
message(STATUS "download: https://raw.githubusercontent.com/measurement-kit/mkdata/v0.3.0/mkdata.hpp")
file(DOWNLOAD https://raw.githubusercontent.com/measurement-kit/mkdata/v0.3.0/mkdata.hpp
"${CMAKE_BINARY_DIR}/.mkbuild/include/mkdata.hpp"
EXPECTED_HASH SHA256=96bb0384ecd7231a861111d8818a560b7d5ca83316cf7946a4f1a352db6ecfe3
TLS_VERIFY ON)
LIST(APPEND CMAKE_REQUIRED_INCLUDES "${CMAKE_BINARY_DIR}/.mkbuild/include")
CHECK_INCLUDE_FILE_CXX("mkdata.hpp" MK_HAVE_HEADER_3413)
if(NOT ("${MK_HAVE_HEADER_3413}"))
message(FATAL_ERROR "cannot find: mkdata.hpp")
endif()
#
# Set restrictive compiler flags
#
macro(MKSetRestrictiveCompilerFlags)
if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") OR
("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Werror")
# https://www.owasp.org/index.php/C-Based_Toolchain_Hardening_Cheat_Sheet
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Wall")
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Wextra")
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Wconversion")
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Wcast-align")
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Wformat=2")
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Wformat-security")
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -fno-common")
# Some options are only supported by GCC when we're compiling C code:
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Wmissing-prototypes")
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Wstrict-prototypes")
else()
set(MK_C_FLAGS "${MK_C_FLAGS} -Wmissing-prototypes")
set(MK_C_FLAGS "${MK_C_FLAGS} -Wstrict-prototypes")
endif()
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Wmissing-declarations")
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Wstrict-overflow")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Wtrampolines")
endif()
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Woverloaded-virtual")
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Wreorder")
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Wsign-promo")
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -Wnon-virtual-dtor")
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} -fstack-protector-all")
if(NOT "${APPLE}")
set(MK_LD_FLAGS "${MK_LD_FLAGS} -Wl,-z,noexecstack")
set(MK_LD_FLAGS "${MK_LD_FLAGS} -Wl,-z,now")
set(MK_LD_FLAGS "${MK_LD_FLAGS} -Wl,-z,relro")
set(MK_LD_FLAGS "${MK_LD_FLAGS} -Wl,-z,nodlopen")
set(MK_LD_FLAGS "${MK_LD_FLAGS} -Wl,-z,nodump")
endif()
add_definitions(-D_FORTIFY_SOURCES=2)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# TODO(bassosimone): add support for /Wall and /analyze
set(MK_COMMON_FLAGS "${MK_COMMON_FLAGS} /WX /W4 /EHs")
set(MK_LD_FLAGS "${MK_LD_FLAGS} /WX")
else()
message(FATAL_ERROR "Compiler not supported: ${CMAKE_CXX_COMPILER_ID}")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MK_COMMON_FLAGS} ${MK_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MK_COMMON_FLAGS} ${MK_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MK_LD_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${MK_LD_FLAGS}")
if("${WIN32}")
add_definitions(-D_WIN32_WINNT=0x0600) # for NI_NUMERICSERV and WSAPoll
endif()
endmacro()
MKSetRestrictiveCompilerFlags()
#
# Prepare for compiling targets
#
add_definitions(${CMAKE_REQUIRED_DEFINITIONS})
include_directories(${CMAKE_REQUIRED_INCLUDES})
#
# mkjson
#
add_library(
mkjson
mkjson.cpp
)
target_link_libraries(
mkjson
${CMAKE_REQUIRED_LIBRARIES}
)
#
# unit-tests
#
add_executable(
unit-tests
unit-tests.cpp
)
target_link_libraries(
unit-tests
${CMAKE_REQUIRED_LIBRARIES}
)
#
# test: unit_tests
#
add_test(
NAME unit_tests COMMAND unit-tests
)