-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
581 lines (525 loc) · 21.8 KB
/
Copy pathCMakeLists.txt
File metadata and controls
581 lines (525 loc) · 21.8 KB
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
cmake_minimum_required(VERSION 3.5)
cmake_policy(SET CMP0048 NEW)
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()
project (Bloaty VERSION 1.1)
include(CTest)
set(CMAKE_CXX_STANDARD 20)
set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Group projects in visual studio
# Options we define for users.
option(BLOATY_ENABLE_ASAN "Enable address sanitizer." OFF)
option(BLOATY_ENABLE_UBSAN "Enable undefined behavior sanitizer." OFF)
option(BLOATY_ENABLE_CMAKETARGETS "Enable installing cmake target files." ON)
option(BLOATY_ENABLE_BUILDID "Enable build id." ON)
option(BLOATY_ENABLE_RE2 "Enable the support for regular expression functions." ON)
option(BLOATY_PREFER_SYSTEM_ABSL "Prefer to use the system absl if available" YES)
option(BLOATY_PREFER_SYSTEM_CAPSTONE "Prefer to use the system capstone if available" YES)
option(BLOATY_PREFER_SYSTEM_PROTOBUF "Prefer to use the system protobuf if available" YES)
option(BLOATY_PREFER_SYSTEM_RE2 "Prefer to use the system re2 if available" YES)
option(BLOATY_PREFER_SYSTEM_ZLIB "Prefer to use the system zlib if available" YES)
option(BLOATY_PREFER_SYSTEM_ZSTD "Prefer to use the system zstd if available" YES)
if(UNIX OR MINGW)
find_package(PkgConfig)
if(BLOATY_PREFER_SYSTEM_ZLIB)
find_package(ZLIB)
endif()
if(BLOATY_PREFER_SYSTEM_ZSTD)
pkg_search_module(ZSTD libzstd)
endif()
if(BLOATY_ENABLE_RE2 AND BLOATY_PREFER_SYSTEM_RE2)
pkg_search_module(RE2 re2)
endif()
if(BLOATY_PREFER_SYSTEM_CAPSTONE)
pkg_search_module(CAPSTONE capstone)
endif()
if(BLOATY_PREFER_SYSTEM_PROTOBUF)
pkg_search_module(PROTOBUF protobuf)
endif()
if(BLOATY_ENABLE_RE2)
if(RE2_FOUND)
MESSAGE(STATUS "System re2 found, using")
else()
MESSAGE(STATUS "System re2 not found, using bundled version")
endif()
endif()
if(CAPSTONE_FOUND)
MESSAGE(STATUS "System capstone found, using")
else()
MESSAGE(STATUS "System capstone not found, using bundled version")
endif()
if(PROTOBUF_FOUND)
MESSAGE(STATUS "System protobuf found, using")
else()
MESSAGE(STATUS "System protobuf not found, using bundled version")
endif()
if (ZLIB_FOUND)
MESSAGE(STATUS "System zlib found, using")
else()
MESSAGE(STATUS "System zlib not found, using bundled version")
endif()
if (ZSTD_FOUND)
MESSAGE(STATUS "System zstd found, using")
else()
MESSAGE(STATUS "System zstd not found, using bundled version")
endif()
endif()
if(BLOATY_PREFER_SYSTEM_ABSL)
find_package(absl CONFIG)
endif()
if(absl_FOUND)
MESSAGE(STATUS "System absl found, using")
else()
MESSAGE(STATUS "System absl not found, using bundled version")
endif()
# Set default build type.
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
# Helper function for checking out Git submodules.
function(init_submodule PATH)
message(STATUS "initializing submodule ${PATH}")
execute_process(
COMMAND git submodule update --init --recursive "${PATH}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
endfunction()
# Add third_party libraries, disabling as much as we can of their builds.
if(NOT absl_FOUND)
init_submodule(third_party/abseil-cpp)
set(BLOATY_BUILD_TESTING_SAVE "${BUILD_TESTING}")
set(BUILD_TESTING OFF)
set(ABSL_MSVC_STATIC_RUNTIME ON)
set(ABSL_ENABLE_INSTALL ON)
add_subdirectory(third_party/abseil-cpp)
set(BUILD_TESTING "${BLOATY_BUILD_TESTING_SAVE}")
endif()
if(BLOATY_ENABLE_RE2)
add_definitions(-DUSE_RE2)
endif()
include(CheckCXXCompilerFlag)
# Set MSVC runtime before including thirdparty libraries
if(MSVC)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>)
else()
# Link also the runtime library statically so that MSVCR*.DLL is not required at runtime.
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
# This is achieved by replacing msvc option /MD with /MT and /MDd with /MTd
# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if (flag_var MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif()
endforeach()
endif()
endif()
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
init_submodule(third_party/demumble)
if(UNIX OR MINGW)
if(BLOATY_ENABLE_RE2)
if(RE2_FOUND)
include_directories(${RE2_INCLUDE_DIRS})
else()
init_submodule(third_party/re2)
set(RE2_BUILD_TESTING OFF CACHE BOOL "enable testing for RE2" FORCE)
add_subdirectory(third_party/re2)
include_directories(third_party/re2)
endif()
endif()
if(CAPSTONE_FOUND)
# Work around pkg-config files that incorrectly point to include/capstone
# instead of include e.g. homebrew's capstone package
get_filename_component(CAPSTONE_DIR_NAME "${CAPSTONE_INCLUDE_DIRS}" NAME)
if(CAPSTONE_DIR_NAME STREQUAL "capstone")
get_filename_component(CAPSTONE_INCLUDE_DIRS "${CAPSTONE_INCLUDE_DIRS}" DIRECTORY)
endif()
include_directories(${CAPSTONE_INCLUDE_DIRS})
else()
init_submodule(third_party/capstone)
set(BUILD_STATIC_LIBS ON CACHE BOOL "Build static library" FORCE)
set(CAPSTONE_BUILD_SHARED OFF CACHE BOOL "Build shared library" FORCE)
set(CAPSTONE_BUILD_TESTS OFF CACHE BOOL "Build tests" FORCE)
add_subdirectory(third_party/capstone)
include_directories(third_party/capstone/include)
endif()
if(PROTOBUF_FOUND)
include_directories(${PROTOBUF_INCLUDE_DIRS})
else()
init_submodule(third_party/protobuf)
set(protobuf_INSTALL OFF CACHE BOOL "Install protobuf binaries and file" FORCE)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "enable tests for proto2" FORCE)
set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "enable shared libs for proto2" FORCE)
add_subdirectory(third_party/protobuf)
include_directories(SYSTEM third_party/protobuf/src)
# Work around gcc warning in protobuf's message_lite.cc
# See https://github.com/protocolbuffers/protobuf/issues/6419
CHECK_CXX_COMPILER_FLAG("-Wno-stringop-overflow" COMPILER_SUPPORTS_WNO_STRINGOP_OVERFLOW)
CHECK_CXX_COMPILER_FLAG("-Wno-stringop-overread" COMPILER_SUPPORTS_WNO_STRINGOP_OVERREAD)
if(COMPILER_SUPPORTS_WNO_STRINGOP_OVERFLOW)
target_compile_options(libprotobuf PRIVATE -Wno-stringop-overflow)
target_compile_options(libprotobuf-lite PRIVATE -Wno-stringop-overflow)
target_compile_options(libprotoc PRIVATE -Wno-stringop-overflow)
endif()
if(COMPILER_SUPPORTS_WNO_STRINGOP_OVERREAD)
target_compile_options(libprotobuf PRIVATE -Wno-stringop-overread)
target_compile_options(libprotobuf-lite PRIVATE -Wno-stringop-overread)
target_compile_options(libprotoc PRIVATE -Wno-stringop-overread)
endif()
endif()
if(NOT ZLIB_FOUND)
init_submodule(third_party/zlib)
include_directories(SYSTEM third_party/zlib)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib)
add_subdirectory(third_party/zlib)
endif()
if(ZSTD_FOUND)
include_directories(${ZSTD_INCLUDE_DIRS})
else()
init_submodule(third_party/zstd)
set(ZSTD_BUILD_PROGRAMS OFF CACHE BOOL "build zstd programs" FORCE)
set(ZSTD_BUILD_SHARED OFF CACHE BOOL "build zstd shared lib" FORCE)
set(ZSTD_BUILD_STATIC ON CACHE BOOL "build zstd static lib" FORCE)
set(ZSTD_BUILD_CONTRIB OFF CACHE BOOL "build zstd contrib programs" FORCE)
set(ZSTD_BUILD_TESTS OFF CACHE BOOL "build zstd tests" FORCE)
include_directories(SYSTEM third_party/zstd/lib)
add_subdirectory(third_party/zstd/build/cmake)
endif()
else()
if(BLOATY_ENABLE_RE2)
init_submodule(third_party/re2)
set(RE2_BUILD_TESTING OFF CACHE BOOL "enable testing for RE2" FORCE)
add_subdirectory(third_party/re2)
include_directories(third_party/re2)
set_property(TARGET re2 PROPERTY FOLDER "third_party")
endif()
set(BUILD_STATIC_LIBS ON CACHE BOOL "Build static library" FORCE)
set(CAPSTONE_BUILD_SHARED OFF CACHE BOOL "Build shared library" FORCE)
set(CAPSTONE_BUILD_TESTS OFF CACHE BOOL "Build tests" FORCE)
init_submodule(third_party/capstone)
add_subdirectory(third_party/capstone)
include_directories(third_party/capstone/include)
set_property(TARGET capstone PROPERTY FOLDER "third_party")
set(protobuf_INSTALL OFF CACHE BOOL "Install protobuf binaries and file" FORCE)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "enable tests for proto2" FORCE)
set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "enable shared libs for proto2" FORCE)
init_submodule(third_party/protobuf)
add_subdirectory(third_party/protobuf)
include_directories(SYSTEM third_party/protobuf/src)
# Work around MSVC internal compiler error with C++17 in protobuf's descriptor_visitor.h
# Set C++20 for protobuf targets only
if(MSVC)
set_property(TARGET libprotobuf PROPERTY CXX_STANDARD 20)
set_property(TARGET libprotobuf-lite PROPERTY CXX_STANDARD 20)
set_property(TARGET libprotoc PROPERTY CXX_STANDARD 20)
set_property(TARGET protoc PROPERTY CXX_STANDARD 20)
endif()
# Work around gcc warning in protobuf's message_lite.cc
# See https://github.com/protocolbuffers/protobuf/issues/6419
CHECK_CXX_COMPILER_FLAG("-Wno-stringop-overflow" COMPILER_SUPPORTS_WNO_STRINGOP_OVERFLOW)
CHECK_CXX_COMPILER_FLAG("-Wno-stringop-overread" COMPILER_SUPPORTS_WNO_STRINGOP_OVERREAD)
if(COMPILER_SUPPORTS_WNO_STRINGOP_OVERFLOW)
target_compile_options(libprotobuf PRIVATE -Wno-stringop-overflow)
target_compile_options(libprotobuf-lite PRIVATE -Wno-stringop-overflow)
target_compile_options(libprotoc PRIVATE -Wno-stringop-overflow)
endif()
if(COMPILER_SUPPORTS_WNO_STRINGOP_OVERREAD)
target_compile_options(libprotobuf PRIVATE -Wno-stringop-overread)
target_compile_options(libprotobuf-lite PRIVATE -Wno-stringop-overread)
target_compile_options(libprotoc PRIVATE -Wno-stringop-overread)
endif()
init_submodule(third_party/zlib)
include_directories(third_party/zlib)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib)
add_subdirectory(third_party/zlib)
set_property(TARGET example PROPERTY FOLDER "third_party")
set_property(TARGET minigzip PROPERTY FOLDER "third_party")
set_property(TARGET zlib PROPERTY FOLDER "third_party")
set_property(TARGET zlibstatic PROPERTY FOLDER "third_party")
init_submodule(third_party/zstd)
set(ZSTD_BUILD_PROGRAMS OFF CACHE BOOL "build zstd programs" FORCE)
set(ZSTD_BUILD_SHARED OFF CACHE BOOL "build zstd shared lib" FORCE)
set(ZSTD_BUILD_STATIC ON CACHE BOOL "build zstd static lib" FORCE)
set(ZSTD_BUILD_CONTRIB OFF CACHE BOOL "build zstd contrib programs" FORCE)
set(ZSTD_BUILD_TESTS OFF CACHE BOOL "build zstd tests" FORCE)
include_directories(third_party/zstd/lib)
add_subdirectory(third_party/zstd/build/cmake)
set_property(TARGET libzstd_static PROPERTY FOLDER "third_party")
set_property(TARGET libprotobuf PROPERTY FOLDER "third_party")
set_property(TARGET libprotobuf-lite PROPERTY FOLDER "third_party")
set_property(TARGET libprotoc PROPERTY FOLDER "third_party")
set_property(TARGET protoc PROPERTY FOLDER "third_party")
endif()
include_directories(.)
include_directories(src)
if(NOT absl_FOUND)
init_submodule(third_party/abseil-cpp)
include_directories(third_party/abseil-cpp)
endif()
include_directories("${CMAKE_CURRENT_BINARY_DIR}/src")
include_directories(third_party/demumble/third_party/llvm/include)
include_directories(third_party/demumble/third_party/swift/include)
# Demumble has an open issue build as a library.
# See https://github.com/nico/demumble/issues/39
set(DEMUMBLE_SOURCES
third_party/demumble/third_party/llvm/lib/Demangle/Demangle.cpp
third_party/demumble/third_party/llvm/lib/Demangle/DLangDemangle.cpp
third_party/demumble/third_party/llvm/lib/Demangle/ItaniumDemangle.cpp
third_party/demumble/third_party/llvm/lib/Demangle/MicrosoftDemangle.cpp
third_party/demumble/third_party/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
third_party/demumble/third_party/llvm/lib/Demangle/RustDemangle.cpp
third_party/demumble/third_party/swift/lib/Demangling/Context.cpp
third_party/demumble/third_party/swift/lib/Demangling/CrashReporter.cpp
third_party/demumble/third_party/swift/lib/Demangling/Demangler.cpp
third_party/demumble/third_party/swift/lib/Demangling/Errors.cpp
third_party/demumble/third_party/swift/lib/Demangling/ManglingUtils.cpp
third_party/demumble/third_party/swift/lib/Demangling/NodeDumper.cpp
third_party/demumble/third_party/swift/lib/Demangling/NodePrinter.cpp
third_party/demumble/third_party/swift/lib/Demangling/OldDemangler.cpp
third_party/demumble/third_party/swift/lib/Demangling/OldRemangler.cpp
third_party/demumble/third_party/swift/lib/Demangling/Punycode.cpp
third_party/demumble/third_party/swift/lib/Demangling/Remangler.cpp
)
set_source_files_properties(
${DEMUMBLE_SOURCES}
PROPERTIES COMPILE_DEFINITIONS NDEBUG)
# Baseline build flags.
if(MSVC)
set(CMAKE_CXX_FLAGS "/EHsc /wd4018 /D_CRT_SECURE_NO_WARNINGS /DNOMINMAX")
else()
set(CMAKE_CXX_FLAGS "-W -Wall -Wno-sign-compare")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g1")
set_source_files_properties(third_party/demumble/third_party/llvm/lib/Demangle/MicrosoftDemangle.cpp
third_party/demumble/third_party/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
third_party/demumble/third_party/swift/lib/Demangling/Demangler.cpp
third_party/demumble/third_party/swift/lib/Demangling/Errors.cpp
third_party/demumble/third_party/swift/lib/Demangling/NodePrinter.cpp
third_party/demumble/third_party/swift/lib/Demangling/OldDemangler.cpp
third_party/demumble/third_party/swift/lib/Demangling/OldRemangler.cpp
third_party/demumble/third_party/swift/lib/Demangling/Remangler.cpp
PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
endif()
add_definitions(
-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1
-DSWIFT_STDLIB_HAS_TYPE_PRINTING=1
-DSWIFT_SUPPORT_OLD_MANGLING=1
)
if(APPLE)
elseif(UNIX)
if(BLOATY_ENABLE_BUILDID)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--build-id")
endif()
endif()
# When using Ninja, compiler output won't be colorized without this.
CHECK_CXX_COMPILER_FLAG(-fdiagnostics-color=always SUPPORTS_COLOR_ALWAYS)
if(SUPPORTS_COLOR_ALWAYS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
endif()
# Implement ASAN/UBSAN options
if(BLOATY_ENABLE_ASAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=address")
endif()
if(BLOATY_ENABLE_UBSAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=undefined")
endif()
if(DEFINED ENV{CXXFLAGS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{CXXFLAGS}")
endif()
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src)
if(PROTOC_FOUND)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/src/bloaty.pb.cc
${CMAKE_CURRENT_BINARY_DIR}/src/bloaty.pb.h
DEPENDS protoc ${CMAKE_CURRENT_SOURCE_DIR}/src/bloaty.proto
COMMAND protoc ${CMAKE_CURRENT_SOURCE_DIR}/src/bloaty.proto
--cpp_out=${CMAKE_CURRENT_BINARY_DIR}/src
-I${CMAKE_CURRENT_SOURCE_DIR}/src
)
else()
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/src/bloaty.pb.cc
${CMAKE_CURRENT_BINARY_DIR}/src/bloaty.pb.h
COMMAND protoc ${CMAKE_CURRENT_SOURCE_DIR}/src/bloaty.proto
--cpp_out=${CMAKE_CURRENT_BINARY_DIR}/src
-I${CMAKE_CURRENT_SOURCE_DIR}/src
)
endif()
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/bloaty_package.bloaty
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_library(libbloaty STATIC
src/bloaty.cc
src/bloaty.h
src/disassemble.cc
${CMAKE_CURRENT_BINARY_DIR}/src/bloaty.pb.cc
${CMAKE_CURRENT_BINARY_DIR}/src/bloaty.pb.h
src/dwarf/attr.h
src/dwarf/attr.cc
src/dwarf/dwarf_util.cc
src/dwarf/debug_info.cc
src/dwarf/line_info.cc
src/dwarf.cc
src/dwarf_constants.h
src/eh_frame.cc
src/elf.cc
src/macho.cc
src/pe.cc
third_party/lief_pe/pe_structures.h
src/range_map.cc
src/range_map.h
src/re.h
src/source_map.cc
src/source_map.h
src/util.cc
src/util.h
src/webassembly.cc
${DEMUMBLE_SOURCES}
)
set_property(TARGET libbloaty PROPERTY FOLDER "bloaty")
set(LIBBLOATY_LIBS libbloaty)
set(LIBBLOATY_DEPS "")
if(UNIX OR MINGW)
if(PROTOBUF_FOUND)
list(APPEND LIBBLOATY_DEPS ${PROTOBUF_LIBRARIES})
else()
list(APPEND LIBBLOATY_DEPS libprotoc)
endif()
if(BLOATY_ENABLE_RE2)
if(RE2_FOUND)
list(APPEND LIBBLOATY_DEPS ${RE2_LIBRARIES})
else()
list(APPEND LIBBLOATY_DEPS re2)
endif()
endif()
if(CAPSTONE_FOUND)
list(APPEND LIBBLOATY_DEPS ${CAPSTONE_LIBRARIES})
else()
list(APPEND LIBBLOATY_DEPS capstone)
endif()
if(ZLIB_FOUND)
list(APPEND LIBBLOATY_DEPS ZLIB::ZLIB)
else()
list(APPEND LIBBLOATY_DEPS zlibstatic)
endif()
if(ZSTD_FOUND)
list(APPEND LIBBLOATY_LIBS ${ZSTD_LIBRARIES})
else()
list(APPEND LIBBLOATY_LIBS libzstd_static)
endif()
else()
set(LIBBLOATY_DEPS libprotoc capstone)
if(BLOATY_ENABLE_RE2)
list(APPEND LIBBLOATY_DEPS re2)
endif()
list(APPEND LIBBLOATY_DEPS zlibstatic)
list(APPEND LIBBLOATY_DEPS libzstd_static)
endif()
if(UNIX OR MINGW)
if(BLOATY_ENABLE_RE2)
if(RE2_FOUND)
link_directories(${RE2_LIBRARY_DIRS})
endif()
endif()
if(CAPSTONE_FOUND)
link_directories(${CAPSTONE_LIBRARY_DIRS})
endif()
if(PROTOBUF_FOUND)
link_directories(${PROTOBUF_LIBRARY_DIRS})
endif()
if(ZSTD_FOUND)
link_directories(${ZSTD_LIBRARY_DIRS})
endif()
endif()
list(APPEND LIBBLOATY_DEPS absl::strings)
list(APPEND LIBBLOATY_DEPS absl::optional)
list(APPEND LIBBLOATY_DEPS absl::demangle_internal)
list(APPEND LIBBLOATY_DEPS absl::log_internal_message)
list(APPEND LIBBLOATY_DEPS absl::log_internal_check_op)
list(APPEND LIBBLOATY_DEPS Threads::Threads)
target_link_libraries(libbloaty ${LIBBLOATY_DEPS})
if(DEFINED ENV{LIB_FUZZING_ENGINE})
message("LIB_FUZZING_ENGINE set, building fuzz_target instead of Bloaty")
add_executable(fuzz_target tests/fuzz_target.cc)
target_link_libraries(fuzz_target ${LIBBLOATY_LIBS} $ENV{LIB_FUZZING_ENGINE})
else()
add_executable(bloaty src/main.cc)
target_link_libraries(bloaty ${LIBBLOATY_LIBS})
set_property(TARGET bloaty PROPERTY FOLDER "bloaty")
if(BLOATY_ENABLE_CMAKETARGETS)
install(
TARGETS bloaty
EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION bin
)
else()
install(
TARGETS bloaty
RUNTIME DESTINATION bin
)
endif()
if (IS_DIRECTORY "${PROJECT_SOURCE_DIR}/tests")
enable_testing()
find_package(Python COMPONENTS Interpreter)
find_program(LIT_EXECUTABLE NAMES lit-script.py lit.py lit)
find_program(FILECHECK_EXECUTABLE FileCheck)
find_program(YAML2OBJ_EXECUTABLE yaml2obj)
if(Python_FOUND AND LIT_EXECUTABLE AND FILECHECK_EXECUTABLE AND YAML2OBJ_EXECUTABLE)
set(BLOATY_SRC_DIR ${PROJECT_SOURCE_DIR})
set(BLOATY_OBJ_DIR ${PROJECT_BINARY_DIR})
configure_file(tests/lit.site.cfg.in tests/lit.site.cfg @ONLY)
add_custom_target(check-bloaty
COMMAND ${Python_EXECUTABLE} ${LIT_EXECUTABLE} -sv ${PROJECT_BINARY_DIR}/tests --param bloaty=$<TARGET_FILE:bloaty>
DEPENDS
bloaty
${CMAKE_CURRENT_SOURCE_DIR}/tests/lit.cfg
${CMAKE_CURRENT_BINARY_DIR}/tests/lit.site.cfg
COMMENT "Running bloaty tests..."
USES_TERMINAL)
set_property(TARGET check-bloaty PROPERTY FOLDER "tests")
endif()
if(BUILD_TESTING)
option(INSTALL_GTEST "" OFF)
init_submodule(third_party/googletest)
add_subdirectory(third_party/googletest)
include_directories(third_party/googletest/googletest/include)
include_directories(third_party/googletest/googlemock/include)
set(TEST_TARGETS
bloaty_test
bloaty_test_pe
bloaty_misc_test
range_map_test
)
foreach(target ${TEST_TARGETS})
add_executable(${target} tests/${target}.cc)
target_link_libraries(${target} ${LIBBLOATY_LIBS} gtest_main gmock)
set_property(TARGET ${target} PROPERTY FOLDER "tests")
endforeach(target)
add_executable(fuzz_test tests/fuzz_target.cc tests/fuzz_driver.cc)
target_link_libraries(fuzz_test ${LIBBLOATY_LIBS})
set_property(TARGET fuzz_test PROPERTY FOLDER "tests")
foreach(testlib gmock gmock_main gtest gtest_main)
set_property(TARGET ${testlib} PROPERTY FOLDER "tests/libs")
endforeach(testlib)
file(GLOB fuzz_corpus tests/testdata/fuzz_corpus/*)
add_test(NAME range_map_test COMMAND range_map_test)
add_test(NAME bloaty_test_x86-64 COMMAND bloaty_test WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests/testdata/linux-x86_64)
add_test(NAME bloaty_test_x86 COMMAND bloaty_test WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests/testdata/linux-x86)
add_test(NAME bloaty_test_pe_x64 COMMAND bloaty_test_pe WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests/testdata/PE/x64)
add_test(NAME bloaty_test_pe_x86 COMMAND bloaty_test_pe WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests/testdata/PE/x86)
add_test(NAME bloaty_misc_test COMMAND bloaty_misc_test WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests/testdata/misc)
add_test(NAME fuzz_test COMMAND fuzz_test ${fuzz_corpus} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests/testdata/fuzz_corpus)
endif()
endif()
if(BLOATY_ENABLE_CMAKETARGETS)
install(EXPORT ${PROJECT_NAME}Targets NAMESPACE ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME})
endif()
endif()