Skip to content

Commit

Permalink
cmake: Some fixes and optional targets (dashpay#14)
Browse files Browse the repository at this point in the history
* cmake: Only include GMP_INCLUDES if gmp has been found

Otherwise it fails with the following if gmp wasn't found:

CMake Error in src/CMakeLists.txt:
  Found relative path while evaluating include directories of <target>:  "GMP_INCLUDES-NOTFOUND"

* cmake: Drop broken gmp include

This seems to be broken because `GMP_INCLUDE_DIR` isn't set at all by `Findgmp.cmake`, it sets `GMP_INCLUDES` instead. It's however set by relic's script which isn't configured at this point though. If you want to keep this include it should be `include_directories(${GMP_INCLUDES})` rather i guess?

* cmake: Install relic headers into chiabls

I think this should be done because chiabls depends on how relic was
configure.

* cmake: Make blspy optional

* cmake: Make runbench/runtest optional
  • Loading branch information
xdustinface authored Mar 16, 2021
1 parent 58bbcd0 commit 1776926
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ ENDIF()

project(BLS)

set(BUILD_BLS_PYTHON_BINDINGS 1 CACHE INTEGER "")
set(BUILD_BLS_TESTS 1 CACHE INTEGER "")
set(BUILD_BLS_BENCHMARKS 1 CACHE INTEGER "")

message(STATUS "Build python bindings: ${BUILD_BLS_PYTHON_BINDINGS}")
message(STATUS "Build tests: ${BUILD_BLS_TESTS}")
message(STATUS "Build benchmarks: ${BUILD_BLS_BENCHMARKS}")

# Add path for custom modules
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
Expand All @@ -32,7 +40,6 @@ set(STBIN TRUE)
find_package(gmp)
if (GMP_FOUND)
message(STATUS "Found libgmp")
include_directories(${GMP_INCLUDE_DIR})
set(ARITH "gmp" CACHE STRING "")
else()
set(ARITH "easy" CACHE STRING "")
Expand Down Expand Up @@ -90,5 +97,7 @@ if (EMSCRIPTEN)
else()
# emscripten can't build python bindings, it produces only javascript
# add_subdirectory(contrib/pybind11)
add_subdirectory(python-bindings)
if (BUILD_BLS_PYTHON_BINDINGS)
add_subdirectory(python-bindings)
endif()
endif()
5 changes: 4 additions & 1 deletion python-bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ include_directories(
${relic_SOURCE_DIR}/include
${relic_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/../contrib/catch
${GMP_INCLUDES}
)

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

pybind11_add_module(blspy ${CMAKE_CURRENT_SOURCE_DIR}/pythonbindings.cpp)

if (SODIUM_FOUND)
Expand Down
32 changes: 22 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ include_directories(
${INCLUDE_DIRECTORIES}
${relic_SOURCE_DIR}/include
${relic_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/../contrib/catch
${GMP_INCLUDES}
)

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)
Expand Down Expand Up @@ -78,16 +80,26 @@ set_target_properties(combined
)

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)

add_executable(runtest test.cpp)
add_executable(runbench test-bench.cpp)
if (BUILD_BLS_TESTS)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/catch)
add_executable(runtest test.cpp)
if (SODIUM_FOUND)
target_link_libraries(runtest blstmp relic_s sodium)
else()
target_link_libraries(runtest blstmp relic_s)
endif()
endif()

if (SODIUM_FOUND)
target_link_libraries(runtest blstmp relic_s sodium)
target_link_libraries(runbench blstmp relic_s sodium)
else()
target_link_libraries(runtest blstmp relic_s)
target_link_libraries(runbench blstmp relic_s)
if (BUILD_BLS_BENCHMARKS)
add_executable(runbench test-bench.cpp)
if (SODIUM_FOUND)
target_link_libraries(runbench blstmp relic_s sodium)
else()
target_link_libraries(runbench blstmp relic_s)
endif()
endif()

0 comments on commit 1776926

Please sign in to comment.