-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
229 lines (193 loc) · 9.14 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
####################################################################################################
# Copyright 2022 Chair of EDA, Technical University of Munich
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
####################################################################################################
####################################################################################################
# cmake project settings
cmake_minimum_required(VERSION 3.15)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR})
project(vrtlmod)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
message(WARNING "CMAKE_CXX_STANDARD not set. Default to ${CMAKE_CXX_STANDARD}")
endif()
####################################################################################################
####################################################################################################
# cmake project settings
option(BUILD_TESTING "Enable Tests" OFF)
include(CTest)
option (FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." True)
if (${FORCE_COLORED_OUTPUT})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options (-fdiagnostics-color=always)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options (-fcolor-diagnostics)
endif()
endif()
####################################################################################################
####################################################################################################
# cmake install settings
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/installed" CACHE PATH "default install path" FORCE)
endif()
set(CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_DATADIR "${CMAKE_INSTALL_PREFIX}/share")
set(CMAKE_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include")
set(CMAKE_INSTALL_BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")
####################################################################################################
####################################################################################################
# environment ######################################################################################
if(NOT LLVM_DIR) #try environment
set(LLVM_DIR $ENV{LLVM_DIR})
endif()
####################################################################################################
# cmake packages
find_package(VERILATOR REQUIRED)
if( ${verilator_VERSION_MAJOR} LESS 4 OR ${verilator_VERSION_MAJOR} GREATER 4)
message(FATAL_ERROR "Verilator version \"${verilator_VERSION}\" is not required major 4.xxx" )
endif()
if(NOT Clang_DIR)
set(Clang_DIR_SEARCH ${LLVM_DIR}/lib/cmake/clang)
endif()
message(STATUS "LLVM_DIR: ${LLVM_DIR}")
find_package(LLVM REQUIRED CONFIG
NO_DEFAULT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
PATHS ${LLVM_DIR}/lib/cmake/llvm
)
message(STATUS "LLVM_DIR: ${LLVM_DIR}")
if( ${LLVM_VERSION_MAJOR} LESS 13)
message(FATAL_ERROR "LLVM version \"${LLVM_VERSION}\" is less than required major 13.xxx" )
endif()
if(${LLVM_VERSION_MAJOR} GREATER 13)
message(WARNING "LLVM version \"${LLVM_VERSION}\" is greater than tested major 13.xxx" )
endif()
find_package(Clang REQUIRED CONFIG
NO_DEFAULT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
PATHS ${Clang_DIR_SEARCH}
)
find_package(Boost 1.70 REQUIRED
COMPONENTS filesystem
)
message("Boost Version: ${Boost_VERSION}")
message("Using LLVM_DIR: ${LLVM_DIR}")
message("LLVM Version: ${LLVM_VERSION} at ${LLVM_INSTALL_PREFIX}")
message("LLVM INCLUDE DIRS: ${LLVM_INCLUDE_DIRS}")
message("Using Clang_DIR: ${Clang_DIR}")
message("Clang INCLUDE DIRS: ${LLVM_INSTALL_PREFIX}/lib/clang/${LLVM_VERSION}/include" "")
####################################################################################################
####################################################################################################
# Third Party/ non-package Libraries ###############################################################
add_subdirectory(third_party)
####################################################################################################
if(LLVM_FOUND AND Clang_FOUND AND verilator_FOUND)
add_definitions(-DVRTLMOD_VERSION="0.9.4")
add_definitions(-DVRTLMOD_VERILATOR_VERSION=${VRTLMOD_VERILATOR_VERSION})
set(CLANG_INCLUDE_DIRS ${LLVM_INSTALL_PREFIX}/lib/clang/${LLVM_VERSION}/include)
set(CLANG_LIBS clangTooling clangRewriteFrontend)
llvm_map_components_to_libnames(LLVM_LIBS option support Support)
# read default target dictionary from file
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/src/vapi/templates/targetdictionary.hpp CMAKE_TARGET_DICTIONARY_BODY)
# replace default boilerplate
string(REGEX REPLACE "^/\*.*#ifndef" "#ifndef" CMAKE_TARGET_DICTIONARY_BODY "${CMAKE_TARGET_DICTIONARY_BODY}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/vapi/templates/targetdictionary_header.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/targetdictionary_header.cpp @ONLY)
add_library(${PROJECT_NAME}-core OBJECT
src/util/logging.cpp
src/util/utility.cpp
src/vrtlmod.cpp
src/vapi/generator.cpp
src/vapi/templates/vrtlmodapi_header.cpp
src/vapi/templates/vrtlmodapi_source.cpp
${CMAKE_CURRENT_BINARY_DIR}/targetdictionary_header.cpp
src/core/consumer.cpp
src/core/filecontext.cpp
src/core/core.cpp
src/core/types.cpp
src/core/vrtlparse.cpp
src/passes/elaborate.cpp
src/passes/analyze.cpp
src/passes/signaldeclrewrite.cpp
src/passes/injectionrewrite.cpp
src/passes/rewritemacrosaction.cpp
)
set(AUTO_INCLUDE_DIRS ${CLANG_INCLUDE_DIRS} ${VERILATOR_INCLUDE_DIRS})
list(LENGTH AUTO_INCLUDE_DIRS AUTO_INCLUDE_DIRS_SIZE)
list(TRANSFORM AUTO_INCLUDE_DIRS PREPEND "\"-I")
list(TRANSFORM AUTO_INCLUDE_DIRS APPEND "\"")
string(REPLACE ";" ",\n " AUTO_INCLUDE_DIRS "${AUTO_INCLUDE_DIRS}")
configure_file(include/vrtlmod/util/utility.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/vrtlmod/util/utility.hpp @ONLY)
target_link_libraries(${PROJECT_NAME}-core PRIVATE
pugixml
Boost::filesystem
${CLANG_LIBS}
${LLVM_LIBS}
)
target_include_directories(${PROJECT_NAME}-core PUBLIC
include
${CMAKE_CURRENT_BINARY_DIR}/include
${LLVM_INCLUDE_DIRS}
)
target_include_directories(${PROJECT_NAME}-core PRIVATE
${VERILATOR_INCLUDE_DIRS}
)
add_executable(${PROJECT_NAME}-bin
src/main.cpp
)
target_link_libraries(${PROJECT_NAME}-bin PRIVATE
${PROJECT_NAME}-core
)
if(NOT LLVM_ENABLE_RTTI) # set or unset by find_package(LLVM)
message(WARNING "LLVM built without Runtime Type Information (RTTI) (-DLLVM_ENABLE_RTTI=Off)... Disable Runtime Type Information (-fno-rtti) for vrtlmod.")
target_compile_options(${PROJECT_NAME}-core PUBLIC -fno-rtti)
target_compile_options(${PROJECT_NAME}-bin PUBLIC -fno-rtti)
endif()
set_target_properties(${PROJECT_NAME}-bin
PROPERTIES OUTPUT_NAME ${PROJECT_NAME}
)
endif()
option(BUILD_DOC "Build documentation" OFF)
find_package(Doxygen)
if (DOXYGEN_FOUND)
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/doc/doxyfile.cmake.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/doc/doxyfile)
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
add_custom_target( doc EXCLUDE_FROM_ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating ${PROJECT_NAME} API documentation with Doxygen"
VERBATIM
)
else (DOXYGEN_FOUND)
message("Doxygen need to be installed to generate the doxygen documentation")
endif (DOXYGEN_FOUND)
########### TESTING #################
add_subdirectory(test)
install(TARGETS ${PROJECT_NAME}-bin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/static
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/vrtlmod-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/vrtlmod-config.cmake @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/vrtlmod-config.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake)