-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
161 lines (131 loc) · 4.82 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
cmake_minimum_required(VERSION 3.27.6)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
if(NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER "clang")
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER "clang++")
endif()
# HDF5 and PThreads do not have static libraries
#set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
project(Atlas CXX)
set (SIM_BASE ${PROJECT_SOURCE_DIR})
# Profile build flags
set(CMAKE_CXX_FLAGS_FASTDEBUG "-O3 -g")
set(CMAKE_CXX_FLAGS_DEBUG "-U_FORTIFY_SOURCE -UNDEBUG -O0 -g")
if(EXISTS ${SPARTA_SEARCH_DIR}/CMakeLists.txt)
set(BUILD_SPARTA_FROM_SOURCE TRUE)
else()
set(BUILD_SPARTA_FROM_SOURCE FALSE)
endif()
if(NOT BUILD_SPARTA_FROM_SOURCE)
add_compile_options ( -Werror
-Wall -Wextra -Winline -Winit-self -Wunused-function
-Wuninitialized -Wsequence-point -Wno-inline -Wunknown-pragmas
-Woverloaded-virtual -Wunused-parameter -Wmissing-field-initializers -pipe)
else()
add_compile_options (
-Winline -Winit-self -Wunused-function
-Wuninitialized -Wsequence-point -Wno-inline -Wunknown-pragmas
-Woverloaded-virtual -Wmissing-field-initializers -pipe)
endif()
# Use ccache if installed
find_program (CCACHE_PROGRAM ccache)
if (CCACHE_PROGRAM)
set_property (GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
message ("-- Using ccache")
endif ()
################################################################################
# Set up Sparta
set(SPARTA_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
# To build/use a side sparta, the suggestion is to install sparta in a
# local directory and set SPARTA_SEARCH_DIR to that:
#
# cd /my/path/to/map/sparta/build
# cmake --install . --prefix .
#
# cd atlas/build
# SPARTA_SEARCH_DIR=/my/path/to/map/sparta/build cmake ....args
#
if(BUILD_SPARTA_FROM_SOURCE)
message (STATUS "Building SPARTA from source in ${SPARTA_SEARCH_DIR}")
add_subdirectory(${SPARTA_SEARCH_DIR} "${CMAKE_BINARY_DIR}/sparta")
include_directories(${SPARTA_SEARCH_DIR})
include(${SPARTA_SEARCH_DIR}/cmake/SpartaTestingMacros.cmake)
include(${SPARTA_SEARCH_DIR}/cmake/sparta-config.cmake)
set(SPARTA_LIBS ${Sparta_LIBS})
else()
if(IS_DIRECTORY ${SPARTA_SEARCH_DIR})
message (STATUS "Using '${SPARTA_SEARCH_DIR}' for sparta install")
elseif(DEFINED ENV{CONDA_PREFIX})
message (STATUS "Looking for SPARTA in the conda environment: '$ENV{CONDA_PREFIX}'")
set(SPARTA_SEARCH_DIR $ENV{CONDA_PREFIX})
else()
message (STATUS "If needed, please provide the location where sparta is installed: -DSPARTA_SEARCH_DIR=<directory>")
endif()
set(CMAKE_MODULE_PATH "${SPARTA_SEARCH_DIR}/lib/cmake/sparta" ${CMAKE_MODULE_PATH})
find_package(Sparta REQUIRED)
set(SPARTA_LIBS "SPARTA::sparta")
if (NOT SPARTA_FOUND)
message (FATAL_ERROR "Sparta was not found in ${SPARTA_SEARCH_DIR}")
else()
message (STATUS "Sparta was found in ${SPARTA_SEARCH_DIR}")
endif()
include_directories(${SPARTA_INCLUDE_DIRS})
endif()
################################################################################
include_directories(${CMAKE_SOURCE_DIR})
# Mavis
include_directories(SYSTEM mavis)
add_subdirectory(mavis)
# SoftFloat
include_directories(SYSTEM softfloat)
add_subdirectory(softfloat)
# ELFIO
include_directories(SYSTEM elfio)
# 32-bit register JSON directory
add_compile_definitions(REG32_JSON_DIR="${SIM_BASE}/arch/rv32")
add_compile_definitions(REG64_JSON_DIR="${SIM_BASE}/arch/rv64")
add_subdirectory(arch)
add_subdirectory(core)
add_subdirectory(core/inst_handlers)
add_subdirectory(system)
add_subdirectory(sim)
add_subdirectory(cosim)
add_subdirectory(test)
include(FetchContent)
FetchContent_Declare(
spike
GIT_REPOSITORY https://github.com/riscv-software-src/riscv-isa-sim.git
GIT_TAG master
SOURCE_DIR ${SIM_BASE}/spike
)
FetchContent_MakeAvailable(spike)
################################################################################
if(NOT CLANGFORMAT_EXECUTABLE)
set(CLANGFORMAT_EXECUTABLE clang-format)
endif()
# CPUTopology is pretty clean as it is. There's an option to NOT
# collapse the array of structures in clang-format v16, but we're not
# there yet
add_custom_target(clangformat
find core system sim arch include cosim test -name "*.[hc]pp" > clang-format-files.out
COMMAND
${CLANGFORMAT_EXECUTABLE} -i --files=clang-format-files.out
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
COMMENT
"Formatting Atlas with ${CLANGFORMAT_EXECUTABLE} ..."
)
add_custom_target(clangformat-check
find core system sim arch include cosim test -name "*.[hc]pp" > clang-format-files.out
COMMAND
${CLANGFORMAT_EXECUTABLE} --Werror -n --files=clang-format-files.out
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
COMMENT
"Formatting Atlas with ${CLANGFORMAT_EXECUTABLE} ..."
)