This repository has been archived by the owner on Jun 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
248 lines (222 loc) · 8.3 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# Autogenerated by `mkbuild`; DO NOT EDIT!
cmake_minimum_required(VERSION 3.12.0)
project("mkudns")
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()
if((${APPLE}))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/include")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L/usr/local/lib")
endif()
#
# argh.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_1399)
if("${FAILURE_1399}")
message(FATAL_ERROR "${FAILURE_1399}")
endif()
message(STATUS "download: https://raw.githubusercontent.com/adishavit/argh/v1.3.0/argh.h")
file(DOWNLOAD https://raw.githubusercontent.com/adishavit/argh/v1.3.0/argh.h
"${CMAKE_BINARY_DIR}/.mkbuild/include/argh.h"
EXPECTED_HASH SHA256=ddb7dfc18dcf90149735b76fb2cff101067453a1df1943a6911233cb7085980c
TLS_VERIFY ON)
LIST(APPEND CMAKE_REQUIRED_INCLUDES "${CMAKE_BINARY_DIR}/.mkbuild/include")
CHECK_INCLUDE_FILE_CXX("argh.h" MK_HAVE_HEADER_1899)
if(NOT ("${MK_HAVE_HEADER_1899}"))
message(FATAL_ERROR "cannot find: argh.h")
endif()
CHECK_INCLUDE_FILE_CXX("ares.h" MK_HAVE_HEADER_2040)
if(NOT ("${MK_HAVE_HEADER_2040}"))
message(FATAL_ERROR "cannot find: ares.h")
endif()
CHECK_LIBRARY_EXISTS("cares" "ares_process" "" MK_HAVE_LIB_2181)
if(NOT ("${MK_HAVE_LIB_2181}"))
message(FATAL_ERROR "cannot find: cares")
endif()
LIST(APPEND CMAKE_REQUIRED_LIBRARIES "cares")
#
# 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_2560)
if("${FAILURE_2560}")
message(FATAL_ERROR "${FAILURE_2560}")
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_3088)
if(NOT ("${MK_HAVE_HEADER_3088}"))
message(FATAL_ERROR "cannot find: mkdata.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_3419)
if("${FAILURE_3419}")
message(FATAL_ERROR "${FAILURE_3419}")
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_3971)
if(NOT ("${MK_HAVE_HEADER_3971}"))
message(FATAL_ERROR "cannot find: json.hpp")
endif()
if(("${APPLE}"))
if(EXISTS "/usr/local/opt/openssl")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/opt/openssl/include")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/opt/openssl/lib")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L/usr/local/opt/openssl/lib")
endif()
endif()
CHECK_INCLUDE_FILE_CXX("openssl/rsa.h" MK_HAVE_HEADER_4459)
if(NOT ("${MK_HAVE_HEADER_4459}"))
message(FATAL_ERROR "cannot find: openssl/rsa.h")
endif()
CHECK_LIBRARY_EXISTS("crypto" "RSA_new" "" MK_HAVE_LIB_4614)
if(NOT ("${MK_HAVE_LIB_4614}"))
message(FATAL_ERROR "cannot find: crypto")
endif()
LIST(APPEND CMAKE_REQUIRED_LIBRARIES "crypto")
CHECK_INCLUDE_FILE_CXX("openssl/ssl.h" MK_HAVE_HEADER_4807)
if(NOT ("${MK_HAVE_HEADER_4807}"))
message(FATAL_ERROR "cannot find: openssl/ssl.h")
endif()
CHECK_LIBRARY_EXISTS("ssl" "SSL_read" "" MK_HAVE_LIB_4962)
if(NOT ("${MK_HAVE_LIB_4962}"))
message(FATAL_ERROR "cannot find: ssl")
endif()
LIST(APPEND CMAKE_REQUIRED_LIBRARIES "ssl")
#
# 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")
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})
#
# mkudns
#
add_library(
mkudns
mkudns.cpp
)
target_link_libraries(
mkudns
${CMAKE_REQUIRED_LIBRARIES}
)
#
# mkudns-client
#
add_executable(
mkudns-client
mkudns-client.cpp
)
target_link_libraries(
mkudns-client
mkudns
${CMAKE_REQUIRED_LIBRARIES}
)
#
# test: resolve_address
#
add_test(
NAME resolve_address COMMAND mkudns-client --server-address 1.1.1.1 www.kernel.org
)