-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
157 lines (118 loc) · 4.15 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
cmake_minimum_required(VERSION 3.12)
project(ICA LANGUAGES C CXX)
set(ICA_VERSION 0.0.1)
set(BOOST_VERSION 1.77.0)
set(LLVM_VERSION 10.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Always export compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Project local modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Minimum compiler requirements
include(CheckCompilerSupported)
check_min_version("GNU" 7.3)
check_min_version("Clang" 6.0)
check_min_version("AppleClang" 7.0)
check_compiler_supported()
#
# Target itself and its compilation flags
#
file(GLOB_RECURSE ica_sources CONFIGURE_DEPENDS src/*.cpp)
add_library(ICAPlugin SHARED ${ica_sources})
add_library(ICA::ICAPlugin ALIAS ICAPlugin)
set_target_properties(ICAPlugin PROPERTIES OUTPUT_NAME "ica-plugin")
target_include_directories(ICAPlugin PRIVATE include)
# GCC toolchain. Can also be provided in CMAKE_CXX_FLAGS
set(GCC_TOOLCHAIN "" CACHE PATH "Ask Clang to use GCC toolchain from specified directory")
if (EXISTS ${GCC_TOOLCHAIN})
set(TOOLCHAIN_ARG "--gcc-toolchain=${GCC_TOOLCHAIN}")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(STATUS "Using GCC toolchain: ${GCC_TOOLCHAIN}")
target_compile_options(ICAPlugin PRIVATE "${TOOLCHAIN_ARG}")
target_link_options(ICAPlugin PRIVATE "${TOOLCHAIN_ARG}")
endif()
endif()
# Warnings
target_compile_options(ICAPlugin PRIVATE
-Wall
-Wold-style-cast
# $<$<CXX_COMPILER_ID:GNU>:-Wsuggest-final-types>
$<$<CXX_COMPILER_ID:GNU>:-Wsuggest-override>
$<$<CXX_COMPILER_ID:GNU>:-Wuseless-cast>
$<$<CXX_COMPILER_ID:Clang>:-Wno-unknown-warning-option>
# $<$<CXX_COMPILER_ID:Clang>:-Wno-unused-command-line-argument>
)
# Feature flags
target_compile_options(ICAPlugin PRIVATE -ftemplate-backtrace-limit=0)
# Linker flags
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_link_options(ICAPlugin PRIVATE -undefined dynamic_lookup)
endif()
# Interface
add_library(ICAChecks INTERFACE)
add_dependencies(ICAChecks ICAPlugin)
target_compile_options(ICAChecks INTERFACE
"SHELL:-Xclang -load -Xclang $<TARGET_FILE:ICA::ICAPlugin>"
"SHELL:-Xclang -add-plugin -Xclang ica-plugin"
)
function(add_ica_options)
foreach(opt IN LISTS ARGN)
add_compile_options("SHELL:-Xclang -plugin-arg-ica-plugin -Xclang ${opt}")
endforeach()
endfunction()
function(target_ica_options TARGET VISIBILITY)
foreach(opt IN LISTS ARGN)
target_compile_options(${TARGET} ${VISIBILITY} "SHELL:-Xclang -plugin-arg-ica-plugin -Xclang ${opt}")
endforeach()
endfunction()
function(add_ica_checks)
list(JOIN ARGN "," ICA_CHECKS)
link_libraries(ICAChecks)
add_ica_options("checks=${ICA_CHECKS}")
endfunction()
function(target_ica_checks TARGET VISIBILITY)
list(JOIN ARGN "," ICA_CHECKS)
target_link_libraries(${TARGET} ${VISIBILITY} ICAChecks)
target_ica_options(${TARGET} ${VISIBILITY} "checks=${ICA_CHECKS}")
endfunction()
function(ica_no_url)
add_ica_options("no-url")
endfunction()
function(target_ica_no_url TARGET VISIBILITY)
target_ica_options(${TARGET} ${VISIBILITY} "no-url")
endfunction()
#
# Third-party
#
include(BoostFromInternet)
find_package(Boost ${BOOST_VERSION} REQUIRED)
find_package(LLVMHeaders ${LLVM_VERSION} REQUIRED)
target_link_libraries(ICAPlugin PRIVATE LLVMHeaders Boost::headers)
#
# Packaging
#
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/ICAConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/ICAConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/ICA"
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/ICAConfigVersion.cmake"
VERSION "${ICA_VERSION}"
COMPATIBILITY SameMajorVersion
)
install(TARGETS ICAPlugin ICAChecks EXPORT ICATargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(EXPORT ICATargets NAMESPACE ICA:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ICA)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/ICAConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/ICAConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ICA
)
#
# Tests
#
enable_testing()
add_subdirectory(test)