Skip to content

Commit

Permalink
Implement CMake build system
Browse files Browse the repository at this point in the history
This is a draft of a CMake build system. It doesn't yet include RVFI, JSON docs, formal stuff, etc.
  • Loading branch information
Timmmm committed Jan 2, 2025
1 parent 2cccaa9 commit 80d0154
Show file tree
Hide file tree
Showing 16 changed files with 579 additions and 711 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ _build/
_sbuild/
*.o
*.a
/z3_problems
z3_problems

# Typical CMake build directory.
/build
76 changes: 76 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
cmake_minimum_required(VERSION 3.22)

project(sail_riscv)

# Enable CTest
enable_testing()

# We technically require C++20 since the C generated by Sail - which we compile
# as C++ - uses designated initialisers, a C++20 feature. However in practice
# much older compilers support this feature so everything does work with C++17,
# but you get lots of warnings on compilers that support C++20 if you use
# this feature without -std=c++20.
if (cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(CMAKE_CXX_STANDARD 20)
else()
set(CMAKE_CXX_STANDARD 17)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

# Export compile_commands.json for IDE support.
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

# Always use Position Independent Code. By default it is only used for
# shared libraries (which require it), but you also need it for static
# libraries if you link them into shared libraries.
# Generally it just simplifies everything for a negligable performance cost.
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)

# Don't allow undefined symbols in shared libraries. This is generally a pain.
if (UNIX)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined")
endif()

# Optional faster binary. Increases compilation time a lot though due to LTO.
option(EXTRA_FAST "Enable aggressive optimisation flags (-march=native, -flto, etc)" FALSE)

if (EXTRA_FAST)
include("cmake/extra_fast.cmake")
endif()

# Extra CMake files.
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

# These are the main requirements.
# Don't use `REQUIRED` so that we can print custom help messages.
find_package(ZLIB)
if (NOT ZLIB_FOUND)
message(FATAL_ERROR "Zlib not found. Try 'sudo apt install zlib1g-dev' or 'sudo dnf install zlib-devel'.")
endif()

find_package(GMP)
if (NOT GMP_FOUND)
message(FATAL_ERROR "GMP not found. Try 'sudo apt install libgmp3-dev' or 'sudo dnf install gmp-devel'.")
endif()

find_program(SAIL_BIN "sail")
if (NOT SAIL_BIN)
message(FATAL_ERROR "Sail not found. See README.md for installation instructions.")
endif()

set(ENABLED_ARCHITECTURES "rv32;rv64" CACHE STRING "Enabled architectures to build (rv32, rv64, rv32d, rv64f)" )

# Softfloat support.
add_subdirectory("dependencies/softfloat")

# Sail C runtime.
add_subdirectory("sail_runtime")

# Sail model generated C code.
add_subdirectory("model")

# Emulator binary.
add_subdirectory("emulator")

# Old pre-compiled riscv-tests.
add_subdirectory("test/riscv-tests")
Loading

0 comments on commit 80d0154

Please sign in to comment.