Skip to content

Commit

Permalink
Improve and simplify the build process.
Browse files Browse the repository at this point in the history
  • Loading branch information
AmineKhaldi committed Sep 7, 2021
1 parent ffa9d77 commit b3dcc93
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 80 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Expand Up @@ -24,8 +24,8 @@ message(STATUS "Build benchmarks: ${BUILD_BLS_BENCHMARKS}")

# Add path for custom modules
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules
${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules
)

include(FetchContent)
Expand Down
2 changes: 1 addition & 1 deletion js-bindings/CMakeLists.txt
Expand Up @@ -16,7 +16,7 @@ add_executable(blsjs ${CMAKE_CURRENT_SOURCE_DIR}/jsbindings.cpp
)
add_custom_target(install_npm_dependencies npm ci)
add_dependencies(blsjs install_npm_dependencies)
target_link_libraries(blsjs PRIVATE blstmp relic_s)
target_link_libraries(blsjs PRIVATE bls)

# Copy necessary files for the npm package
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/package.json package.json COPYONLY)
Expand Down
19 changes: 1 addition & 18 deletions python-bindings/CMakeLists.txt
@@ -1,8 +1,3 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.14 FATAL_ERROR)
set (CMAKE_CXX_STANDARD 17)

# CMake 3.14+
include(FetchContent)

FetchContent_Declare(
pybind11
Expand All @@ -11,17 +6,5 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(pybind11 relic)


include_directories(
${INCLUDE_DIRECTORIES}
${relic_SOURCE_DIR}/include
${relic_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/../contrib/catch
)

if (GMP_FOUND)
include_directories(${GMP_INCLUDES})
endif(GMP_FOUND)

pybind11_add_module(blspy ${CMAKE_CURRENT_SOURCE_DIR}/pythonbindings.cpp)
target_link_libraries(blspy PRIVATE blstmp relic_s)
target_link_libraries(blspy PRIVATE bls)
80 changes: 21 additions & 59 deletions src/CMakeLists.txt
@@ -1,84 +1,46 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.14 FATAL_ERROR)
set (CMAKE_CXX_STANDARD 17)

file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
source_group("SrcHeaders" FILES ${HEADERS})

include_directories(
${INCLUDE_DIRECTORIES}
${relic_SOURCE_DIR}/include
${relic_BINARY_DIR}/include
)

if (GMP_FOUND)
include_directories(${GMP_INCLUDES})
endif(GMP_FOUND)

set(C_LIB ${CMAKE_BINARY_DIR}/libbls.a)

add_library(bls ${CMAKE_CURRENT_SOURCE_DIR}/privatekey.cpp)

add_library(blstmp ${HEADERS}
add_library(bls
${HEADERS}
${CMAKE_CURRENT_SOURCE_DIR}/privatekey.cpp
${CMAKE_CURRENT_SOURCE_DIR}/bls.cpp
${CMAKE_CURRENT_SOURCE_DIR}/elements.cpp
${CMAKE_CURRENT_SOURCE_DIR}/schemes.cpp
)

target_compile_definitions(blstmp PRIVATE BLSALLOC_SODIUM=1)
target_link_libraries(blstmp PUBLIC sodium)

if(MSVC)
add_custom_command(
OUTPUT ${C_LIB}
COMMAND ${CMAKE_AR} /OUT:${C_LIB} $<TARGET_FILE:blstmp> $<TARGET_FILE:relic_s>
DEPENDS blstmp relic_s
)
add_custom_target(combined_custom
DEPENDS ${C_LIB}
)
else()
set(OPREFIX object_)
set(LIBRARIES_TO_COMBINE
COMMAND ${CMAKE_COMMAND} -E make_directory ${OPREFIX}$<TARGET_NAME:blstmp> && cd ${OPREFIX}$<TARGET_NAME:blstmp> && ${CMAKE_AR} -x $<TARGET_FILE:blstmp>
COMMAND ${CMAKE_COMMAND} -E make_directory ${OPREFIX}$<TARGET_NAME:relic_s> && cd ${OPREFIX}$<TARGET_NAME:relic_s> && ${CMAKE_AR} -x $<TARGET_FILE:relic_s>
)

find_library(GMP_NAME NAMES libgmp.a)
if(NOT ${GMP_NAME} STREQUAL "GMP_NAME-NOTFOUND")
list(APPEND LIBRARIES_TO_COMBINE COMMAND ${CMAKE_COMMAND} -E make_directory ${OPREFIX}gmp && cd ${OPREFIX}gmp && ${CMAKE_AR} -x ${GMP_NAME})
endif()

add_custom_target(combined_custom
${LIBRARIES_TO_COMBINE}
COMMAND ${CMAKE_AR} -rs ${C_LIB} ${OPREFIX}*/*${CMAKE_C_OUTPUT_EXTENSION}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS blstmp relic_s
)
endif()
target_include_directories(bls
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
$<$<BOOL:${GMP_FOUND}>:${GMP_INCLUDES}>
${relic_SOURCE_DIR}/include
${relic_BINARY_DIR}/include
)

add_library(combined STATIC IMPORTED GLOBAL)
add_dependencies(combined combined_custom)
target_link_libraries(bls combined)
target_compile_definitions(bls
PRIVATE
BLSALLOC_SODIUM=1
)

set_target_properties(combined
PROPERTIES
IMPORTED_LOCATION ${C_LIB}
target_link_libraries(bls
PUBLIC
relic_s
sodium
)

file(GLOB includes "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp")
install(DIRECTORY ${relic_SOURCE_DIR}/include/ DESTINATION include/chiabls)
install(DIRECTORY ${relic_BINARY_DIR}/include/ DESTINATION include/chiabls)
install(FILES ${includes} DESTINATION include/chiabls)
install(FILES ${C_LIB} DESTINATION lib)
install(FILES ${HEADERS} DESTINATION include/chiabls)
install(FILES $<TARGET_FILE:bls> DESTINATION lib)

if(BUILD_BLS_TESTS)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/catch)
add_executable(runtest test.cpp)
target_link_libraries(runtest blstmp relic_s)
target_link_libraries(runtest PRIVATE bls)
endif()

if(BUILD_BLS_BENCHMARKS)
add_executable(runbench test-bench.cpp)
target_link_libraries(runbench blstmp relic_s)
target_link_libraries(runbench PRIVATE bls)
endif()

0 comments on commit b3dcc93

Please sign in to comment.