-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
238 lines (187 loc) · 5.95 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
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
# Copyright 2021-present, Trail of Bits, Inc. All rights reserved.
cmake_minimum_required(VERSION 3.22)
# Fix behavior of CMAKE_CXX_STANDARD when targeting macOS.
if (POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif ()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
project(
gap
LANGUAGES C CXX
VERSION 0.0.0
DESCRIPTION "A utility library to bridge llvm and mlir gaps"
HOMEPAGE_URL "https://github.com/lifting-bits/gap"
)
# Globally set the required C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
include(GNUInstallDirs)
# check if gap is being used directly or via add_subdirectory,
# but allow overriding
if(NOT DEFINED GAP_MASTER_PROJECT)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(GAP_MASTER_PROJECT ON)
else()
set(GAP_MASTER_PROJECT OFF)
endif()
endif()
include(project_settings)
include(utils)
# adds header paths of library to list named var
function(add_headers lib var)
set(headers ${${var}})
foreach (header ${ARGN})
set(headers ${headers} ${CMAKE_CURRENT_SOURCE_DIR}/include/gap/${lib}/${header})
endforeach()
set(${var} ${headers} PARENT_SCOPE)
endfunction()
# adds source paths of library to list named var
function(add_sources lib var)
set(sources ${${var}})
foreach (source ${ARGN})
set(sources ${sources} ${CMAKE_CURRENT_SOURCE_DIR}/src/${source})
endforeach()
set(${var} ${sources} PARENT_SCOPE)
endfunction()
#
# CCACHE
#
find_program(CCACHE_PROGRAM ccache)
if (CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif ()
#
# GAP build settings
#
add_library(gap-settings INTERFACE)
add_library(gap::gap-settings ALIAS gap-settings)
option(GAP_ENABLE_WARNINGS "Enable extended warnings" ON)
if(GAP_ENABLE_WARNINGS)
include(compiler_warnings)
set_project_warnings(gap-settings)
endif()
target_include_directories(gap-settings
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
# sanitizer options if supported by compiler
include(sanitizers)
enable_sanitizers(gap-settings)
# allow for static analysis options
include(static_analyzers)
option(GAP_ENABLE_COROUTINES "Enable coroutines" ON)
if (${GAP_ENABLE_COROUTINES})
find_package(Coroutines COMPONENTS Experimental Final REQUIRED)
target_compile_definitions(gap-settings INTERFACE GAP_ENABLE_COROUTINES)
target_link_libraries(gap-settings INTERFACE std::coroutines)
endif()
#
# Core GAP libraries
#
add_subdirectory(core)
add_subdirectory(coro)
add_subdirectory(graph)
option(GAP_ENABLE_SARIF "Enable SARIF support"
$<IN_LIST:sarif,VCPKG_MANIFEST_FEATURES>
)
if (${GAP_ENABLE_SARIF})
add_subdirectory(sarif)
endif()
option(GAP_ENABLE_MLIR "Enable MLIR support" OFF)
if (${GAP_ENABLE_MLIR})
find_package(LLVM REQUIRED CONFIG)
find_package(MLIR REQUIRED CONFIG)
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
include(AddMLIR)
add_subdirectory(mlir)
endif()
set(GAP_HEADERS
${GAP_CORE_HEADERS}
${GAP_CORO_HEADERS}
)
add_library(gap INTERFACE)
add_library(gap::gap ALIAS gap)
target_link_libraries(gap
INTERFACE
gap-core
gap-coro
gap-settings
)
set_target_properties(gap PROPERTIES PUBLIC_HEADER "${GAP_HEADERS}")
#
# testing support
#
option(GAP_ENABLE_TESTING "Enable GAP Test Builds" ON)
if (GAP_ENABLE_TESTING)
include(CTest)
enable_testing()
add_subdirectory(test)
endif ()
#
# instalation support
#
option(GAP_INSTALL "Generate the install target." ${GAP_MASTER_PROJECT})
set_property(
TARGET gap PROPERTY POSITION_INDEPENDENT_CODE ON
)
set_target_properties(${PROJECT_NAME}
PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}
)
if (GAP_INSTALL)
set(GAP_CMAKE_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} CACHE PATH "Path where CMake utilities will be installed")
set(GAP_INSTALL_TARGETS gap gap-core gap-coro gap-settings)
set(GAP_EXPORT_NAME gapTargets)
install_gap_target(gap core)
install_gap_target(gap-core core)
install_gap_target(gap-settings core)
install_gap_target(gap-coro coro)
install_gap_target(gap-graph graph)
if (${GAP_ENABLE_SARIF})
install_gap_target(gap-sarif sarif)
endif()
if (${GAP_ENABLE_MLIR})
install_gap_target(gap-mlir mlir)
endif()
#
# packaging support
#
set(CPACK_PACKAGE_VENDOR "Trail of Bits")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"A utility library to bridge llvm and mlir gaps."
)
set(CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${CMAKE_PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${CMAKE_PROJECT_VERSION_PATCH})
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
include(CPack)
set(GAP_CONFIG_NAME "${PROJECT_NAME}Config")
set(GAP_PACKAGE_CONFIG_FILE "${GAP_CONFIG_NAME}.cmake")
set(GAP_PACKAGE_CONFIG_VERSION_FILE "${GAP_CONFIG_NAME}Version.cmake")
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/${GAP_CONFIG_NAME}.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${GAP_PACKAGE_CONFIG_FILE}"
INSTALL_DESTINATION ${GAP_CMAKE_INSTALL_DIR}
)
write_basic_package_version_file(
${GAP_PACKAGE_CONFIG_VERSION_FILE}
VERSION ${PACKAGE_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindCoroutines.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${GAP_PACKAGE_CONFIG_FILE}"
"${CMAKE_CURRENT_BINARY_DIR}/${GAP_PACKAGE_CONFIG_VERSION_FILE}"
DESTINATION ${GAP_CMAKE_INSTALL_DIR}
)
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/compiler_warnings.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/sanitizers.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/static_analyzers.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/project_settings.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/prevent_in_source_builds.cmake"
DESTINATION ${GAP_CMAKE_INSTALL_DIR}
)
endif()