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 flake for nix build support #207

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
46 changes: 25 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
.[bB]in/
.[oP]bj/
[bB]in/
[oP]bj/
[tT]mp/
_[tT]mp/

.vs/
.sandbox/
.dist/
.keys/
dist/
out/

.DS_Store
*.log
park*_hash.txt

lib/*
build*/
cmake-build*/
.[bB]in/
.[oP]bj/
[bB]in/
[oP]bj/
[tT]mp/
_[tT]mp/

.vs/
.sandbox/
.dist/
.keys/
dist/
out/

.DS_Store
*.log
park*_hash.txt

lib/*
build*/
cmake-build*/

.idea/
cmake-build-debug/
result
44 changes: 31 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ set(CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules
)

set(BUILD_LOCAL "0" CACHE STRING "")
set(BUILD_BLADEBIT_TESTS "1" CACHE STRING "")

#
# Grab Dependencies
#
set(platform_libs)

if(NOT BUILD_LOCAL)
# BLS
include(FetchContent)

Expand All @@ -49,6 +52,12 @@ set(BUILD_BLS_PYTHON_BINDINGS "0" CACHE STRING "0")
set(BUILD_BLS_TESTS "0" CACHE STRING "")
set(BUILD_BLS_BENCHMARKS "0" CACHE STRING "")
FetchContent_MakeAvailable(bls)
else()
find_package(sodium REQUIRED)
find_package(gmp REQUIRED)
find_package(relic REQUIRED)
find_package(bls REQUIRED)
endif()

# Threads
find_package(Threads REQUIRED)
Expand All @@ -60,10 +69,11 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
endif()

# Catch
# TODO: Add configuration var to disable this
if(BUILD_BLADEBIT_TESTS)
include(cmake_modules/FindCatch2.cmake)
set_target_properties(Catch2 PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set_target_properties(Catch2WithMain PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()


# Config
Expand Down Expand Up @@ -157,13 +167,13 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
${c_opts})

set(tests_c_opts /DBB_TEST_MODE=1 ${tests_c_opts})
set(link_opts

set(link_opts
/SUBSYSTEM:CONSOLE
/STACK:33554432,1048576
${link_opts})

set(release_c_opts
set(release_c_opts
/Oi
/O2
/Gy
Expand Down Expand Up @@ -214,7 +224,7 @@ else()

set(tests_c_opts -DBB_TEST_MODE=1 ${tests_c_opts})

set(release_c_opts
set(release_c_opts
-O3 #-flto
-D_NDEBUG=1
-DNDEBUG=1
Expand All @@ -239,7 +249,7 @@ else()

# Avoid ranlib error: plugin needed to handle lto objectR "gcc-ar")
# set(c_opts -ffat-lto-objects ${c_opts})

# Build with native architecture when not building release packages
if(NOT DEFINED ENV{CI})
set(c_opts -march=native ${c_opts})
Expand Down Expand Up @@ -291,7 +301,7 @@ file(GLOB_RECURSE src_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
tests/*.cpp
)

file(GLOB_RECURSE src_dev RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
file(GLOB_RECURSE src_dev RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
CONFIGURE_DEPENDS LIST_DIRECTORIES false
src/sandbox/*.cpp
src/sandbox/*.h
Expand Down Expand Up @@ -376,7 +386,7 @@ set(bb_include_dirs
# target_compile_options(${tgt} PRIVATE $<$<CONFIG:Debug>:${c_opts} ${debug_c_opts}>)
# target_link_options(${tgt} PRIVATE $<$<CONFIG:Release>:${link_opts} ${release_link_opts}>)
# target_link_options(${tgt} PRIVATE $<$<CONFIG:Debug>:${link_opts} ${debug_link_opts}>)

# target_include_directories(${tgt} PRIVATE ${bb_include_dirs})
# endmacro()

Expand All @@ -387,8 +397,14 @@ set_target_properties(lib_bladebit PROPERTIES
OUTPUT_NAME bladebit
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)
target_link_libraries(lib_bladebit PUBLIC Threads::Threads bls ${platform_libs})
target_include_directories(lib_bladebit PUBLIC ${bb_include_dirs})
if(BUILD_LOCAL)
target_link_libraries(lib_bladebit PUBLIC Threads::Threads ${GMP_LIBRARIES} ${sodium_LIBRARY_RELEASE} ${BLS_LIBRARY} ${RELIC_LIBRARY} ${platform_libs})
target_include_directories(lib_bladebit PUBLIC ${bb_include_dirs} ${RELIC_INCLUDE_DIR} ${BLS_INCLUDE_DIR})
else()
target_link_libraries(lib_bladebit PUBLIC Threads::Threads bls ${platform_libs})
target_include_directories(lib_bladebit PUBLIC ${bb_include_dirs})
endif()


target_compile_options(lib_bladebit PUBLIC $<$<CONFIG:Release>:${c_opts} ${release_c_opts}>)
target_compile_options(lib_bladebit PUBLIC $<$<CONFIG:Debug>:${c_opts} ${debug_c_opts}>)
Expand All @@ -405,21 +421,23 @@ target_link_libraries(bladebit_dev PRIVATE lib_bladebit)
add_executable(fsegen src/tools/FSETableGenerator.cpp ${bb_sources} ${bb_headers})
target_link_libraries(fsegen PRIVATE lib_bladebit)

# add_executable(plot_tool
# src/tools/PlotTools_Main.cpp
# add_executable(plot_tool
# src/tools/PlotTools_Main.cpp
# src/tools/PlotReader.cpp
# src/tools/PlotValidator.cpp
# src/tools/PlotComparer.cpp
# src/tools/PlotComparer.cpp
# ${bb_headers}
# )
# target_link_libraries(plot_tool PRIVATE lib_bladebit)

# Tests
if(BUILD_BLADEBIT_TESTS)
add_executable(tests ${src_tests} ${bb_headers})
target_compile_options(tests PUBLIC $<$<CONFIG:Release>:${c_opts} ${release_c_opts} ${tests_c_opts}>)
target_compile_options(tests PUBLIC $<$<CONFIG:Debug>:${c_opts} ${debug_c_opts} ${tests_c_opts}>)
set_target_properties(tests PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
target_link_libraries(tests PRIVATE lib_bladebit Catch2::Catch2WithMain)
endif()

# Pretty source view for IDE projects
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src
Expand Down
25 changes: 25 additions & 0 deletions cmake_modules/Findbls.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Find libnuma
#
# NUMA_FOUND : True if libnuma was found
# NUMA_INCLUDE_DIR : Where to find numa.h & numaif.h
# NUMA_LIBRARY : Library to link

include(FindPackageHandleStandardArgs)

find_path(BLS_INCLUDE_DIR
NAMES bls.hpp chiabls/bls.hpp
HINTS ${INCLUDE_INSTALL_DIR})

find_library(BLS_LIBRARY
NAMES libbls.a
HINTS ${LIB_INSTALL_DIR})

set(BLS_INCLUDE_DIR ${BLS_INCLUDE_DIR}/chiabls)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(bls
REQUIRED_VARS BLS_INCLUDE_DIR BLS_LIBRARY)

mark_as_advanced(
BLS_INCLUDE_DIR
BLS_LIBRARY)
87 changes: 87 additions & 0 deletions cmake_modules/Findgmp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Try to find the GMP library
# https://gmplib.org/
#
# This module supports requiring a minimum version, e.g. you can do
# find_package(GMP 6.0.0)
# to require version 6.0.0 to newer of GMP.
#
# Once done this will define
#
# GMP_FOUND - system has GMP lib with correct version
# GMP_INCLUDES - the GMP include directory
# GMP_LIBRARIES - the GMP library
# GMP_VERSION - GMP version
#
# Copyright (c) 2016 Jack Poulson, <[email protected]>
# Redistribution and use is allowed according to the terms of the BSD license.

find_path(GMP_INCLUDES NAMES gmp.h PATHS $ENV{GMPDIR} ${INCLUDE_INSTALL_DIR})

# Set GMP_FIND_VERSION to 5.1.0 if no minimum version is specified
if(NOT GMP_FIND_VERSION)
if(NOT GMP_FIND_VERSION_MAJOR)
set(GMP_FIND_VERSION_MAJOR 5)
endif()
if(NOT GMP_FIND_VERSION_MINOR)
set(GMP_FIND_VERSION_MINOR 1)
endif()
if(NOT GMP_FIND_VERSION_PATCH)
set(GMP_FIND_VERSION_PATCH 0)
endif()
set(GMP_FIND_VERSION
"${GMP_FIND_VERSION_MAJOR}.${GMP_FIND_VERSION_MINOR}.${GMP_FIND_VERSION_PATCH}")
endif()

message("GMP_INCLUDES=${GMP_INCLUDES}")
if(GMP_INCLUDES)
# Since the GMP version macros may be in a file included by gmp.h of the form
# gmp-.*[_]?.*.h (e.g., gmp-x86_64.h), we search each of them.
file(GLOB GMP_HEADERS "${GMP_INCLUDES}/gmp.h" "${GMP_INCLUDES}/gmp-*.h")
foreach(gmp_header_filename ${GMP_HEADERS})
file(READ "${gmp_header_filename}" _gmp_version_header)
string(REGEX MATCH
"define[ \t]+__GNU_MP_VERSION[ \t]+([0-9]+)" _gmp_major_version_match
"${_gmp_version_header}")
if(_gmp_major_version_match)
set(GMP_MAJOR_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+__GNU_MP_VERSION_MINOR[ \t]+([0-9]+)"
_gmp_minor_version_match "${_gmp_version_header}")
set(GMP_MINOR_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+__GNU_MP_VERSION_PATCHLEVEL[ \t]+([0-9]+)"
_gmp_patchlevel_version_match "${_gmp_version_header}")
set(GMP_PATCHLEVEL_VERSION "${CMAKE_MATCH_1}")
set(GMP_VERSION
${GMP_MAJOR_VERSION}.${GMP_MINOR_VERSION}.${GMP_PATCHLEVEL_VERSION})
endif()
endforeach()

# Check whether found version exists and exceeds the minimum requirement
if(NOT GMP_VERSION)
set(GMP_VERSION_OK FALSE)
message(STATUS "GMP version was not detected")
elseif(${GMP_VERSION} VERSION_LESS ${GMP_FIND_VERSION})
set(GMP_VERSION_OK FALSE)
message(STATUS "GMP version ${GMP_VERSION} found in ${GMP_INCLUDES}, "
"but at least version ${GMP_FIND_VERSION} is required")
else()
set(GMP_VERSION_OK TRUE)
endif()
endif()

if(STBIN)
set(_gmp_lib_name libgmp.a)
else()
set(_gmp_lib_name libgmp.so)
endif()

find_library(GMP_LIBRARIES
NAMES
${_gmp_lib_name} gmp.lib libgmp-10 libgmp gmp
PATHS
$ENV{GMPDIR} ${LIB_INSTALL_DIR}
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(gmp DEFAULT_MSG
GMP_INCLUDES GMP_LIBRARIES GMP_VERSION_OK)
mark_as_advanced(GMP_INCLUDES GMP_LIBRARIES)
25 changes: 25 additions & 0 deletions cmake_modules/Findrelic.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Find libnuma
#
# NUMA_FOUND : True if libnuma was found
# NUMA_INCLUDE_DIR : Where to find numa.h & numaif.h
# NUMA_LIBRARY : Library to link

include(FindPackageHandleStandardArgs)

find_path(RELIC_INCLUDE_DIR
NAMES relic_conf.h relic/relic_conf.h
HINTS ${INCLUDE_INSTALL_DIR})

find_library(RELIC_LIBRARY
NAMES librelic_s.a
HINTS ${LIB_INSTALL_DIR})

set(RELIC_INCLUDE_DIR ${RELIC_INCLUDE_DIR}/relic)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(RELIC
REQUIRED_VARS RELIC_INCLUDE_DIR RELIC_LIBRARY)

mark_as_advanced(
RELIC_INCLUDE_DIR
RELIC_LIBRARY)
Loading