-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
175 lines (143 loc) · 4.85 KB
/
Copy pathCMakeLists.txt
File metadata and controls
175 lines (143 loc) · 4.85 KB
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
cmake_minimum_required(VERSION 3.20)
project(slang-autos
VERSION 0.1.0
DESCRIPTION "SystemVerilog AUTO macro expander built on slang"
LANGUAGES CXX
)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Export compile commands for IDE support
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Options
option(SLANG_AUTOS_BUILD_TESTS "Build tests" ON)
option(SLANG_AUTOS_BUILD_LSP "Build LSP server" ON)
option(SLANG_AUTOS_USE_SYSTEM_SLANG "Use system-installed slang instead of submodule" OFF)
# ============================================================================
# Dependencies
# ============================================================================
# slang - SystemVerilog compiler
if(SLANG_AUTOS_USE_SYSTEM_SLANG)
find_package(slang REQUIRED)
else()
# Use slang as a submodule
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/external/slang/CMakeLists.txt")
message(FATAL_ERROR
"slang submodule not found. Please run:\n"
" git submodule update --init --recursive\n"
"Or set SLANG_AUTOS_USE_SYSTEM_SLANG=ON to use system-installed slang."
)
endif()
# Configure slang build options
set(SLANG_INCLUDE_TESTS OFF CACHE BOOL "" FORCE)
set(SLANG_INCLUDE_TOOLS OFF CACHE BOOL "" FORCE)
set(SLANG_INCLUDE_INSTALL OFF CACHE BOOL "" FORCE)
set(SLANG_INCLUDE_DOCS OFF CACHE BOOL "" FORCE)
set(SLANG_INCLUDE_PYLIB OFF CACHE BOOL "" FORCE)
add_subdirectory(external/slang)
endif()
# FetchContent for dependencies
include(FetchContent)
# toml++ - TOML parsing for configuration files
FetchContent_Declare(
tomlplusplus
GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
GIT_TAG v3.4.0
GIT_SHALLOW ON
)
FetchContent_MakeAvailable(tomlplusplus)
# reflect-cpp - JSON serialization (required for LSP)
if(SLANG_AUTOS_BUILD_LSP)
FetchContent_Declare(
reflectcpp
GIT_REPOSITORY https://github.com/getml/reflect-cpp.git
GIT_TAG v0.17.0
GIT_SHALLOW ON
)
FetchContent_MakeAvailable(reflectcpp)
# Suppress warnings in reflect-cpp
if(TARGET reflectcpp AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(reflectcpp PRIVATE
-Wno-missing-field-initializers
-Wno-unused-parameter
)
endif()
endif()
# ============================================================================
# Main Library
# ============================================================================
add_library(slang-autos-lib
src/CompilationUtils.cpp
src/Diagnostics.cpp
src/Parser.cpp
src/TemplateMatcher.cpp
src/SignalAggregator.cpp
src/Writer.cpp
src/Tool.cpp
src/AutosAnalyzer.cpp
src/Config.cpp
src/DotStarExpander.cpp
)
target_include_directories(slang-autos-lib
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(slang-autos-lib
PUBLIC
slang::slang
tomlplusplus::tomlplusplus
)
# Enable warnings
target_compile_options(slang-autos-lib PRIVATE
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall -Wextra -Wpedantic>
$<$<CXX_COMPILER_ID:MSVC>:/W4>
)
# ============================================================================
# CLI Executable
# ============================================================================
add_executable(slang-autos src/main.cpp)
target_link_libraries(slang-autos
PRIVATE
slang-autos-lib
)
# ============================================================================
# Dot-Star Expand CLI
# ============================================================================
add_executable(slang-expand src/main_expand.cpp)
target_link_libraries(slang-expand
PRIVATE
slang-autos-lib
)
# ============================================================================
# Tests
# ============================================================================
if(SLANG_AUTOS_BUILD_TESTS)
enable_testing()
# Catch2 - Testing framework
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.5.2
)
FetchContent_MakeAvailable(Catch2)
add_subdirectory(tests)
endif()
# ============================================================================
# LSP Extension
# ============================================================================
if(SLANG_AUTOS_BUILD_LSP)
add_subdirectory(extensions/lsp)
endif()
# ============================================================================
# Install
# ============================================================================
include(GNUInstallDirs)
install(TARGETS slang-autos slang-expand
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
if(SLANG_AUTOS_BUILD_LSP)
install(TARGETS slang-autos-lsp
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()