-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
336 lines (261 loc) · 12.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
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
# WINDESKTOP
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakePredefinedTargets")
cmake_minimum_required (VERSION 3.8)
project(InstOpt
VERSION 1.5.0
DESCRIPTION "engine"
LANGUAGES CXX
)
include(CheckCXXCompilerFlag)
include(GNUInstallDirs)
include("${CMAKE_SOURCE_DIR}/cmake/tr_add_project.cmake")
message(STATUS "CMAKE_TOOLCHAIN_FILE is ${CMAKE_TOOLCHAIN_FILE}")
message(STATUS "CMAKE_INSTALL_INCLUDEDIR is ${CMAKE_INSTALL_INCLUDEDIR}")
message(STATUS "CMAKE_CURRENT_LIST_DIR is ${CMAKE_CURRENT_LIST_DIR}")
# ---------------------------------------------------------------------------------------
# Compiler config
# ---------------------------------------------------------------------------------------
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
set(VALGRIND_PROJ_DIR "src/valgrind-3.17.0")
option(INSTOPT_BUILD_ALL "Build all artifacts" OFF)
# build shared option
option(INSTOPT_BUILD_SHARED "Build shared library" OFF)
# precompiled headers option
option(INSTOPT_ENABLE_PCH "Build static or shared library using precompiled header to speed up compilation time" OFF)
# example options
option(INSTOPT_BUILD_EXAMPLE "Build example" ${INSTOPT_MASTER_PROJECT})
option(INSTOPT_BUILD_EXAMPLE_HO "Build header only example" OFF)
# testing options
option(INSTOPT_BUILD_TESTS "Build tests" OFF)
option(INSTOPT_BUILD_TESTS_HO "Build tests using the header only version" OFF)
# bench options
option(INSTOPT_BUILD_BENCH "Build benchmarks (Requires https://github.com/google/benchmark.git to be installed)" OFF)
# sanitizer options
option(INSTOPT_SANITIZE_ADDRESS "Enable address sanitizer in tests" OFF)
# warning options
option(INSTOPT_BUILD_WARNINGS "Enable compiler warnings" OFF)
# install options
option(INSTOPT_INSTALL "Generate the install target" ${INSTOPT_MASTER_PROJECT})
option(INSTOPT_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)
option(INSTOPT_FMT_EXTERNAL_HO "Use external fmt header-only library instead of bundled" OFF)
option(INSTOPT_NO_EXCEPTIONS "Compile with -fno-exceptions. Call abort() on any spdlog exceptions" OFF)
if(INSTOPT_FMT_EXTERNAL AND INSTOPT_FMT_EXTERNAL_HO)
message(FATAL_ERROR "INSTOPT_FMT_EXTERNAL and INSTOPT_FMT_EXTERNAL_HO are mutually exclusive")
endif()
option(DEBUG_GABLE "print cmake info" OFF)
option(BUILD_VALGRIND "BUILD VALGRIND" OFF)
option(BUILD_TRIGGERBUG "BUILD TRIGGERBUG" OFF)
option(BUILD_CRYPTO_ANALYZER "BUILD CRYPTO_ANALYZER" OFF)
option(BUILD_VEXLLVM "BUILD VEXLLVM" OFF)
option(BUILD_PYTHON_FRONTEND "BUILD PYTHON_BLACKEND" OFF)
option(BUILD_TRTEST "BUILD DEVELOP TEST" ON)
#option(BUILD_CFG "BUILD CFG" OFF)
message(STATUS "TR version ${TriggerBug_VERSION} ")
if ("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
message(FATAL_ERROR "In source builds are not allowed. You should invoke "
"CMake from a different directory.")
endif()
# -Gr __fastcall
# -Ot 代码速度优先
# -Oi inline内部函数
# -O3 优化速度
# /GS 安全检查
# /MD 多线程DLL库
# /Ob2 内联函数扩展 - 任何适用项 inline
# /Ob2 展开标记为 inline 或 __inline 的函数和编译器选择的任何其他函数(由编译器自行进行展开,通常称作自动内联)
# set(EXTINSN -mmmx -msse -msse2 -msse3 -msse4.1 -msse4.2 -mssse3 -mavx -mavx2)
add_definitions(-D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS)
add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
IF (WIN32)
MESSAGE(STATUS "Now is windows")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /utf-8 /Ob2 /Gr /Ot /Oi /O3 /GS- ")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /utf-8 /Ob2 /Gr /Ot /Oi /O3 /GS- ")
add_definitions(/arch:AVX2)
# add_compile_options(-ftrack-macro-expansion=0 -fno-diagnostics-show-caret)
else()
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -openmp -Qopenmp -Wall")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -openmp -Qopenmp -Wall")
add_compile_options(-fdeclspec
-fms-extensions
-fms-compatibility-version=19.00
-fdiagnostics-show-template-tree
-fimplicit-templates
)
ENDIF ()
# -fms-extensions open Microsoft extension (to support explicit constructor calls)
# https://clang.llvm.org/docs/UsersManual.html
add_compile_options(
# -fdelayed-template-parsing add it after libz3
-Wno-microsoft-explicit-constructor-call
-Wno-microsoft-unqualified-friend
-Wno-ambiguous-member-template
-Wno-extern-c-compat
-Wno-microsoft-template
-Wno-format
-Wno-switch
-Wno-unused-variable
)
add_compile_options(-fdelayed-template-parsing)
set(TR_COMPONENT_CXX_FLAGS "")
if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel"))
set(SSE_FLAGS "-msse" "-msse2")
set(AVX_FLAGS "-mavx" "-mavx2")
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
set(SSE_FLAGS "-msse" "-msse2" )
set(AVX_FLAGS "-mavx" "-mavx2")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(SSE_FLAGS "/arch:SSE2")
set(AVX_FLAGS "/arch:AVX2")
else()
message(FATAL_ERROR "Unknown compiler ${CMAKE_CXX_COMPILER_ID}")
endif()
check_cxx_compiler_flag("-msse2" HAS_SSE2)
if (${HAS_SSE2})
add_definitions(${SSE_FLAGS})
else()
message(WARNING "your operating system does not support ${SSE_FLAGS} vector extensions")
endif()
check_cxx_compiler_flag("-mavx2" HAS_AVX2)
if (${HAS_AVX2})
add_definitions(${AVX_FLAGS})
else()
message(WARNING "your operating system does not support ${AVX_FLAGS} vector extensions")
endif()
unset(SSE_FLAGS)
unset(AVX_FLAGS)
# 加入一个配置头文件,用于处理 CMake 对源码的设置
#configure_file (
# "${PROJECT_SOURCE_DIR}/config.h.in"
# "${PROJECT_BINARY_DIR}/config.h"
# )
# The package gflags:x64-windows provides CMake targets:
find_package(LLVM CONFIG REQUIRED)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message(STATUS "Using LLVM_BINARY_DIR in: ${LLVM_BINARY_DIR}")
# LLVM_INSTALL_PREFIX
include("${CMAKE_SOURCE_DIR}/cmake/BCCompiler.cmake")
# LLVM VISUALIZERS
SET(LLVMVISUALIZERS_PATH support/LLVMVisualizers/)
SET(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION TRUE)
message(STATUS "Using LLVMVisualizers in: ${LLVMVISUALIZERS_PATH}")
add_subdirectory(${LLVMVISUALIZERS_PATH})
# The package gflags:x64-windows provides CMake targets:
find_package(gflags REQUIRED)
# target_link_libraries(main PRIVATE gflags_shared gflags::gflags_shared)
# The package glog:x64-windows provides CMake targets:
find_package(glog REQUIRED)
# target_link_libraries(main PRIVATE glog::glog)
# The package spdlog:x64-windows provides CMake targets:
find_package(spdlog REQUIRED)
# target_link_libraries(main PRIVATE spdlog::spdlog spdlog::INSTOPT_header_only)
# The package z3:x64-windows provides CMake targets:
find_package(Z3 REQUIRED)
# target_link_libraries(main PRIVATE z3::libz3)
message(STATUS "Z3_FOUND: ${Z3_FOUND}")
message(STATUS "Found Z3 ${Z3_VERSION_STRING}")
message(STATUS "Z3_DIR: ${Z3_DIR}")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(glog DEFAULT_MSG GLOG_INCLUDE_DIR GLOG_LIBRARY)
target_include_directories(z3::libz3 INTERFACE ${Z3_CXX_INCLUDE_DIRS})
target_include_directories(LLVMCore INTERFACE ${LLVM_INCLUDE_DIRS})
target_compile_definitions(LLVMCore INTERFACE ${LLVM_DEFINITIONS})
target_include_directories(gflags_shared INTERFACE ${GFLAGS_INCLUDE_DIR})
#target_include_directories(glog::glog INTERFACE ${GLOG_INCLUDE_DIR})
#if(NOT GLOG_INCLUDE_DIR)
# message(FATAL_ERROR "no ${GLOG_INCLUDE_DIR}")
#endif()
add_subdirectory("src/tracer")
add_subdirectory("src/utils")
TR_add_subdir(obj.instoptVexHelper "src/helper" ON)
TR_add_subdir(libvalgrind ${VALGRIND_PROJ_DIR}/VEX/ BUILD_VALGRIND)
TR_add_subdir(libengine "src/engine" BUILD_TRIGGERBUG)
TR_add_subdir(libcryptoAnalyzer "src/crypto_analyzer" BUILD_CRYPTO_ANALYZER)
TR_add_subdir(libvexllvm "src/vexllvm" BUILD_VEXLLVM)
#TR_add_subdir(TRtest "tests" BUILD_TRTEST)
#TR_add_subdir(libcfg "src/CFG" BUILD_CFG)
IF (${BUILD_TRTEST})
add_subdirectory("tests")
ENDIF()
IF (${BUILD_PYTHON_FRONTEND})
find_library(TR_PYTHON3_LIB_PATH python3)
IF(NOT TR_PYTHON3_LIB_PATH)
MESSAGE(FATAL_ERROR "TriggerBug: python3.x dir not found")
ENDIF(NOT TR_PYTHON3_LIB_PATH)
MESSAGE(STATUS ${TR_PYTHON3_LIB_PATH} " found")
TR_add_subdir(libpythonfront "src/python" BUILD_PYTHON_FRONTEND)
ENDIF()
# ---------------------------------------------------------------------------------------
# Build binaries
# ---------------------------------------------------------------------------------------
if(INSTOPT_BUILD_EXAMPLE OR INSTOPT_BUILD_EXAMPLE_HO OR INSTOPT_BUILD_ALL)
message(STATUS "Generating example(s)")
add_subdirectory(example)
INSTOPT_enable_warnings(example)
if(INSTOPT_BUILD_EXAMPLE_HO)
INSTOPT_enable_warnings(example_header_only)
endif()
endif()
if(INSTOPT_BUILD_TESTS OR INSTOPT_BUILD_TESTS_HO OR INSTOPT_BUILD_ALL)
message(STATUS "Generating tests")
enable_testing()
add_subdirectory(tests)
endif()
if(INSTOPT_BUILD_BENCH OR INSTOPT_BUILD_ALL)
message(STATUS "Generating benchmarks")
add_subdirectory(bench)
endif()
# ---------------------------------------------------------------------------------------
# Install
# ---------------------------------------------------------------------------------------
if(INSTOPT_INSTALL)
message(STATUS "Generating install")
set(project_config_in "${CMAKE_CURRENT_LIST_DIR}/cmake/spdlogConfig.cmake.in")
set(project_config_out "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfig.cmake")
set(config_targets_file "spdlogConfigTargets.cmake")
set(version_config_file "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfigVersion.cmake")
set(export_dest_dir "${CMAKE_INSTALL_LIBDIR}/cmake/spdlog")
set(pkgconfig_install_dir "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
set(pkg_config "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
# ---------------------------------------------------------------------------------------
# Include files
# ---------------------------------------------------------------------------------------
install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" PATTERN "fmt/bundled" EXCLUDE)
install(
TARGETS spdlog INSTOPT_header_only
EXPORT spdlog
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
if(NOT INSTOPT_FMT_EXTERNAL AND NOT INSTOPT_FMT_EXTERNAL_HO)
install(DIRECTORY include/${PROJECT_NAME}/fmt/bundled/
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/fmt/bundled/")
endif()
# ---------------------------------------------------------------------------------------
# Install pkg-config file
# ---------------------------------------------------------------------------------------
get_target_property(PKG_CONFIG_DEFINES spdlog INTERFACE_COMPILE_DEFINITIONS)
string(REPLACE ";" " -D" PKG_CONFIG_DEFINES "${PKG_CONFIG_DEFINES}")
string(CONCAT PKG_CONFIG_DEFINES "-D" "${PKG_CONFIG_DEFINES}")
configure_file("cmake/${PROJECT_NAME}.pc.in" "${pkg_config}" @ONLY)
install(FILES "${pkg_config}" DESTINATION "${pkgconfig_install_dir}")
# ---------------------------------------------------------------------------------------
# Install CMake config files
# ---------------------------------------------------------------------------------------
install(EXPORT spdlog DESTINATION ${export_dest_dir} NAMESPACE spdlog:: FILE ${config_targets_file})
include(CMakePackageConfigHelpers)
configure_file("${project_config_in}" "${project_config_out}" @ONLY)
write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion)
install(FILES "${project_config_out}" "${version_config_file}" DESTINATION "${export_dest_dir}")
# ---------------------------------------------------------------------------------------
# Support creation of installable packages
# ---------------------------------------------------------------------------------------
include(cmake/spdlogCPack.cmake)
endif()
# set_target_properties(acc_gen PROPERTIES FOLDER "Utils")
# set_target_properties(intrinsics_gen PROPERTIES FOLDER "Utils")
# set_target_properties(omp_gen PROPERTIES FOLDER "Utils")