forked from gvsoc/gvsoc-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
183 lines (137 loc) · 5.32 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
cmake_minimum_required(VERSION 3.16.3)
set(CMAKE_INSTALL_MESSAGE LAZY)
if (NOT CMAKE_SKIP_INSTALL_RPATH)
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
project(gvsoc-core)
# 2.2 Misc
#
# import_kconfig(<prefix> <kconfig_fragment> [<keys>])
#
# Parse a KConfig fragment (typically with extension .config) and
# introduce all the symbols that are prefixed with 'prefix' into the
# CMake namespace. List all created variable names in the 'keys'
# output variable if present.
function(import_kconfig prefix kconfig_fragment)
# Parse the lines prefixed with 'prefix' in ${kconfig_fragment}
file(
STRINGS
${kconfig_fragment}
DOT_CONFIG_LIST
REGEX "^${prefix}"
ENCODING "UTF-8"
)
foreach (CONFIG ${DOT_CONFIG_LIST})
# CONFIG could look like: CONFIG_NET_BUF=y
# Match the first part, the variable name
string(REGEX MATCH "[^=]+" CONF_VARIABLE_NAME ${CONFIG})
# Match the second part, variable value
string(REGEX MATCH "=(.+$)" CONF_VARIABLE_VALUE ${CONFIG})
# The variable name match we just did included the '=' symbol. To just get the
# part on the RHS we use match group 1
set(CONF_VARIABLE_VALUE ${CMAKE_MATCH_1})
if("${CONF_VARIABLE_VALUE}" MATCHES "^\"(.*)\"$") # Is surrounded by quotes
set(CONF_VARIABLE_VALUE ${CMAKE_MATCH_1})
endif()
set("${CONF_VARIABLE_NAME}" "${CONF_VARIABLE_VALUE}" PARENT_SCOPE)
list(APPEND keys "${CONF_VARIABLE_NAME}")
endforeach()
foreach(outvar ${ARGN})
set(${outvar} "${keys}" PARENT_SCOPE)
endforeach()
endfunction()
# GVSOC needs to be given a config file containing all the components to be compiled
foreach(subdir ${GVSOC_MODULES})
set(GAPY_TARGETS_DIR_OPT ${GAPY_TARGETS_DIR_OPT} --target-dir=${subdir})
endforeach()
set(TARGET_CONFIG_DIR ${CMAKE_BINARY_DIR}/gvsoc/configs)
file(MAKE_DIRECTORY ${TARGET_CONFIG_DIR})
if(DEFINED GVSOC_TARGETS)
string(REPLACE " " ";" GVSOC_TARGETS_LIST "${GVSOC_TARGETS}")
foreach(target ${GVSOC_TARGETS_LIST})
set(TARGET_CONFIG ${TARGET_CONFIG_DIR}/${target}.config)
message(STATUS "Generating GVSOC config to ${TARGET_CONFIG} with command: ")
# Gapy is used to extract the list of components out of the specified target
set(GAPY_CMD gapy --target=${target} ${GAPY_TARGETS_DIR_OPT}
--platform=gvsoc
--builddir=${CMAKE_CURRENT_BINARY_DIR}
--installdir=${CMAKE_INSTALL_PREFIX}/models
--component-file=${TARGET_CONFIG} components
--py-stack
)
string(REPLACE ";" " " GAPY_CMD_STR " ${GAPY_CMD}")
message(STATUS ${GAPY_CMD_STR})
# We generate first the list of components for the specified target
execute_process (
COMMAND ${GAPY_CMD} RESULT_VARIABLE ret
)
if(ret EQUAL "1")
message( FATAL_ERROR "Caught error while generating gvsoc config")
endif()
import_kconfig(CONFIG_ ${TARGET_CONFIG})
endforeach()
else()
set(CONFIG_BUILD_ALL 1)
endif()
# install sub folder
set(GVSOC_MODELS_INSTALL_FOLDER "models")
set(GVSOC_MODELS_OPTIM_INSTALL_FOLDER "")
set(GVSOC_MODELS_DEBUG_INSTALL_FOLDER "debug")
set(GVSOC_MODELS_SV_INSTALL_FOLDER "sv")
set(GVSOC_MODELS_OPTIM_M32_INSTALL_FOLDER "m32")
set(GVSOC_MODELS_DEBUG_M32_INSTALL_FOLDER "debug_m32")
# ================
# Utility includes
# ================
include(cmake/vp_model.cmake)
# =======
# Options
# =======
option(BUILD_OPTIMIZED "build GVSOC with optimizations" ON)
option(BUILD_DEBUG "build GVSOC with debug information" ON)
option(BUILD_OPTIMIZED_M32 "build GVSOC with optimizations in 32bits mode" OFF)
option(BUILD_DEBUG_M32 "build GVSOC with debug information in 32bits mode" OFF)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O2")
set(CMAKE_CC_FLAGS_RELWITHDEBINFO "-g -O2")
# set target types
vp_set_target_types(
BUILD_DEBUG ${BUILD_DEBUG}
BUILD_OPTIMIZED ${BUILD_OPTIMIZED}
BUILD_OPTIMIZED_M32 ${BUILD_OPTIMIZED_M32}
BUILD_DEBUG_M32 ${BUILD_DEBUG_M32}
)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
install(DIRECTORY bin/ DESTINATION bin USE_SOURCE_PERMISSIONS)
add_subdirectory(dpi-wrapper)
add_subdirectory(engine)
add_subdirectory(models)
set(is_first true)
foreach(subdir ${GVSOC_MODULES})
if (NOT ${is_first})
if(IS_DIRECTORY ${subdir})
get_filename_component(name ${subdir} NAME)
message(STATUS ${subdir})
if(EXISTS ${subdir}/CMakeLists.txt)
add_subdirectory(${subdir} ${CMAKE_CURRENT_BINARY_DIR}/${name}/models)
endif()
endif()
endif()
set(is_first false)
endforeach()
if(NOT CONFIG_COMPONENTS STREQUAL "")
string(REPLACE " " ";" CONFIG_COMPONENTS ${CONFIG_COMPONENTS})
foreach(component ${CONFIG_COMPONENTS})
string(REPLACE " " ";" SRCS_LIST "${CONFIG_SRCS_${component}}")
vp_model(NAME ${component}
SOURCES "${SRCS_LIST}"
)
endforeach()
endif()