This repository has been archived by the owner on Aug 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
229 lines (202 loc) · 7.51 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# Autogenerated by `mkbuild`; DO NOT EDIT!
cmake_minimum_required(VERSION 3.12.0)
project("mkreport")
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)
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()
#
# 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_1056)
if("${FAILURE_1056}")
message(FATAL_ERROR "${FAILURE_1056}")
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_1573)
if(NOT ("${MK_HAVE_HEADER_1573}"))
message(FATAL_ERROR "cannot find: catch.hpp")
endif()
#
# date.h
#
message(STATUS "mkdirAll: ${CMAKE_BINARY_DIR}/.mkbuild/include")
execute_process(COMMAND
${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/.mkbuild/include"
RESULT_VARIABLE FAILURE_1900)
if("${FAILURE_1900}")
message(FATAL_ERROR "${FAILURE_1900}")
endif()
message(STATUS "download: https://raw.githubusercontent.com/HowardHinnant/date/v2.4.1/include/date/date.h")
file(DOWNLOAD https://raw.githubusercontent.com/HowardHinnant/date/v2.4.1/include/date/date.h
"${CMAKE_BINARY_DIR}/.mkbuild/include/date.h"
EXPECTED_HASH SHA256=07aa75752540023ccccab178ed193f536c9d032cbbda997159af9f339d331eda
TLS_VERIFY ON)
LIST(APPEND CMAKE_REQUIRED_INCLUDES "${CMAKE_BINARY_DIR}/.mkbuild/include")
CHECK_INCLUDE_FILE_CXX("date.h" MK_HAVE_HEADER_2434)
if(NOT ("${MK_HAVE_HEADER_2434}"))
message(FATAL_ERROR "cannot find: date.h")
endif()
#
# mkuuid4.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_2760)
if("${FAILURE_2760}")
message(FATAL_ERROR "${FAILURE_2760}")
endif()
message(STATUS "download: https://raw.githubusercontent.com/measurement-kit/mkuuid4/v0.1.0/mkuuid4.hpp")
file(DOWNLOAD https://raw.githubusercontent.com/measurement-kit/mkuuid4/v0.1.0/mkuuid4.hpp
"${CMAKE_BINARY_DIR}/.mkbuild/include/mkuuid4.hpp"
EXPECTED_HASH SHA256=5b6b4445697d9beb6ad5310d98b7743c2ffe8266cdec79df0a7a429dcfc247ac
TLS_VERIFY ON)
LIST(APPEND CMAKE_REQUIRED_INCLUDES "${CMAKE_BINARY_DIR}/.mkbuild/include")
CHECK_INCLUDE_FILE_CXX("mkuuid4.hpp" MK_HAVE_HEADER_3293)
if(NOT ("${MK_HAVE_HEADER_3293}"))
message(FATAL_ERROR "cannot find: mkuuid4.hpp")
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_3626)
if("${FAILURE_3626}")
message(FATAL_ERROR "${FAILURE_3626}")
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_4178)
if(NOT ("${MK_HAVE_HEADER_4178}"))
message(FATAL_ERROR "cannot find: json.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}" AND NOT "${MINGW}")
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")
elseif(("${MINGW}"))
set(MK_LD_FLAGS "${MK_LD_FLAGS} -static")
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})
#
# mkreport
#
add_library(
mkreport
mkreport.cpp
)
target_link_libraries(
mkreport
${CMAKE_REQUIRED_LIBRARIES}
)
#
# unit-tests
#
add_executable(
unit-tests
unit-tests.cpp
)
target_link_libraries(
unit-tests
mkreport
${CMAKE_REQUIRED_LIBRARIES}
)
#
# test: unit_tests
#
add_test(
NAME unit_tests COMMAND unit-tests
)