-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCMakeLists.txt
375 lines (299 loc) · 13.2 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(qbox VERSION 2.0)
##############################################
# ----- fetch GreenSocs cmake BOILERPLATE
##############################################
set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to build all targets.")
set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE BOOL "The with CMAKE_CXX_STANDARD selected C++ standard is a requirement.")
set(GIT_BRANCH "main" CACHE STRING "Git branch from which to clone all gs repositoies")
set(GREENSOCS_GIT "" CACHE STRING "Git directory from which to clone all gs repositories")
set(PKG_LOCK "package-lock.cmake" CACHE STRING "Package lock which will be used by the user")
set(QEMU_PATH_NAME "" CACHE STRING "The name of the path of qemu in the git directory")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
execute_process(COMMAND git config --get remote.origin.url
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE GIT_URL)
string(REGEX MATCH "(.*\/)" GREENSOCS_GIT_ORIGIN "${GIT_URL}")
string(REGEX REPLACE "(.*)/sandboxes/[^\/]*/(.*)" "\\1/" GREENSOCS_GIT_ORIGIN "${GREENSOCS_GIT_ORIGIN}")
if ("${GREENSOCS_GIT}" STREQUAL "")
set(GREENSOCS_GIT "${GREENSOCS_GIT_ORIGIN}")
endif()
message(STATUS "GREENSOCS_GIT = ${GREENSOCS_GIT}")
string(FIND "${GREENSOCS_GIT}" "github" GITHUB_URL)
if(GITHUB_URL EQUAL -1)
set(QEMU_PATH_NAME "qemu/qemu")
else()
set(QEMU_PATH_NAME "qemu")
endif()
message(STATUS "QEMU_PATH_NAME=${QEMU_PATH_NAME}")
include(FetchContent)
include(CTest)
# download CPM.cmake
file(
DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.5/CPM.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
)
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)
if(EXISTS "${PROJECT_SOURCE_DIR}/Packages")
if("${GREENSOCS_GIT}" STREQUAL "")
set(GREENSOCS_GIT "https://git.codelinaro.org/clo/private/qqvp/")
endif()
endif()
# Allow using package-lock.cmake files in projects using this boilerplate to
# pin repos, etc.
CPMUsePackageLock(${PKG_LOCK})
# ##############################################
include(${PROJECT_SOURCE_DIR}/cmake/boilerplate.cmake)
if(APPLE)
set(CMAKE_BUILD_RPATH "\@executable_path/../lib;\@executable_path/../lib/libqemu")
set(CMAKE_INSTALL_RPATH "\@executable_path/../lib;\@executable_path/../lib/libqemu")
else()
set(CMAKE_BUILD_RPATH "\$ORIGIN/../lib;\$ORIGIN/../lib/libqemu")
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib;\$ORIGIN/../lib/libqemu")
endif()
list(APPEND CMAKE_BUILD_RPATH
"${CMAKE_BINARY_DIR}/_deps/libqemu-build/qemu-prefix/lib/"
"${CMAKE_BINARY_DIR}"
)
if ("${CMAKE_INSTALL_PREFIX}" STREQUAL "" OR "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local")
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install)
message(STATUS "CMAKE PREFIX PATH = ${CMAKE_INSTALL_PREFIX}")
endif()
# This block allow to retrieves the name of the binary directory which is used to ignore SystemC tests
# ----------------------------------------------------------------------------------------
string(REPLACE "${PROJECT_SOURCE_DIR}/" "" CMAKE_BINARY_NAME "${CMAKE_BINARY_DIR}")
message(STATUS "CMAKE_BINARY_NAME = ${CMAKE_BINARY_NAME}")
message(STATUS "PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR}")
configure_file(${PROJECT_SOURCE_DIR}/cmake/CTestCustom.cmake ${CMAKE_BINARY_DIR} @ONLY)
# ----------------------------------------------------------------------------------------
mark_as_advanced(CMAKE_CXX_STANDARD_REQUIRED)
include(GNUInstallDirs)
#This is an exclusive define for the SCP library which allow to switch ON/OFF if we want thread local or not.
add_compile_definitions(DISABLE_REPORT_THREAD_LOCAL)
find_path(LIBELF_INCLUDE_DIR NAMES "libelf.h" "libelf/libelf.h"
HINTS $ENV{LIBELF_HOME}/include /usr/include /usr/local/include
REQUIRED)
find_library(LIBELF_LIBRARIES NAMES elf "libelf.a"
HINTS $ENV{LIBELF_HOME}/lib /usr/lib /lib /usr/local/lib
REQUIRED)
find_library(LIBZ_LIBRARIES NAMES z "libz.a"
HINTS $ENV{LIBZ_HOME}/lib /usr/lib /lib
REQUIRED)
list(APPEND LIBELF_LIBRARIES ${LIBZ_LIBRARIES})
list(APPEND LIBELF_INCLUDE_DIR ${LIBELF_INCLUDE_DIR}/libelf)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibELF DEFAULT_MSG
LIBELF_LIBRARIES
LIBELF_INCLUDE_DIR)
mark_as_advanced(LIBELF_INCLUDE_DIR LIBELF_LIBRARIES)
find_package(Threads REQUIRED)
gs_addexpackage("gh:nih-at/libzip#v1.10.1")
gs_systemc()
# Other Dependencies
gs_addexpackage("gh:rpclib/rpclib#v2.3.0")
# libasio-dev should be installed on the system
if(NOT GS_ONLY)
set(CROW_BUILD_EXAMPLES OFF CACHE STRING "Disable building Crow examples")
set(DCROW_BUILD_TESTS OFF CACHE STRING "Disable building Crow tests")
set(CROW_INSTALL ON CACHE STRING "Enable Crow install")
gs_addexpackage("gh:CrowCpp/Crow#v1.2.0")
set(CROW_DEP "Crow::Crow")
endif()
option(WITHOUT_PYTHON_BINDER "without python binder model" OFF)
option(QEMU_ENABLE_USB_REDIRECT "enable qemu usb redirect" OFF)
if((NOT WITHOUT_PYTHON_BINDER) AND (NOT GS_ONLY))
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)
gs_addexpackage("gh:pybind/pybind11#v2.11.1")
set(PYBIND11_EMBED "pybind11::embed")
endif()
set(systemc_srcs
systemc-components/common/src/cciutils.cc
systemc-components/common/src/luautils.cc
systemc-components/common/src/uutils.cc
systemc-components/common/src/memory_services.cc
systemc-components/common/src/libgssync/pre_suspending_sc_support.cc
systemc-components/common/src/libgssync/qk_factory.cc
systemc-components/common/src/libgssync/qkmultithread.cc
systemc-components/common/src/macs/backends/tap.cc
systemc-components/common/src/macs/components/mac.cc
systemc-components/common/src/macs/components/phy.cc
)
if (NOT WITHOUT_QEMU)
set (qemu_srcs
qemu-components/common/src/libqemu-cxx/callbacks.cc
qemu-components/common/src/libqemu-cxx/console.cc
qemu-components/common/src/libqemu-cxx/cpu.cc
qemu-components/common/src/libqemu-cxx/device.cc
qemu-components/common/src/libqemu-cxx/gpex.cc
qemu-components/common/src/libqemu-cxx/gpio.cc
qemu-components/common/src/libqemu-cxx/libqemu-cxx.cc
qemu-components/common/src/libqemu-cxx/loader.cc
qemu-components/common/src/libqemu-cxx/memory.cc
qemu-components/common/src/libqemu-cxx/object.cc
qemu-components/common/src/libqemu-cxx/rcu-read-lock.cc
qemu-components/common/src/libqemu-cxx/sysbus.cc
qemu-components/common/src/libqemu-cxx/target-info.cc
qemu-components/common/src/libqemu-cxx/timer.cc
qemu-components/common/src/libqemu-cxx/target/aarch64.cc
qemu-components/common/src/libqemu-cxx/target/riscv.cc
qemu-components/common/src/libqemu-cxx/target/microblaze.cc
qemu-components/common/src/libqemu-cxx/target-info.cc
qemu-components/common/src/dmi_utils.cc
)
endif()
add_library(${PROJECT_NAME} SHARED
${systemc_srcs}
# qemu_srcs should be empty if WITHOUT_QEMU is set
${qemu_srcs}
)
build_lua()
if (NOT WITHOUT_QEMU)
CPMAddPackage(
NAME libslirp
GIT_REPOSITORY https://gitlab.freedesktop.org/slirp/libslirp.git
GIT_TAG v4.8.0
GIT_SHALLOW TRUE
DOWNLOAD_ONLY YES
)
find_program(MESON meson)
if(NOT MESON)
message(FATAL_ERROR "meson not found")
endif()
execute_process(
COMMAND ${MESON} setup --default-library static --prefix ${libslirp_BINARY_DIR}/libslirp-prefix/ ${libslirp_BINARY_DIR} ${libslirp_SOURCE_DIR}
WORKING_DIRECTORY ${libslirp_SOURCE_DIR}
RESULT_VARIABLE result
ERROR_VARIABLE error_output
)
if(result)
message(FATAL_ERROR "The command 'meson setup' failed with the output error: \n${error_output}")
endif()
execute_process(
COMMAND ${MESON} install -C ${libslirp_BINARY_DIR}
WORKING_DIRECTORY ${libslirp_SOURCE_DIR}
RESULT_VARIABLE result
ERROR_VARIABLE error_output
)
if(result)
message(FATAL_ERROR "The command 'meson install' failed with the output error: \n${error_output}")
endif()
set(CONFIGURE_ENVIRONMENT_VARIABLE "PKG_CONFIG_PATH=${libslirp_BINARY_DIR}/libslirp-prefix/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig/")
# TODO: Remove the "hack" in the future, once support for Ubuntu 20 can be
# dropped. A fix for it was added in CMake 3.18, but the default version of
# Ubuntu 20 is 3.16
# This is a hack to workaround a CMake issue. We specify an existing file
# which is _not_ a submodule so that FetchContent does not init any
# submodule. See https://gitlab.kitware.com/cmake/cmake/-/issues/20579
CPMAddPackage(
NAME qemu
GIT_REPOSITORY "${GREENSOCS_GIT}/${QEMU_PATH_NAME}.git"
GIT_TAG "${GIT_BRANCH}"
GIT_SHALLOW TRUE
GIT_SUBMODULES "CMakeLists.txt"
)
if(TARGET libqemu)
list(APPEND TARGET_LIBS "libqemu")
endif()
set(LIBQEMU_CXX_SRC_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/qemu-components/common/include/libqemu-cxx)
set(LIBQEMU_CXX_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX})
set(LIBQEMU_CXX_LIB_DIR ${CMAKE_INSTALL_LIBDIR}/libqemu-cxx)
foreach(target ${LIBQEMU_TARGETS})
# The quite complex generator expressions does the followings:
# - fetch the library name through the INTERFACE_LINK_LIBRARIES property
# - evaluate it as a generator expression since it can contains
# $<BUILD_INTERFACE> and $<INSTALL_INTERFACE> in a list
# - join the result to remove empty elements in the final list
target_compile_definitions(${PROJECT_NAME}
PRIVATE
LIBQEMU_TARGET_${target}_LIBRARY="$<JOIN:$<GENEX_EVAL:$<TARGET_PROPERTY:libqemu-${target},INTERFACE_LINK_LIBRARIES>>,>")
endforeach()
target_include_directories(
${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/qemu-components/common/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}>
)
target_link_libraries(${PROJECT_NAME} PUBLIC
libqemu
)
install(DIRECTORY ${LIBQEMU_CXX_SRC_INCLUDE_DIR}
DESTINATION ${LIBQEMU_CXX_INCLUDE_DIR})
if (WIN32)
install(TARGETS ${PROJECT_NAME} DESTINATION lib/$<IF:$<CONFIG:Debug>,debug,release>)
else ()
install(TARGETS ${PROJECT_NAME} EXPORT libqemu-cxx-targets)
endif ()
include(CMakePackageConfigHelpers)
configure_package_config_file(libqemu-cxxConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/libqemu-cxxConfig.cmake
INSTALL_DESTINATION ${LIBQEMU_CXX_LIB_DIR}/cmake)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/libqemu-cxxConfigVersion.cmake
VERSION 1.0.0
COMPATIBILITY AnyNewerVersion)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/libqemu-cxxConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/libqemu-cxxConfigVersion.cmake
DESTINATION ${LIBQEMU_CXX_LIB_DIR}/cmake)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/qemu-components" DESTINATION ${CMAKE_INSTALL_PREFIX})
set(QEMU_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/qemu-components")
endif() # WITHOUT_QEMU
if(CMAKE_COMPILER_IS_GNUCC)
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall -Wextra -Wno-unused-parameter
"$<$<CONFIG:Debug>:-O0;-g3;-ggdb>"
)
endif()
if (APPLE)
set(CMAKE_MACOSX_RPATH ON)
# Since dlopen does not automatically look into `brew --prefix`/lib, we
# add this path to both CMAKE_BUILD_RPATH and CMAKE_INSTALL_RPATH, so
# the user won't need to set the DYLD_LIBRARY_PATH env variable.
find_program(BREW_BIN brew)
execute_process(COMMAND ${BREW_BIN} --prefix
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE BREW_PREFIX)
set(BREW_LIB ${BREW_PREFIX}/lib)
list(APPEND CMAKE_BUILD_RPATH ${BREW_LIB})
list(APPEND CMAKE_INSTALL_RPATH ${BREW_LIB})
endif (APPLE)
gs_addexpackage("gh:google/googletest#v1.15.2")
target_include_directories(
${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/systemc-components/common/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}>
${LIBELF_INCLUDE_DIR}
)
target_link_libraries(${PROJECT_NAME} PUBLIC
${TARGET_LIBS}
${LIBELF_LIBRARIES}
Threads::Threads
rpc
${CROW_DEP}
zip
${PYBIND11_EMBED}
${CMAKE_DL_LIBS}
)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/systemc-components" DESTINATION ${CMAKE_INSTALL_PREFIX})
set(QBOX_INCLUDE_DIR "${QEMU_INCLUDE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/systemc-components")
gs_export(${PROJECT_NAME} ${QBOX_INCLUDE_DIR})
if (NOT DEFINED GS_ONLY)
install(TARGETS rpc zip DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
endif()
list(APPEND TARGET_LIBS ${PROJECT_NAME})
if(NOT WITHOUT_QEMU)
add_subdirectory(qemu-components)
add_subdirectory(platforms)
endif()
add_subdirectory(systemc-components)
if((NOT WITHOUT_PYTHON_BINDER) AND (NOT GS_ONLY))
add_subdirectory(py-models)
endif()
add_subdirectory(html)
gs_enable_testing()
if(UNIX AND NOT APPLE)
target_link_libraries(${PROJECT_NAME} INTERFACE rt)
endif()