forked from goldsborough/clang-expand
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
166 lines (137 loc) · 4.57 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 SETUP
###########################################################
cmake_minimum_required(VERSION 3.5)
project(clang-expand)
###########################################################
## DOCUMENTATION
###########################################################
# Add a target to generate documentation with Doxygen.
find_package(Doxygen)
if(DOXYGEN_FOUND)
# Replace all variables of the form @<var>@ inside the Doxyfile
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY
)
add_custom_target(
docs
${DOXYGEN_EXECUTABLE}
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/docs
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif()
###########################################################
## DEPENDENCIES
###########################################################
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")
set(CLANG_LIBS
clangAST
clangASTMatchers
clangAnalysis
clangBasic
clangDriver
clangEdit
clangFrontend
clangFrontendTool
clangLex
clangParse
clangSema
clangEdit
clangRewrite
clangRewriteFrontend
clangSerialization
clangTooling
clangToolingCore
)
if (NOT CMAKE_HOST_APPLE)
set(CLANG_LIBS -Wl,--start-group ${CLANG_LIBS} -Wl,--end-group)
endif()
find_package(LLVM REQUIRED)
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
include_directories(SYSTEM ${CLANG_INCLUDE_DIRS})
# Third Party
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR})
# Also contains clang libraries
link_directories(${LLVM_LIBRARY_DIRS})
set(CMAKE_EXE_LINKER_FLAGS ${LLVM_LD_FLAGS_STRING})
###########################################################
## COMPILER FLAGS
###########################################################
set(CXX_STANDARD_REQUIRED ON)
list(REMOVE_ITEM LLVM_CXX_FLAGS
${LLVM_INCLUDE_DIRS} # Already included
"-DNDEBUG"
"-std=c++11" # Want our own standard
"-std=c++1y"
"-stdlib=libc++"
"-fno-rtti-DLLVM_BUILD_GLOBAL_ISEL" # Weird bugs on Debian
"-fdata-sections-O3"
"-fdata-sections-O2")
if (NOT ${CMAKE_CXX_COMPILER} MATCHES "clang.*")
# These seem to be clang-specific
list(REMOVE_ITEM LLVM_CXX_FLAGS
"-Wcovered-switch-default"
"-Wstring-conversion")
endif()
set(EXTRA_FLAGS
-Os
-O3
-fdata-sections
-std=c++14
-fno-rtti
-DLLVM_BUILD_GLOBAL_ISEL
-DJSON_NOEXCEPTION)
set(ALL_FLAGS ${WARNINGS} ${LLVM_CXX_FLAGS} ${EXTRA_FLAGS})
add_compile_options(${ALL_FLAGS})
###########################################################
## INCLUDES
###########################################################
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
###########################################################
## SOURCES
###########################################################
add_subdirectory(source)
###########################################################
## TARGETS
###########################################################
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/bin/${CLANG_EXPAND_OS_NAME})
message(STATUS "Binaries will land in ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
add_executable(clang-expand clang-expand.cpp)
target_link_libraries(clang-expand
clang-expand-library
${CLANG_LIBS}
${LLVM_LIBS})
###########################################################
## DOCKER
###########################################################
find_program(DOCKER_COMPOSE NAMES docker-compose)
if (DOCKER_COMPOSE)
message(STATUS "Found docker-compose at ${DOCKER_COMPOSE}")
add_custom_target(
docker
COMMAND docker-compose up
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
COMMENT "Building clang-expand with docker" VERBATIM
)
message(STATUS "Enabled 'docker' target for building binaries")
endif()
###########################################################
## TOOLS <3
###########################################################
# IWYU
option(CLANG_EXPAND_IWYU OFF)
if(${CLANG_EXPAND_IWYU})
find_program(iwyu_path NAMES include-what-you-use iwyu)
if(iwyu_path)
message(STATUS "Found include-what-you-use, integrating with target")
set_property(TARGET clang-expand
PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
else()
message(WARNING "Could not find include-what-you-use, skipping")
endif()
endif()