generated from riscv-software-src/template-riscv-code
-
Notifications
You must be signed in to change notification settings - Fork 58
/
CMakeLists.txt
129 lines (106 loc) · 4.29 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
cmake_minimum_required(VERSION 3.19)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
project(olympia CXX)
add_compile_options ( -Werror
-Wall -Wextra -Winline -Winit-self -Wno-unused-function
-Wuninitialized -Wno-sequence-point -Wno-inline -Wno-unknown-pragmas
-Woverloaded-virtual -Wno-unused-parameter -Wno-missing-field-initializers -pipe)
################################################################################
# Set up Sparta
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)
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})
################################################################################
# Set up STF library
set (STF_LIB_BASE ${PROJECT_SOURCE_DIR}/stf_lib)
set (DISABLE_STF_DOXYGEN ON)
set (DISABLE_STF_TESTS ON)
if (CMAKE_BUILD_TYPE MATCHES "^[Rr]elease")
set (FULL_LTO true)
endif()
include(${STF_LIB_BASE}/cmake/stf_linker_setup.cmake)
setup_stf_linker(false)
# 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 (SIM_BASE ${PROJECT_SOURCE_DIR})
set (OLYMPIA_VERSION "v0.1.0")
add_definitions(-DOLYMPIA_VERSION=\"${OLYMPIA_VERSION}\")
# Profile build flags
set(CMAKE_CXX_FLAGS_PROFILE "-O3 -pg -g -ftime-trace")
set(CMAKE_CXX_FLAGS_FASTDEBUG "-O3 -g")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
# Include directories
include_directories (core mss sim)
include_directories (SYSTEM fsl)
include_directories (SYSTEM mavis)
include_directories (SYSTEM stf_lib)
# Mavis, the Core, MSS, the simulator and Fusion
add_subdirectory (mavis)
add_subdirectory (core)
add_subdirectory (mss)
# Tell FSL to use the top mavis submodule, instead of fsl's submodule
set(FSL_MAVIS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/mavis")
add_subdirectory (fsl)
# Add STF library to the build
add_subdirectory (${STF_LIB_BASE})
# Add testing, but do not build as part of the 'all' target
add_subdirectory (test EXCLUDE_FROM_ALL)
# The simulator
add_executable(olympia
sim/OlympiaSim.cpp
sim/main.cpp
)
target_link_libraries (olympia core mss SPARTA::sparta mavis ${STF_LINK_LIBS})
if (CMAKE_BUILD_TYPE MATCHES "^[Rr]elease")
target_compile_options (core PUBLIC -flto)
target_compile_options (mss PUBLIC -flto)
target_compile_options (olympia PUBLIC -flto)
target_link_options (olympia PUBLIC -flto)
endif()
# Create a few links like reports and arch directories
file(CREATE_LINK ${PROJECT_SOURCE_DIR}/reports ${CMAKE_CURRENT_BINARY_DIR}/reports SYMBOLIC)
file(CREATE_LINK ${PROJECT_SOURCE_DIR}/arches ${CMAKE_CURRENT_BINARY_DIR}/arches SYMBOLIC)
file(CREATE_LINK ${PROJECT_SOURCE_DIR}/mavis/json ${CMAKE_CURRENT_BINARY_DIR}/mavis_isa_files SYMBOLIC)
file(CREATE_LINK ${PROJECT_SOURCE_DIR}/traces ${CMAKE_CURRENT_BINARY_DIR}/traces SYMBOLIC)
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 mss -name "*.[hc]pp" | grep -v CPUTopology > clang-format-files.out
COMMAND
${CLANGFORMAT_EXECUTABLE} -i --files=clang-format-files.out
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
COMMENT
"Formatting ${prefix} with ${CLANGFORMAT_EXECUTABLE} ..."
)
add_custom_target(clangformat-check
find core mss -name "*.[hc]pp" | grep -v CPUTopology > clang-format-files.out
COMMAND
${CLANGFORMAT_EXECUTABLE} --Werror -n --files=clang-format-files.out
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
COMMENT
"Formatting ${prefix} with ${CLANGFORMAT_EXECUTABLE} ..."
)