Skip to content

Commit

Permalink
Add GMP and Bitwuzla with ASan + UBSan support.
Browse files Browse the repository at this point in the history
  • Loading branch information
fvrmatteo committed Nov 14, 2024
1 parent 0b86d0f commit 3136bea
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 15 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ simple_git(https://github.com/stp/stp a9bc247d98cd98213b2d0f6821dc51b823c50483
"-DBUILD_EXECUTABLES:STRING=OFF"
"-DSTATICCOMPILE:STRING=ON"
)
include(gmp.cmake)
include(xed.cmake)
include(bitwuzla.cmake)
if(NOT USE_SYSTEM_LLVM)
Expand Down
23 changes: 23 additions & 0 deletions GMPConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
if(GMP_FOUND)
return()
endif()

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)

find_library(GMP_LIBRARY gmp PATHS "${PACKAGE_PREFIX_DIR}/lib" NO_CACHE REQUIRED NO_DEFAULT_PATH)
add_library(GMP::GMP STATIC IMPORTED)
set_target_properties(GMP::GMP PROPERTIES
IMPORTED_CONFIGURATIONS "NOCONFIG"
IMPORTED_LOCATION_NOCONFIG "${GMP_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${PACKAGE_PREFIX_DIR}/include"
)

find_library(GMP_LIBRARY gmpxx PATHS "${PACKAGE_PREFIX_DIR}/lib" NO_CACHE REQUIRED NO_DEFAULT_PATH)
add_library(GMP::GMPXX STATIC IMPORTED)
set_target_properties(GMP::GMPXX PROPERTIES
IMPORTED_CONFIGURATIONS "NOCONFIG"
IMPORTED_LOCATION_NOCONFIG "${GMP_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${PACKAGE_PREFIX_DIR}/include"
)

set(GMP_FOUND ON)
35 changes: 20 additions & 15 deletions bitwuzla.cmake
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
find_package(Python3 COMPONENTS Interpreter REQUIRED)
message(STATUS "Python3: ${Python3_EXECUTABLE}")

# TODO: pass compiler flags

set(CONFIGURE_ARGS
"--assertions"
"--no-testing"
"--no-unit-testing"
"--prefix"
"<SOURCE_DIR>/install"
"-Db_ndebug=true"
"-Dtesting=disabled"
"-Dunit_testing=disabled"
"-Dprefix=${CMAKE_INSTALL_PREFIX}"
"-Dbuildtype=debugoptimized"
"-Dpkg_config_path=${CMAKE_INSTALL_PREFIX}/lib/pkgconfig"
)

if(USE_SANITIZERS)
list(APPEND CONFIGURE_ARGS "--assertions --asan --ubsan")
list(APPEND CONFIGURE_ARGS
"-Db_ndebug=false"
"-Db_sanitize=address,undefined"
"-Db_lundef=false"
)
endif()

if(BUILD_SHARED_LIBS)
list(APPEND CONFIGURE_ARGS "--shared")
list(APPEND CONFIGURE_ARGS "-Ddefault_library=shared")
else()
list(APPEND CONFIGURE_ARGS "--static")
list(APPEND CONFIGURE_ARGS "-Ddefault_library=static")
endif()

ExternalProject_Add(bitwuzla
GIT_REPOSITORY
"https://github.com/LLVMParty/bitwuzla"
GIT_TAG
"sanitizers_fix"
"sanitizers"
GIT_PROGRESS
ON
GIT_SHALLOW
Expand All @@ -35,11 +37,14 @@ ExternalProject_Add(bitwuzla
BUILD_IN_SOURCE
1
CONFIGURE_COMMAND
"${Python3_EXECUTABLE}" "<SOURCE_DIR>/configure.py" ${CONFIGURE_ARGS}
"meson"
"setup"
"build"
${CONFIGURE_ARGS}
BUILD_COMMAND
"ninja" "-C" "<SOURCE_DIR>/build" "install"
"ninja" "-C" "<SOURCE_DIR>/build"
INSTALL_COMMAND
"${CMAKE_COMMAND}" -E copy_directory <SOURCE_DIR>/install "${CMAKE_INSTALL_PREFIX}"
"ninja" "-C" "<SOURCE_DIR>/build" "install"
PREFIX
bitwuzla-prefix
)
Expand Down
44 changes: 44 additions & 0 deletions gmp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# TODO: pass compiler flags

set(DEFAULT_C_CXX_FLAGS "-pedantic")

if(CMAKE_OSX_SYSROOT)
set(DEFAULT_C_CXX_FLAGS "${DEFAULT_C_CXX_FLAGS} -isysroot ${CMAKE_OSX_SYSROOT}")
endif()

set(CONFIGURE_ARGS
"--enable-cxx"
"--prefix"
"${CMAKE_INSTALL_PREFIX}"
"CC=${CMAKE_C_COMPILER}"
"CXX=${CMAKE_CXX_COMPILER}"
"CFLAGS=${CMAKE_C_FLAGS} ${DEFAULT_C_CXX_FLAGS}"
"CXXFLAGS=${CMAKE_CXX_FLAGS} ${DEFAULT_C_CXX_FLAGS}"
"LDFLAGS=${CMAKE_EXE_LINKER_FLAGS}"
)

if(BUILD_SHARED_LIBS)
list(APPEND CONFIGURE_ARGS "--enable-shared=yes --enable-static=no")
else()
list(APPEND CONFIGURE_ARGS "--enable-shared=no --enable-static=yes")
endif()

ExternalProject_Add(gmp
URL
https://gmplib.org/download/gmp/gmp-6.3.0.tar.xz
URL_MD5
956dc04e864001a9c22429f761f2c283
CMAKE_CACHE_ARGS
${CMAKE_ARGS}
CONFIGURE_COMMAND
"<SOURCE_DIR>/configure" ${CONFIGURE_ARGS}
BUILD_COMMAND
"make"
INSTALL_COMMAND
"make" "install"
PREFIX
gmp-prefix
)

# TODO: generate GMPVersion.cmake as well file
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/GMPConfig.cmake.in" "${CMAKE_INSTALL_PREFIX}/lib/cmake/gmp/GMPConfig.cmake" @ONLY)

0 comments on commit 3136bea

Please sign in to comment.