Skip to content

Commit

Permalink
cmake: Prepare blst dependency (#972)
Browse files Browse the repository at this point in the history
Configure blst dependency using CMake's ExternalProject.
  • Loading branch information
chfast authored Aug 27, 2024
1 parent 2d20cc6 commit 6caebac
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
43 changes: 43 additions & 0 deletions cmake/blst.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
include_guard()
include(ExternalProject)

if(MSVC)
set(BLST_BUILD_SCRIPT build.bat)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# Don't pass CC to the script because it doesn't work.
set(BLST_BUILD_SCRIPT ./build.sh -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET})
else()
# Pass CC and AR, this supports cross-compilation.
# Pass CFLAGS as part of CC (e.g. to pass -m32). Using CFLAGS directly overwrites blst's default.
string(JOIN " " BLST_CC ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS})
set(BLST_BUILD_SCRIPT ./build.sh CC='${BLST_CC}' AR='${CMAKE_AR}')
endif()

ExternalProject_Add(
blst
EXCLUDE_FROM_ALL TRUE
PREFIX ${PROJECT_BINARY_DIR}/deps
URL https://github.com/supranational/blst/archive/refs/tags/v0.3.13.tar.gz
URL_HASH SHA256=89772cef338e93bc0348ae531462752906e8fa34738e38035308a7931dd2948f
DOWNLOAD_NO_PROGRESS TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ${BLST_BUILD_SCRIPT}
BUILD_IN_SOURCE TRUE
BUILD_BYPRODUCTS "<SOURCE_DIR>/${CMAKE_STATIC_LIBRARY_PREFIX}blst${CMAKE_STATIC_LIBRARY_SUFFIX}"
LOG_BUILD TRUE
LOG_OUTPUT_ON_FAILURE TRUE
INSTALL_COMMAND ""
)
ExternalProject_Get_Property(blst SOURCE_DIR)

set(BLST_INCLUDE_DIR ${SOURCE_DIR}/bindings)
file(MAKE_DIRECTORY ${BLST_INCLUDE_DIR})

add_library(blst::blst STATIC IMPORTED GLOBAL)
add_dependencies(blst::blst blst)
set_target_properties(
blst::blst PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${BLST_INCLUDE_DIR}
IMPORTED_LOCATION ${SOURCE_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}blst${CMAKE_STATIC_LIBRARY_SUFFIX}
)

2 changes: 2 additions & 0 deletions lib/evmone_precompiles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright 2023 The evmone Authors.
# SPDX-License-Identifier: Apache-2.0

include(blst)

add_library(evmone_precompiles STATIC)
add_library(evmone::precompiles ALIAS evmone_precompiles)
target_link_libraries(evmone_precompiles PUBLIC evmc::evmc_cpp PRIVATE evmone::evmmax)
Expand Down

0 comments on commit 6caebac

Please sign in to comment.