-
Notifications
You must be signed in to change notification settings - Fork 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2036 from ucb-bar/build-system
ADD: Add CMake build option for tests and example C++ program
- Loading branch information
Showing
10 changed files
with
167 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,4 @@ project/project/ | |
.sbt | ||
.classpath_cache/ | ||
.vscode/ | ||
tests/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
cmake ./tests/ -S ./tests/ -B ./tests/build/ -D CMAKE_BUILD_TYPE=Debug | ||
cmake --build ./tests/build/ --target all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
######################################################################################################################## | ||
# file: CMakeLists.txt | ||
# | ||
# usage: | ||
# Edit "VARIABLES"-section to suit project requirements. | ||
# Build instructions: | ||
# cmake . -S ./ -B ./build/ -D CMAKE_BUILD_TYPE=Debug | ||
# cmake --build ./build/ --target all | ||
# Cleaning: | ||
# cmake --build ./build/ --target clean | ||
######################################################################################################################## | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
project(chipyard-tests LANGUAGES C CXX) | ||
|
||
|
||
################################# | ||
# RISCV Toolchain | ||
################################# | ||
|
||
set(CMAKE_SYSTEM_NAME "Generic" CACHE STRING "") | ||
set(CMAKE_SYSTEM_PROCESSOR "riscv" CACHE STRING "") | ||
|
||
set(TOOLCHAIN_PREFIX "riscv64-unknown-elf-") | ||
|
||
set(CMAKE_AR "${TOOLCHAIN_PREFIX}ar") | ||
set(CMAKE_ASM_COMPILER "${TOOLCHAIN_PREFIX}gcc") | ||
set(CMAKE_C_COMPILER "${TOOLCHAIN_PREFIX}gcc") | ||
set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PREFIX}g++") | ||
set(CMAKE_LINKER "${TOOLCHAIN_PREFIX}ld") | ||
set(CMAKE_OBJCOPY "${TOOLCHAIN_PREFIX}objcopy") | ||
set(CMAKE_OBJDUMP "${TOOLCHAIN_PREFIX}objdump") | ||
set(CMAKE_SIZE "${TOOLCHAIN_PREFIX}size") | ||
|
||
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/..") | ||
set(CMAKE_EXECUTABLE_SUFFIX ".riscv") | ||
|
||
|
||
################################# | ||
# Flags | ||
################################# | ||
|
||
# CPU architecture | ||
set(ARCH "rv64imafd") | ||
set(ABI "lp64d") | ||
set(CMODEL "medany") | ||
set(ARCH_FLAGS -march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL}) | ||
|
||
# spec | ||
set(SPECS "htif_nano.specs") | ||
set(SPEC_FLAGS -specs=${SPECS}) | ||
|
||
# linker script | ||
set(LINKER_SCRIPT "htif.ld") | ||
|
||
add_compile_options(-std=gnu99) | ||
add_compile_options(-O2 -Wall -Wextra) | ||
add_compile_options(-fno-common -fno-builtin-printf) | ||
add_compile_options(${ARCH_FLAGS}) | ||
add_compile_options(${SPEC_FLAGS}) | ||
|
||
add_link_options(-static) | ||
add_link_options(${SPEC_FLAGS}) | ||
add_link_options(-T ${LINKER_SCRIPT}) | ||
|
||
|
||
################################# | ||
# Build | ||
################################# | ||
|
||
add_executable(pwm pwm.c) | ||
add_executable(blkdev blkdev.c) | ||
add_executable(accum accum.c) | ||
add_executable(charcount charcount.c) | ||
add_executable(cpp-hello cpp-hello.cpp) | ||
add_executable(nic-loopback nic-loopback.c) | ||
add_executable(big-blkdev big-blkdev.c) | ||
add_executable(pingd pingd.c) | ||
add_executable(streaming-passthrough streaming-passthrough.c) | ||
add_executable(streaming-fir streaming-fir.c) | ||
add_executable(nvdla nvdla.c) | ||
add_executable(spiflashread spiflashread.c) | ||
add_executable(spiflashwrite spiflashwrite.c) | ||
add_executable(fft fft.c) | ||
add_executable(gcd gcd.c) | ||
add_executable(hello hello.c) | ||
add_executable(mt-hello mt-hello.c) | ||
add_executable(symmetric symmetric.c) | ||
|
||
|
||
# Add custom command to generate spiflash.img from spiflash.py | ||
add_custom_command( | ||
OUTPUT ${CMAKE_BINARY_DIR}/spiflash.img | ||
COMMAND python3 ${CMAKE_SOURCE_DIR}/spiflash.py --outfile ${CMAKE_SOURCE_DIR}/spiflash.img | ||
DEPENDS ${CMAKE_SOURCE_DIR}/spiflash.py | ||
COMMENT "Generating spiflash.img" | ||
) | ||
|
||
# Add a target for spiflash.img | ||
add_custom_target(spiflash_img ALL | ||
DEPENDS ${CMAKE_BINARY_DIR}/spiflash.img | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
// HACK: This is a workaround for the missing __dso_handle routine in the current toolchain | ||
extern "C" void *__dso_handle = 0; | ||
|
||
int main() { | ||
cout << "Hello World!"; | ||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Generates a binary file that the SPI test uses | ||
|
||
outfile = "spiflash.img" | ||
import argparse | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Generate a binary file for SPI test") | ||
parser.add_argument("--outfile", type=str, default="spiflash.img", help="Output file") | ||
args = parser.parse_args() | ||
|
||
outfile = args.outfile | ||
|
||
with open(outfile, 'wb') as f: | ||
for i in range(0,0x100000,4): | ||
check = 0xdeadbeef - i | ||
f.write(check.to_bytes(4,'little')) | ||
with open(outfile, "wb") as f: | ||
for i in range(0,0x100000,4): | ||
check = 0xdeadbeef - i | ||
f.write(check.to_bytes(4, "little")) |