forked from intel/diagnostics-utility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
341 lines (294 loc) · 9.19 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# /*******************************************************************************
# Copyright Intel Corporation.
# This software and the related documents are Intel copyrighted materials, and your use of them
# is governed by the express license under which they were provided to you (License).
# Unless the License provides otherwise, you may not use, modify, copy, publish, distribute, disclose
# or transmit this software or the related documents without Intel's prior written permission.
# This software and the related documents are provided as is, with no express or implied warranties,
# other than those that are expressly stated in the License.
#
# *******************************************************************************/
cmake_minimum_required(VERSION 3.7)
project(diagnostics)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "..." FORCE)
endif()
set(CMAKE_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}")
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BUILD_DIR}" CACHE PATH "..." FORCE)
endif()
set(SOURCES_INSTALL_PREFIX install/ CACHE PATH "..." FORCE)
option(BUILD_TESTS "Build test programs" OFF)
option(COVERAGE "Add coverage flags" OFF)
option(BUILD_DOCS "Build html documents" OFF)
if(NOT DEFINED OS)
set(OS "linux")
elseif(${OS} STREQUAL "LIN" OR ${OS} STREQUAL "LINUX")
set(OS "linux")
elseif(${OS} STREQUAL "WIN" OR ${OS} STREQUAL "WINDOWS")
set(OS "windows")
else()
message(SEND_ERROR "Operation systems name '${OS}' is incorrect. Please use LIN or WIN")
endif()
install(PROGRAMS diagnostics.py
DESTINATION ${SOURCES_INSTALL_PREFIX}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
install(DIRECTORY databases
DESTINATION ${SOURCES_INSTALL_PREFIX}
PATTERN "src" EXCLUDE
)
install(FILES README.md DESTINATION ${SOURCES_INSTALL_PREFIX})
install(DIRECTORY configs
DESTINATION ${SOURCES_INSTALL_PREFIX}
USE_SOURCE_PERMISSIONS
PATTERN "linux" EXCLUDE
PATTERN "windows" EXCLUDE
)
install(DIRECTORY configs/${OS}/
DESTINATION ${SOURCES_INSTALL_PREFIX}/configs
USE_SOURCE_PERMISSIONS
)
install(DIRECTORY licensing
DESTINATION ${SOURCES_INSTALL_PREFIX}
)
install(DIRECTORY modules
DESTINATION ${SOURCES_INSTALL_PREFIX}
PATTERN "mock" EXCLUDE
PATTERN "*test*" EXCLUDE
PATTERN "CMakeLists.*" EXCLUDE
PATTERN "*__pycache__*" EXCLUDE
PATTERN "parse_args.py" EXCLUDE
)
execute_process(COMMAND git rev-parse HEAD
OUTPUT_VARIABLE GIT_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(COMMAND git log -1 --date=format:"%d/%m/%Y %T" --format="%ad"
OUTPUT_VARIABLE DATE_OF_CREATION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
configure_file(modules/parse_args.py ${SOURCES_INSTALL_PREFIX}/modules/parse_args.py
@ONLY
)
install(DIRECTORY checkers_py
DESTINATION ${SOURCES_INSTALL_PREFIX}
USE_SOURCE_PERMISSIONS
PATTERN "mock" EXCLUDE
PATTERN "*test*" EXCLUDE
PATTERN "CMakeLists.*" EXCLUDE
PATTERN "*__pycache__*" EXCLUDE
PATTERN "merge_json.py" EXCLUDE
PATTERN "*.json" EXCLUDE
PATTERN "linux" EXCLUDE
PATTERN "windows" EXCLUDE
)
install(DIRECTORY checkers_py/${OS}/
DESTINATION ${SOURCES_INSTALL_PREFIX}/checkers_py
USE_SOURCE_PERMISSIONS
PATTERN ".gitkeep" EXCLUDE
PATTERN "mock" EXCLUDE
PATTERN "*test*" EXCLUDE
PATTERN "CMakeLists.*" EXCLUDE
PATTERN "*__pycache__*" EXCLUDE
PATTERN "merge_json.py" EXCLUDE
PATTERN "*.json" EXCLUDE
)
if(${OS} STREQUAL "linux")
install(FILES ${CMAKE_SOURCE_DIR}/checkers_py/${OS}/data/oneapi_names_map.json
DESTINATION ${SOURCES_INSTALL_PREFIX}/checkers_py/data/)
endif()
install(DIRECTORY checkers_exe
DESTINATION ${SOURCES_INSTALL_PREFIX}
USE_SOURCE_PERMISSIONS
PATTERN "mock" EXCLUDE
PATTERN "*test*" EXCLUDE
PATTERN "CMakeLists.*" EXCLUDE
PATTERN "*__pycache__*" EXCLUDE
PATTERN "linux" EXCLUDE
PATTERN "windows" EXCLUDE
)
install(DIRECTORY checkers_exe/${OS}/
DESTINATION ${SOURCES_INSTALL_PREFIX}/checkers_exe
USE_SOURCE_PERMISSIONS
PATTERN ".gitkeep" EXCLUDE
PATTERN "mock" EXCLUDE
PATTERN "*test*" EXCLUDE
PATTERN "CMakeLists.*" EXCLUDE
PATTERN "*__pycache__*" EXCLUDE
)
include(FetchContent)
set(JSON_C_BASE_DIR "${CMAKE_BUILD_DIR}/json-c")
FetchContent_Declare(
json_c
GIT_REPOSITORY https://github.com/json-c/json-c.git
GIT_TAG json-c-0.15-20200726
GIT_SHALLOW TRUE
SOURCE_DIR "${JSON_C_BASE_DIR}/json-c"
BINARY_DIR "${JSON_C_BASE_DIR}/json-c-build"
SUBBUILD_DIR "${JSON_C_BASE_DIR}/json-c-subbuild"
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-DBUILD_SHARED_LIBS=OFF
-DBUILD_STATIC_LIBS=ON
-DDISABLE_STATIC_FPIC=ON
)
FetchContent_GetProperties(json_c)
if(NOT json_c_POPULATED)
FetchContent_Populate(json_c)
add_subdirectory(
${json_c_SOURCE_DIR}
${json_c_BINARY_DIR}
EXCLUDE_FROM_ALL
)
endif()
include_directories(${JSON_C_BASE_DIR} "${JSON_C_BASE_DIR}/json-c-build")
if(BUILD_TESTS)
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS " \
${CMAKE_C_FLAGS} \
-fPIC"
)
set(CMAKE_CXX_FLAGS " \
${CMAKE_CXX_FLAGS} \
-fPIC"
)
if(COVERAGE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif()
endif()
set(GTEST_BASE_DIR "${CMAKE_BUILD_DIR}/gtest")
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.11.0
GIT_SHALLOW TRUE
SOURCE_DIR "${GTEST_BASE_DIR}/googletest"
BINARY_DIR "${GTEST_BASE_DIR}/googletest-build"
SUBBUILD_DIR "${GTEST_BASE_DIR}/googletest-subbuild"
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-DCMAKE_CXX_FLAGS=${GTEST_CXX_FLAGS}
-DCMAKE_C_FLAGS=${GTEST_C_FLAGS}
-DBUILD_GMOCK=ON
-DBUILD_GTEST=ON
-DBUILD_SHARED_LIBS=OFF
-DBUILD_STATIC_LIBS=ON
)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(BUILD_STATIC_LIBS ON CACHE BOOL "" FORCE)
add_subdirectory(
${googletest_SOURCE_DIR}
${googletest_BINARY_DIR}
EXCLUDE_FROM_ALL
)
endif()
enable_testing()
include(GoogleTest)
endif()
if(CMAKE_COMPILER_IS_GNUCC)
set(SECURITY_COMPILATION_FLAGS " \
-Wall \
-fno-strict-overflow \
-fno-delete-null-pointer-checks \
-fwrapv \
-Wformat=2 \
-D_FORTIFY_SOURCE=2 \
-Wformat-security \
-Werror=format-security \
-fstack-protector-strong \
-fPIE \
-fPIC \
-pie \
-fstack-clash-protection \
-mindirect-branch-register"
)
set(INTEGER_OVERFLOW_AND_COMPARISON_FLAGS " \
-Wtype-limits \
-Wstrict-overflow=5 \
-fstrict-overflow \
-Wsign-compare"
)
set(SECURITY_LINK_FLAGS " \
-Wl,-z,relro \
-Wl,-z,now \
-z noexecstack"
)
set(SECURITY_EXE_LINK_FLAGS " \
-Wl,-pie"
)
set(CMAKE_EXE_LINKER_FLAGS " \
${CMAKE_EXE_LINKER_FLAGS} \
${SECURITY_LINK_FLAGS} \
${SECURITY_EXE_LINK_FLAGS}"
)
set(CMAKE_SHARED_LINKER_FLAGS " \
${CMAKE_SHARED_LINKER_FLAGS} \
${SECURITY_LINK_FLAGS}"
)
set(CMAKE_C_FLAGS " \
${CMAKE_C_FLAGS} \
${SECURITY_COMPILATION_FLAGS} \
${INTEGER_OVERFLOW_AND_COMPARISON_FLAGS}"
)
set(CMAKE_CXX_FLAGS " \
${CMAKE_CXX_FLAGS} \
${SECURITY_COMPILATION_FLAGS} \
${INTEGER_OVERFLOW_AND_COMPARISON_FLAGS}"
)
endif()
if(MSVC)
set(SECURITY_COMPILATION_FLAGS " \
/Wall \
/Qspectre"
)
set(INTEGER_OVERFLOW_AND_COMPARISON_FLAGS " \
/GS"
)
set(SECURITY_LINK_FLAGS " \
/DYNAMICBASE \
/HIGHENTROPYVA \
/LARGEADDRESSAWARE \
/NXCOMPAT \
/GUARD:CF"
)
set(SECURITY_EXE_LINK_FLAGS " \
/ALLOWISOLATION"
)
set(CMAKE_EXE_LINKER_FLAGS " \
${CMAKE_EXE_LINKER_FLAGS} \
${SECURITY_EXE_LINK_FLAGS} \
${SECURITY_LINK_FLAGS}"
)
set(CMAKE_SHARED_LINKER_FLAGS " \
${CMAKE_SHARED_LINKER_FLAGS} \
${SECURITY_LINK_FLAGS}"
)
set(CMAKE_C_FLAGS " \
${CMAKE_C_FLAGS} \
${SECURITY_COMPILATION_FLAGS} \
${INTEGER_OVERFLOW_AND_COMPARISON_FLAGS}"
)
set(CMAKE_CXX_FLAGS " \
${CMAKE_CXX_FLAGS} \
${SECURITY_COMPILATION_FLAGS} \
${INTEGER_OVERFLOW_AND_COMPARISON_FLAGS}"
)
endif()
if(BUILD_DOCS)
execute_process(COMMAND sphinx-build -b html ${CMAKE_SOURCE_DIR}/docs/ ${CMAKE_BUILD_DIR}/docs)
install(DIRECTORY ${CMAKE_BUILD_DIR}/docs
DESTINATION ${SOURCES_INSTALL_PREFIX}
)
endif()
add_subdirectory(checkers_samples)
add_subdirectory(checkers_c)
install(SCRIPT "replace.cmake")