@@ -30,8 +30,8 @@ include(CTest)
30
30
if (LLVM_Z3_INSTALL_DIR )
31
31
find_package (Z3 4.7.1 )
32
32
set (need_z3 TRUE )
33
- elseif (DEFINED ENV{TRAILOFBITS_LIBRARIES} )
34
- set (LLVM_Z3_INSTALL_DIR "$ENV{TRAILOFBITS_LIBRARIES } /z3" )
33
+ elseif (DEFINED CXX_COMMON_REPOSITORY_ROOT )
34
+ set (LLVM_Z3_INSTALL_DIR "${CXX_COMMON_REPOSITORY_ROOT } /z3" )
35
35
set (need_z3 TRUE )
36
36
else ()
37
37
set (need_z3 FALSE )
@@ -67,38 +67,80 @@ endif()
67
67
# libraries
68
68
#
69
69
70
+ # LLVM
70
71
find_package (LLVM REQUIRED CONFIG HINTS ${FINDPACKAGE_LLVM_HINTS} )
71
72
72
73
string (REPLACE "." ";" LLVM_VERSION_LIST ${LLVM_PACKAGE_VERSION} )
73
74
list (GET LLVM_VERSION_LIST 0 LLVM_MAJOR_VERSION )
74
75
list (GET LLVM_VERSION_LIST 1 LLVM_MINOR_VERSION )
75
76
76
- set (LLVM_LIBRARIES
77
- LLVMCore LLVMAnalysis LLVMSupport LLVMipo LLVMIRReader
78
- LLVMBitReader LLVMBitWriter LLVMTransformUtils LLVMScalarOpts
79
- LLVMLTO
77
+ add_library (thirdparty_llvm INTERFACE )
78
+ target_include_directories (thirdparty_llvm SYSTEM INTERFACE
79
+ ${LLVM_INCLUDE_DIRS}
80
+ )
81
+ target_compile_definitions (thirdparty_llvm INTERFACE
82
+ ${LLVM_DEFINITIONS}
83
+ )
84
+
85
+ # Go find only the static libraries of LLVM, and link against those.
86
+ foreach (LLVM_LIB IN LISTS LLVM_AVAILABLE_LIBS )
87
+ get_target_property (LLVM_LIB_TYPE ${LLVM_LIB} TYPE )
88
+ if (LLVM_LIB_TYPE STREQUAL "STATIC_LIBRARY" )
89
+ list (APPEND LLVM_LIBRARIES "${LLVM_LIB} " )
90
+ endif ()
91
+ endforeach ()
92
+
93
+ # These are out-of-order in `LLVM_AVAILABLE_LIBS` and should always be last.
94
+ list (REMOVE_ITEM LLVM_LIBRARIES LLVMMC LLVMCore LLVMSupport )
95
+ list (APPEND LLVM_LIBRARIES LLVMMC LLVMCore LLVMSupport )
96
+ message (WARNING "Libraries: ${LLVM_LIBRARIES} " )
97
+
98
+
99
+ target_link_libraries (thirdparty_llvm INTERFACE
100
+ ${LLVM_LIBRARIES}
80
101
)
81
102
82
- list (APPEND PROJECT_LIBRARIES ${LLVM_LIBRARIES} )
83
- list (APPEND PROJECT_DEFINITIONS ${LLVM_DEFINITIONS} )
84
- list (APPEND PROJECT_INCLUDEDIRECTORIES ${LLVM_INCLUDE_DIRS} )
103
+ # Microsoft Z3
104
+ add_library (thirdparty_z3 INTERFACE )
105
+ if (Z3_FOUND )
106
+ target_include_directories (thirdparty_z3 SYSTEM INTERFACE
107
+ ${Z3_INCLUDE_DIR}
108
+ )
109
+ target_link_libraries (thirdparty_z3 INTERFACE
110
+ ${Z3_LIBRARIES}
111
+ )
112
+ endif ()
85
113
86
- # xed
114
+ # Intel XED
87
115
find_package (XED REQUIRED )
88
- list (APPEND PROJECT_LIBRARIES ${XED_LIBRARIES} )
89
- list (APPEND PROJECT_INCLUDEDIRECTORIES ${XED_INCLUDE_DIRS} )
116
+ add_library (thirdparty_xed INTERFACE )
117
+ target_include_directories (thirdparty_xed SYSTEM INTERFACE
118
+ ${XED_INCLUDE_DIRS}
119
+ )
120
+ target_link_libraries (thirdparty_xed INTERFACE
121
+ ${XED_LIBRARIES}
122
+ )
90
123
91
- # google log module
124
+ # Google glog module
92
125
find_package (glog REQUIRED )
93
- list (APPEND PROJECT_LIBRARIES glog::glog )
126
+ add_library (thirdparty_glog INTERFACE )
127
+ target_link_libraries (thirdparty_glog INTERFACE
128
+ glog::glog
129
+ )
94
130
95
- # gflags
131
+ # Google gflags
96
132
find_package (gflags REQUIRED )
97
- list (APPEND PROJECT_LIBRARIES gflags )
133
+ add_library (thirdparty_gflags INTERFACE )
134
+ target_link_libraries (thirdparty_gflags INTERFACE
135
+ gflags
136
+ )
98
137
99
- # windows sdk
138
+ # Windows SDK
139
+ add_library (thirdparty_win32 INTERFACE )
100
140
if (DEFINED WIN32 )
101
- list (APPEND PROJECT_LIBRARIES "Kernel32.lib" )
141
+ target_link_libraries (thirdparty_win32 INTERFACE
142
+ "Kernel32.lib"
143
+ )
102
144
endif ()
103
145
104
146
#
@@ -122,14 +164,10 @@ endif()
122
164
set (REMILL_BUILD_SEMANTICS_DIR_X86 "${CMAKE_CURRENT_BINARY_DIR} /remill/Arch/X86/Runtime/" )
123
165
set (REMILL_BUILD_SEMANTICS_DIR_AARCH64 "${CMAKE_CURRENT_BINARY_DIR} /remill/Arch/AArch64/Runtime/" )
124
166
125
- list (APPEND PROJECT_DEFINITIONS "REMILL_INSTALL_SEMANTICS_DIR=\" ${REMILL_INSTALL_SEMANTICS_DIR} /\" " )
126
- list (APPEND PROJECT_DEFINITIONS "REMILL_BUILD_SEMANTICS_DIR_X86=\" ${REMILL_BUILD_SEMANTICS_DIR_X86} \" " )
127
- list (APPEND PROJECT_DEFINITIONS "REMILL_BUILD_SEMANTICS_DIR_AARCH64=\" ${REMILL_BUILD_SEMANTICS_DIR_AARCH64} \" " )
128
-
129
167
# verion data
130
168
add_subdirectory (remill/Version )
131
169
132
- add_library (${PROJECT_NAME} STATIC
170
+ add_library (remill STATIC
133
171
remill/Arch/AArch64/Arch.cpp
134
172
remill/Arch/AArch64/Decode.cpp
135
173
remill/Arch/AArch64/Extract.cpp
@@ -151,14 +189,102 @@ add_library(${PROJECT_NAME} STATIC
151
189
remill/OS/OS.cpp
152
190
)
153
191
154
- set_property (TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON )
192
+ set_property (TARGET remill PROPERTY POSITION_INDEPENDENT_CODE ON )
193
+ set (THIRDPARTY_LIBRARY_LIST thirdparty_z3 thirdparty_llvm thirdparty_xed thirdparty_glog thirdparty_gflags )
155
194
156
195
# add everything as public.
157
- target_link_libraries (${PROJECT_NAME} PUBLIC ${PROJECT_LIBRARIES} RemillVersion )
158
- target_include_directories (${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR} )
159
- target_include_directories (${PROJECT_NAME} SYSTEM PUBLIC ${PROJECT_INCLUDEDIRECTORIES} )
160
- target_compile_definitions (${PROJECT_NAME} PUBLIC ${PROJECT_DEFINITIONS} ${GLOBAL_DEFINITIONS} )
161
- target_compile_options (${PROJECT_NAME} PUBLIC ${GLOBAL_CXXFLAGS} )
196
+
197
+ if (UNIX AND NOT APPLE )
198
+ #For Linux builds, group LLVM libraries into a single group
199
+ # that avoids frustrating library ordering issues
200
+ set (LINKER_START_GROUP "-Wl,--start-group" )
201
+ set (LINKER_END_GROUP "-Wl,--end-group" )
202
+ else ()
203
+ set (LINKER_START_GROUP "" )
204
+ set (LINKER_END_GROUP "" )
205
+ endif ()
206
+
207
+
208
+ target_link_libraries (remill LINK_PUBLIC
209
+ ${LINKER_START_GROUP} ${THIRDPARTY_LIBRARY_LIST} ${LINKER_END_GROUP}
210
+ RemillVersion
211
+ )
212
+
213
+ target_include_directories (remill PUBLIC ${CMAKE_SOURCE_DIR} )
214
+
215
+ if (WIN32 )
216
+ # warnings and compiler settings
217
+ target_compile_options (remill PUBLIC
218
+ /MD /nologo /W3 /EHsc /wd4141 /wd4146 /wd4180 /wd4244
219
+ /wd4258 /wd4267 /wd4291 /wd4345 /wd4351 /wd4355 /wd4456
220
+ /wd4457 /wd4458 /wd4459 /wd4503 /wd4624 /wd4722 /wd4800
221
+ /wd4100 /wd4127 /wd4512 /wd4505 /wd4610 /wd4510 /wd4702
222
+ /wd4245 /wd4706 /wd4310 /wd4701 /wd4703 /wd4389 /wd4611
223
+ /wd4805 /wd4204 /wd4577 /wd4091 /wd4592 /wd4324
224
+ )
225
+
226
+ target_compile_definitions (remill PUBLIC
227
+ _CRT_SECURE_NO_DEPRECATE
228
+ _CRT_SECURE_NO_WARNINGS
229
+ _CRT_NONSTDC_NO_DEPRECATE
230
+ _CRT_NONSTDC_NO_WARNINGS
231
+ _SCL_SECURE_NO_DEPRECATE
232
+ _SCL_SECURE_NO_WARNINGS
233
+ GOOGLE_PROTOBUF_NO_RTTI
234
+ )
235
+
236
+ else ()
237
+ # warnings and compiler settings
238
+ target_compile_options (remill PUBLIC
239
+ -Wall -Wextra -Wno-unused-parameter -Wno-c++98-compat
240
+ -Wno-unreachable-code-return -Wno-nested-anon-types
241
+ -Wno-extended-offsetof
242
+ -Wno-variadic-macros -Wno-return-type-c-linkage
243
+ -Wno-c99-extensions -Wno-ignored-attributes -Wno-unused-local-typedef
244
+ -Wno-unknown-pragmas -Wno-unknown-warning-option -fPIC
245
+ -fno-omit-frame-pointer -fvisibility-inlines-hidden
246
+ -fno-asynchronous-unwind-tables
247
+ )
248
+
249
+ # Clang-specific warnings/error options
250
+ if ("${CMAKE_C_COMPILER_ID} " STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID} " STREQUAL "AppleClang" )
251
+ target_compile_options (remill PUBLIC
252
+ -Wgnu-alignof-expression -Wno-gnu-anonymous-struct -Wno-gnu-designator
253
+ -Wno-gnu-zero-variadic-macro-arguments -Wno-gnu-statement-expression
254
+ -fno-aligned-allocation
255
+ )
256
+ endif ()
257
+
258
+ # debug symbols
259
+ if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
260
+ target_compile_options (remill PUBLIC
261
+ -gdwarf-2 -g3
262
+ )
263
+ endif ()
264
+
265
+ # optimization flags and definitions
266
+ if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
267
+ target_compile_options (remill PUBLIC
268
+ -O0
269
+ )
270
+ target_compile_definitions (remill PUBLIC
271
+ "DEBUG"
272
+ )
273
+ else ()
274
+ target_compile_options (remill PUBLIC
275
+ -O2
276
+ )
277
+ target_compile_definitions (remill PUBLIC
278
+ "NDEBUG"
279
+ )
280
+ endif ()
281
+ endif ()
282
+
283
+ target_compile_definitions (remill PUBLIC
284
+ "REMILL_INSTALL_SEMANTICS_DIR=\" ${REMILL_INSTALL_SEMANTICS_DIR} /\" "
285
+ "REMILL_BUILD_SEMANTICS_DIR_X86=\" ${REMILL_BUILD_SEMANTICS_DIR_X86} \" "
286
+ "REMILL_BUILD_SEMANTICS_DIR_AARCH64=\" ${REMILL_BUILD_SEMANTICS_DIR_AARCH64} \" "
287
+ )
162
288
163
289
#
164
290
# Also install clang, libllvm and llvm-link
@@ -234,7 +360,7 @@ endfunction()
234
360
set (INSTALLED_CLANG_NAME "remill-clang-${REMILL_LLVM_VERSION}${executable_extension} " )
235
361
set (INSTALLED_LLVMLINK_NAME "remill-llvm-link-${REMILL_LLVM_VERSION}${executable_extension} " )
236
362
237
- if ("${LIBRARY_REPOSITORY_ROOT } " STREQUAL "" OR NOT EXISTS "${LIBRARY_REPOSITORY_ROOT } /llvm" )
363
+ if ("${CXX_COMMON_REPOSITORY_ROOT } " STREQUAL "" OR NOT EXISTS "${CXX_COMMON_REPOSITORY_ROOT } /llvm" )
238
364
set (INSTALLED_LIBLLVM_NAME "${dynamic_lib_prefix} LLVM-${REMILL_LLVM_VERSION} .${dynamic_lib_extension} " )
239
365
240
366
# system binaries are not built statically, so we need to fix the rpath
@@ -268,10 +394,10 @@ if("${LIBRARY_REPOSITORY_ROOT}" STREQUAL "" OR NOT EXISTS "${LIBRARY_REPOSITORY_
268
394
else ()
269
395
# The executable in our binary repository are statically built, meaning that we don't need
270
396
# to change the rpath
271
- InstallExternalTarget ("ext_clang" "${LIBRARY_REPOSITORY_ROOT } /llvm/bin/clang${executable_extension} "
397
+ InstallExternalTarget ("ext_clang" "${CXX_COMMON_REPOSITORY_ROOT } /llvm/bin/clang${executable_extension} "
272
398
"${install_folder} /bin" "${INSTALLED_CLANG_NAME} " )
273
399
274
- InstallExternalTarget ("ext_llvmlink" "${LIBRARY_REPOSITORY_ROOT } /llvm/bin/llvm-link${executable_extension} "
400
+ InstallExternalTarget ("ext_llvmlink" "${CXX_COMMON_REPOSITORY_ROOT } /llvm/bin/llvm-link${executable_extension} "
275
401
"${install_folder} /bin" "${INSTALLED_LLVMLINK_NAME} " )
276
402
endif ()
277
403
@@ -282,9 +408,42 @@ install(TARGETS "${PROJECT_NAME}"
282
408
283
409
set (REMILL_LIBRARY_LOCATION "${install_folder} /lib/libremill.a" )
284
410
set (REMILL_INCLUDE_LOCATION "${install_folder} /include" )
411
+ get_target_property (REMILL_COMPILE_OPTIONS remill COMPILE_OPTIONS )
412
+ get_target_property (REMILL_COMPILE_DEFINITIONS remill COMPILE_DEFINITIONS )
413
+
414
+ GetTargetTree (THIRDPARTY_LIBRARIES ${THIRDPARTY_LIBRARY_LIST} )
415
+ GetPublicIncludeFolders (THIRDPARTY_INCLUDE_DIRECTORIES ${THIRDPARTY_LIBRARIES} )
416
+ foreach (THIRDPARTY_LIB IN LISTS THIRDPARTY_LIBRARIES )
417
+ string (SUBSTRING "${THIRDPARTY_LIB} " 0 1 THIRDPARTY_LIB_PREFIX )
418
+ if (TARGET ${THIRDPARTY_LIB} )
419
+ get_target_property (THIRDPARTY_LIB_TYPE ${THIRDPARTY_LIB} TYPE )
420
+ if (THIRDPARTY_LIB_TYPE STREQUAL "STATIC_LIBRARY" OR THIRDPARTY_LIB_TYPE STREQUAL "SHARED_LIBRARY" )
421
+ list (APPEND THIRDPARTY_LIBRARY_FILES "$${}<TARGET_FILE:${THIRDPARTY_LIB} >" )
422
+ endif ()
423
+ elseif ("${THIRDPARTY_LIB_PREFIX} " STREQUAL "$${}" )
424
+ # E.g. $<LINK_ONLY:...>
425
+ else ()
426
+ list (APPEND THIRDPARTY_LIBRARY_FILES "${THIRDPARTY_LIB} " )
427
+ endif ()
428
+ endforeach ()
429
+
430
+ list (REMOVE_DUPLICATES THIRDPARTY_LIBRARY_FILES )
431
+ if (NOT "x{$LINKER_START_GROUP}x" STREQUAL "xx" )
432
+ list (INSERT THIRDPARTY_LIBRARY_FILES 0 "${LINKER_START_GROUP} " )
433
+ list (APPEND THIRDPARTY_LIBRARY_FILES "${LINKER_END_GROUP} " )
434
+ endif ()
435
+
436
+ # First do the basic substitutions.
285
437
configure_file (
286
438
"${CMAKE_CURRENT_SOURCE_DIR} /cmake/remillConfig.cmake.in"
287
- "${CMAKE_CURRENT_BINARY_DIR} /remillConfig.cmake"
439
+ "${CMAKE_CURRENT_BINARY_DIR} /remillConfig.cmake.pregen"
440
+ @ONLY
441
+ )
442
+
443
+ # Then expand the generator expressions added to `THIRDPARTY_LIBRARY_FILES`.
444
+ file (GENERATE
445
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR} /remillConfig.cmake"
446
+ INPUT "${CMAKE_CURRENT_BINARY_DIR} /remillConfig.cmake.pregen"
288
447
)
289
448
290
449
install (FILES "${CMAKE_CURRENT_BINARY_DIR} /remillConfig.cmake"
@@ -316,6 +475,7 @@ install(FILES
316
475
"${CMAKE_CURRENT_SOURCE_DIR} /remill/BC/Compat/Attributes.h"
317
476
"${CMAKE_CURRENT_SOURCE_DIR} /remill/BC/Compat/BitcodeReaderWriter.h"
318
477
"${CMAKE_CURRENT_SOURCE_DIR} /remill/BC/Compat/CallingConvention.h"
478
+ "${CMAKE_CURRENT_SOURCE_DIR} /remill/BC/Compat/CTypes.h"
319
479
"${CMAKE_CURRENT_SOURCE_DIR} /remill/BC/Compat/DataLayout.h"
320
480
"${CMAKE_CURRENT_SOURCE_DIR} /remill/BC/Compat/DebugInfo.h"
321
481
"${CMAKE_CURRENT_SOURCE_DIR} /remill/BC/Compat/Error.h"
0 commit comments