Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a DOWNLOAD_GMP option to build against a local GMP build #731

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,35 @@ if (NOT ZLIB_FOUND)
endif()
endif()

find_package(GMP)
if (NOT GMP_FOUND)
if (APPLE)
message(FATAL_ERROR "GMP not found. Try 'brew install gmp'.")
elseif (UNIX)
message(FATAL_ERROR "GMP not found. Try 'sudo apt install libgmp-dev' or 'sudo dnf install gmp-devel'.")
else()
message(FATAL_ERROR "GMP not found.")
option(DOWNLOAD_GMP "Download libgmp and build the library locally instead of using a system installation" OFF)
if (DOWNLOAD_GMP)
include(ExternalProject)
ExternalProject_Add(
gmp
URL https://gmplib.org/download/gmp/gmp-6.3.0.tar.xz
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/gmp
CONFIGURE_COMMAND "<SOURCE_DIR>/configure" "--prefix=<INSTALL_DIR>" --disable-shared --enable-static
)
ExternalProject_Get_property(gmp INSTALL_DIR)
add_library(GMP::GMP STATIC IMPORTED GLOBAL)
# Work around `Imported target "GMP::GMP" includes non-existent path`.
# See https://gitlab.kitware.com/cmake/cmake/-/issues/15052
file(MAKE_DIRECTORY ${INSTALL_DIR}/include)
set_target_properties(GMP::GMP PROPERTIES
IMPORTED_LOCATION "${INSTALL_DIR}/lib/libgmp.a"
INTERFACE_INCLUDE_DIRECTORIES "${INSTALL_DIR}/include")
add_dependencies(GMP::GMP gmp)
else()
find_package(GMP)
if (NOT GMP_FOUND)
set(download_gmp "setting -DDOWNLOAD_GMP=TRUE to use a local build of GMP instead of a system library")
if (APPLE)
message(FATAL_ERROR "GMP not found. Try 'brew install gmp' or ${download_gmp}.")
elseif (UNIX)
message(FATAL_ERROR "GMP not found. Try 'sudo apt install libgmp-dev' or 'sudo dnf install gmp-devel' or ${download_gmp}.")
else()
message(FATAL_ERROR "GMP not found. Try ${download_gmp}")
endif()
endif()
endif()

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ build directory, then e.g.
$ make -C build riscv_sim_rv64f_rvfi
```

By default `build_simulators.sh` will download and build [libgmp](https://gmplib.org/).
To use a system installation of libgmp, run `env DOWNLOAD_GMP=FALSE ./build_simulators.sh` instead.

### Executing test binaries

The simulator can be used to execute small test binaries.
Expand Down
7 changes: 4 additions & 3 deletions build_simulators.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

set -e

cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build -j2
: "${DOWNLOAD_GMP:=TRUE}"
cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDOWNLOAD_GMP="${DOWNLOAD_GMP}"
jobs=$( (nproc || sysctl -n hw.ncpu || echo 2) 2>/dev/null)
cmake --build build -j${jobs}
Loading