forked from ruhrie/TraceAtlas
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
127 lines (113 loc) · 4.74 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
cmake_minimum_required(VERSION 3.13)
project(TraceAtlas VERSION 0.3.2)
SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_C_STANDARD 11)
find_package(LLVM 9 REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
llvm_map_components_to_libnames(llvm_libs support core irreader bitreader bitwriter transformutils)
#use the llvm toolchain
#we fix these ourselves since we don't support gcc anyway
#I want windows support, but passes on windows are tricky anyway so that is a secondary goal
set(CMAKE_C_COMPILER ${LLVM_INSTALL_PREFIX}/bin/clang)
set(CMAKE_CXX_COMPILER ${LLVM_INSTALL_PREFIX}/bin/clang++)
set(CMAKE_LINKER ${LLVM_INSTALL_PREFIX}/bin/ld.lld)
set(CMAKE_AR ${LLVM_INSTALL_PREFIX}/bin/llvm-ar)
set(CMAKE_ADDR2LINE ${LLVM_INSTALL_PREFIX}/bin/llvm-addr2line)
set(CMAKE_NM ${LLVM_INSTALL_PREFIX}/bin/llvm-nm)
set(CMAKE_OBJCOPY ${LLVM_INSTALL_PREFIX}/bin/llvm-objcopy)
set(CMAKE_OBJDUMP ${LLVM_INSTALL_PREFIX}/bin/llvm-objdump)
set(CMAKE_RANLIB ${LLVM_INSTALL_PREFIX}/bin/llvm-ranlib)
set(CMAKE_READELF ${LLVM_INSTALL_PREFIX}/bin/llvm-readelf)
set(CMAKE_STRIP ${LLVM_INSTALL_PREFIX}/bin/llvm-strip)
#other dependencies, provided by vcpkg but you can get them elsewhere as long as you have a cmake file
find_package(ZLIB REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED) #nlohmann_json
find_package(spdlog CONFIG REQUIRED) #spdlog
find_package(indicators CONFIG REQUIRED) #indicators
#clang-tidy options
option(ENABLE_LINTER "Run linter" OFF)
if(${ENABLE_LINTER})
find_program(TIDY NAMES clang-tidy-9 clang-tidy)
if(${TIDY} STREQUAL "TIDY-NOTFOUND")
message(FATAL_ERROR "clang-tidy not found! Necessary for linting!")
else()
message(STATUS "Found clang-tidy in ${TIDY}")
endif()
set(CMAKE_CXX_CLANG_TIDY
${TIDY};
--warnings-as-errors=*;
--checks=readability-*,-readability-magic-numbers,performance-*,portability-*,modernize-*,-modernize-use-trailing-return-type;
)
set(CMAKE_C_CLANG_TIDY
${TIDY};
--warnings-as-errors=*;
--checks=readability-*,-readability-magic-numbers,performance-*,portability-*,-clang-analyzer-security.insecureAPI.*;
)
add_compile_options(-Werror)
endif()
if(WIN32)
add_compile_definitions(_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS)
endif()
add_subdirectory("AtlasUtil")
add_subdirectory("cartographer")
add_subdirectory("TraceInfrastructure")
add_subdirectory("tik")
add_subdirectory("deat")
add_subdirectory("Utilities")
#repsonsible for injecting the tracer. Fairly fragile so be careful
function(InjectTracer tar)
target_compile_options(${tar} PRIVATE "-flto")
set_target_properties(${tar} PROPERTIES LINK_FLAGS "-fuse-ld=lld -Wl,--plugin-opt=emit-llvm")
add_custom_command(OUTPUT opt.bc
COMMAND ${LLVM_INSTALL_PREFIX}/bin/opt -load $<TARGET_FILE:AtlasPasses> -EncodedTrace $<TARGET_FILE:${tar}> -o opt.bc
DEPENDS $<TARGET_FILE:${tar}>
)
set_source_files_properties(
opt.bc
PROPERTIES
EXTERNAL_OBJECT true
GENERATED true
)
add_executable(${tar}-trace opt.bc)
set_target_properties(${tar}-trace PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(${tar}-trace PRIVATE AtlasBackend)
endfunction()
#our unit tests
option(ENABLE_TESTING "Build tests" ON)
option(ENABLE_TESTING_LONG "Build tests long" OFF)
if(${ENABLE_TESTING})
enable_testing()
add_subdirectory(Tests)
endif()
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(DoxygenLayout.xml ${CMAKE_CURRENT_BINARY_DIR}/DoxygenLayout.xml @ONLY)
configure_file(Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
endif(DOXYGEN_FOUND)
#stollen from https://github.com/ttroy50/cmake-examples/blob/master/04-static-analysis/clang-format/cmake/modules/clang-format.cmake
#used to run clang-format on the entire source tree
find_program(FORMAT NAMES clang-format-9 clang-format)
if(${FORMAT} STREQUAL "FORMAT-NOTFOUND")
message(WARNING "clang-format not found. Disabling formatting target")
else()
message(STATUS "Found clang-format in ${FORMAT}")
set(CLANG_FORMAT_EXCLUDE_PATTERNS "build" "vcpkg")
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h *.c)
foreach (SOURCE_FILE ${ALL_SOURCE_FILES})
foreach (EXCLUDE_PATTERN ${CLANG_FORMAT_EXCLUDE_PATTERNS})
string(FIND ${SOURCE_FILE} ${EXCLUDE_PATTERN} PROJECT_TRDPARTY_DIR_FOUND)
if (NOT ${PROJECT_TRDPARTY_DIR_FOUND} EQUAL -1)
list(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE})
endif ()
endforeach()
endforeach ()
add_custom_target(
format
COMMAND ${FORMAT}
-style=file
-i
${ALL_SOURCE_FILES}
)
endif()