-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
174 lines (146 loc) · 5.46 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
cmake_minimum_required(VERSION 3.17)
# Temporary workaround for clang 14
# https://github.com/llvm/llvm-project/issues/53950
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows)
set(parser_languages CXX)
else()
set(parser_languages C CXX)
endif()
project(
Parser
VERSION 0.6.0
LANGUAGES ${parser_languages})
configure_file(docs/ReleaseNotes/version.in
${CMAKE_CURRENT_LIST_DIR}/docs/ReleaseNotes/version @ONLY)
include(FetchContent)
FetchContent_Declare(
cmake_modules
GIT_REPOSITORY https://github.com/Tolc-Software/cmake-modules.git
GIT_TAG main)
FetchContent_MakeAvailable(cmake_modules)
# Basis of all shared CMake modules
set(modules ${cmake_modules_SOURCE_DIR}/cmake)
include(${modules}/Doxygen.cmake)
enable_doxygen()
# Set ccache, ipo, etc.
include(${modules}/ProjectSettings.cmake)
# Define add_{warnings,options}
include(${modules}/WarningsAndOptions.cmake)
# allow for static analysis options
include(${modules}/StaticAnalyzers.cmake)
# Define enable_sanitizers
include(${modules}/Sanitizers.cmake)
FetchContent_Declare(
IRSpecification
GIT_REPOSITORY https://github.com/Tolc-Software/IntermediateRepresentation.git
GIT_TAG v0.15.1)
FetchContent_MakeAvailable(IRSpecification)
FetchContent_Declare(
ctre_content
GIT_REPOSITORY https://github.com/hanickadot/compile-time-regular-expressions.git
GIT_TAG v3.4.1)
FetchContent_Populate(ctre_content)
# Define run_conan
include(${modules}/ConanHelpers.cmake)
# Create the profile from variables known during configure
setup_conan_profile(VARIABLE parser_conan_profile)
# This helps with packaging
set(CONAN_REQUIRES_PACKAGES spdlog/1.9.2 fmt/8.1.1)
find_conan_packages(
REQUIRES ${CONAN_REQUIRES_PACKAGES} PROFILE
${parser_conan_profile})
include(${modules}/LLVMUtilities.cmake)
# Download if necessary and get the clang libs Defines
# llvm_entry_{SOURCE_DIR,INCLUDE_DIR} variables
set(llvm_entry_version 14.0.0)
setup_llvm(NAME "LLVM_ENTRY" VERSION ${llvm_entry_version})
# Macro to get downloaded Clang and llvm packages
get_clang_and_llvm(PATH ${llvm_entry_SOURCE_DIR})
# From the LLVM cmake module. Defines add_llvm_{executable,library}
include(AddLLVM)
# Defines get_system_include and format_includes
include(${modules}/IncludePathHelpers.cmake)
# Set the include path for the system library in the variable
# We are using the standard library shipped
# with the downloaded llvm for include paths in the parsing
get_system_include(VARIABLE platform_include LLVM_DIRECTORY
${llvm_entry_SOURCE_DIR} LLVM_VERSION ${llvm_entry_version})
format_includes(VARIABLE INCLUDE_PATH INCLUDES ${platform_include} SYSTEM)
configure_file(src/Helpers/commandLineArgs.cpp.in
${CMAKE_CURRENT_LIST_DIR}/src/Helpers/commandLineArgs.cpp @ONLY)
add_llvm_library(
Parser
src/Builders/commonBuilder.cpp
src/Builders/enumBuilder.cpp
src/Builders/fieldBuilder.cpp
src/Builders/functionBuilder.cpp
src/Builders/namespaceBuilder.cpp
src/Builders/structBuilder.cpp
src/Builders/typeBuilder.cpp
src/Consumer/ParserConsumer.cpp
src/Factory/ParserFrontendActionFactory.cpp
src/Frontend/ParserFrontendAction.cpp
src/Helpers/Type/Matchers/base.cpp
src/Helpers/Type/Matchers/container.cpp
src/Helpers/Type/Matchers/function.cpp
src/Helpers/Type/matchers.cpp
src/Helpers/Type/utilities.cpp
src/Helpers/Utils/combine.cpp
src/Helpers/Utils/split.cpp
src/Helpers/Utils/string.cpp
src/Helpers/commandLineArgs.cpp
src/Helpers/getStructData.cpp
src/Helpers/walkIRStructure.cpp
src/Parser/Parse.cpp
src/Parser/Windows/systemIncludeHelper.cpp
src/Template/cache.cpp
src/Visitor/Helpers/addId.cpp
src/Visitor/Helpers/getDocumentation.cpp
src/Visitor/Helpers/parseFunction.cpp
src/Visitor/ParserVisitor.cpp
src/Visitor/VisitCXXRecordDecl.cpp
src/Visitor/VisitClassTemplateSpecializationDecl.cpp
src/Visitor/VisitEnumDecl.cpp
src/Visitor/VisitFieldDecl.cpp
src/Visitor/VisitFunctionDecl.cpp
src/Visitor/VisitFunctionTemplateDecl.cpp
src/Visitor/VisitNamespaceDecl.cpp
src/Visitor/VisitVarDecl.cpp)
target_link_libraries(
Parser
PUBLIC IR::IR
PRIVATE clangASTMatchers clangBasic clangTooling spdlog::spdlog fmt::fmt)
add_warnings(TARGET Parser)
add_options(TARGET Parser)
# Set sanitizer options on Parser if options defined
enable_sanitizers(Parser)
# Ignore warnings from {clang,ctre} as if they were system headers.
target_include_directories(Parser SYSTEM PRIVATE ${llvm_entry_INCLUDE_DIR})
target_include_directories(Parser SYSTEM PRIVATE ${ctre_content_SOURCE_DIR}/single-header)
target_include_directories(Parser PRIVATE src)
target_include_directories(
Parser PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:include>)
set_target_properties(Parser PROPERTIES CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS
OFF)
# Export the library to link against
add_library(Tolc::Parser ALIAS Parser)
# Only build tests and benchmarks if building this project directly
if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
option(ENABLE_TESTING "Build the testing tree" OFF)
if(ENABLE_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
option(ENABLE_BENCHMARKS "Build the benchmarks" OFF)
if(ENABLE_BENCHMARKS)
# TODO: Add benchmarks
endif()
option(ENABLE_PACKAGING "Enables install and packaging via CPack" OFF)
if(ENABLE_PACKAGING)
add_subdirectory(tools/packaging)
if(ENABLE_TESTING)
add_subdirectory(tests/packaging)
endif()
endif()
endif()