forked from Ghost047/clang-chimera
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
166 lines (146 loc) · 6.36 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
cmake_minimum_required(VERSION 3.3)
project("Clang-Chimera" VERSION 0.1 LANGUAGES C CXX)
# Requirements
## Require Include-What-You-Use
set(IWYU OFF CACHE BOOL "If enable the include-what-you-use program")
if (IWYU)
set(IWYU_PATH CACHE FILEPATH "Path to include-what-you-use program")
message(STATUS "Searching for IWYU ... ")
find_program(iwyu_path NAMES include-what-you-use iwyu)
if(NOT iwyu_path)
message(FATAL_ERROR "Could not find the program include-what-you-use."
"Either disable this requirement with -DIWYU:BOOL=OFF"
"or specify the program path with -DIWYU_PATH:FILEPATH=/path/to/iwyu"
)
endif(NOT iwyu_path)
message(STATUS "Searching for IWYU ... FOUND: ${iwyu_path}")
# Use IWYU
set(CMAKE_C_INCLUDE_WHAT_YOU_USE ${iwyu_path})
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
endif(IWYU)
# Require C++11 features
set(CMAKE_CXX_STANDARD 11)
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE Debug)
#SET(GCC_COVERAGE_COMPILE_FLAGS "-Wfatal-errors")
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}" )
# Required packages
## Require LLVM and Clang
#find_package(LLVM 3.7.0 REQUIRED CONFIG)
find_package(LLVM 3.9.1 REQUIRED CONFIG)
## Require Pthreads
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
## Require ZLIB
find_package(ZLIB REQUIRED)
message(STATUS "Found ZLIB ${ZLIB_VERSION_STRING}")
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message(STATUS "Added LLVM include directories: ${LLVM_INCLUDE_DIRS}")
message(STATUS "Added LLVM definitions: ${LLVM_DEFINITIONS}")
# Add includes and definitions of LLVM
include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
execute_process(COMMAND "/usr/bin/llvm-config --components" RESULT_VARIABLE llvm-comp)
message(STATUS "llvm_components: ${llvm-comp}")
# Find the libraries that correspond to the LLVM/Clang components
## Mapping components to libraries names
llvm_map_components_to_libnames(llvm_libs all analysis asmparser asmprinter bitreader bitwriter bpf bpfasmprinter bpfcodegen bpfdesc bpfinfo codegen core coverage debuginfocodeview debuginfodwarf debuginfopdb engine executionengine globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interpreter ipo irreader libdriver lineeditor linker lto mc mcdisassembler mcjit mcparser mirparser native nativecodegen objcarcopts object objectyaml option orcjit passes profiledata runtimedyld scalaropts selectiondag support symbolize systemz systemzasmparser systemzasmprinter systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target transformutils vectorize x86 x86asmparser x86asmprinter x86codegen x86desc x86disassembler x86info x86utils xcore xcoreasmprinter xcorecodegen xcoredesc xcoredisassembler xcoreinfo)
## Clang libraries
list(APPEND clang_libs
clangTooling
clangToolingCore
clangFormat
clangAST
clangAnalysis
clangBasic
clangDriver
clangEdit
clangFrontend
clangFrontendTool
clangLex
clangParse
clangSema
clangEdit
clangASTMatchers
clangRewrite
clangRewriteFrontend
clangStaticAnalyzerFrontend
clangStaticAnalyzerCheckers
clangStaticAnalyzerCore
clangSerialization
)
# Put all toghether the required libraries
list(APPEND required_libs ${clang_libs} ${llvm_libs})
# Check on required libraries
# - LLVM/Clang Static Libraries
message(STATUS "Checking LLVM/Clang Static libraries: ${required_libs}")
set(LLVM_LIBRARY_DIR "/usr/lib/" CACHE PATH "Library search path for LLVM/Clang")
message(STATUS "Search path: LLVM_LIBRARY_DIR = ${LLVM_LIBRARY_DIR}")
set(required_libs_paths)
foreach (lib ${required_libs})
find_library(required_lib_path ${lib} ${LLVM_LIBRARY_DIR})
if (${required_lib_path} STREQUAL required_lib_path-NOTFOUND)
message(FATAL_ERROR "The library ${lib} was not found. Provide a LLVM_LIBRARY_DIR: -DLLVM_LIBRARY_DIR:PATH=<library_path>.")
endif()
message(STATUS "Found library: ${required_lib_path}")
list(APPEND required_libs_paths ${required_lib_path})
unset(required_lib_path CACHE)
endforeach()
# - Others libraries
list(APPEND other_libs ffi edit ncurses dl m)
message(STATUS "Checking additional libraries: ${other_libs}")
foreach (lib ${other_libs})
find_library(required_lib_path ${lib})
if (${required_lib_path} STREQUAL required_lib_path-NOTFOUND)
message(FATAL_ERROR "The library ${lib} was not found.")
endif()
message(STATUS "Found library: ${required_lib_path}")
unset(required_lib_path CACHE)
endforeach()
###############################################################################
# Doxyen Support
## Search for Doxygen Package
find_package(Doxygen)
## In case has been found
if(DOXYGEN_FOUND)
message(STATUS "Found Doxygen. It is available 'make doc' to generate the documentation")
configure_file(${CMAKE_SOURCE_DIR}/src/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/doc/doxygen
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif(DOXYGEN_FOUND)
###############################################################################
# Checks completed. Add sources/libraries/executables
# Add sources subdirectory
add_subdirectory(${CMAKE_SOURCE_DIR}/src)
# Target: clang-chimera
add_executable(clang-chimera src/main.cpp)
# Includes
target_include_directories(clang-chimera
PRIVATE ${CMAKE_SOURCE_DIR}/include
)
# Link libraries
target_link_libraries(clang-chimera
${required_libs_paths}
operators tooling testing utils
)
# Relink to resolve circular dependencies
target_link_libraries(clang-chimera
${required_libs_paths}
Threads::Threads
z
ffi
edit
ncurses
dl
m
)
install(TARGETS clang-chimera
RUNTIME DESTINATION /usr/local/bin
LIBRARY DESTINATION /usr/local/lib
ARCHIVE DESTINATION /usr/local/lib
)