-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
95 lines (79 loc) · 3.13 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#[[
Copyright 2022 The Silkpre Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
# ethash requires cmake 3.16.2
cmake_minimum_required(VERSION 3.16.2)
option(SILKPRE_TESTING "Build tests and test tools" OFF)
get_directory_property(SILKPRE_HAS_PARENT PARENT_DIRECTORY)
if(NOT SILKPRE_HAS_PARENT)
if(NOT CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchain.cmake CACHE FILEPATH "" FORCE)
endif()
set(HUNTER_URL "https://github.com/cpp-pm/hunter/archive/v0.24.1.tar.gz")
set(HUNTER_SHA1 "4942227a6e6f5e64414c55b97ef98609de199d18")
if(SILKPRE_TESTING)
set(HUNTER_PACKAGES benchmark Catch ethash intx)
else()
set(HUNTER_PACKAGES ethash intx)
endif()
include(FetchContent)
FetchContent_Declare(SetupHunter GIT_REPOSITORY https://github.com/cpp-pm/gate)
FetchContent_MakeAvailable(SetupHunter)
endif()
project(silkpre)
# TODO: disable exceptions
# GMP
find_path(GMP_INCLUDE_DIR NAMES gmp.h)
if(MSVC)
find_library(GMP_LIBRARY mpir)
else()
find_library(GMP_LIBRARY gmp)
endif()
if(GMP_LIBRARY MATCHES ${CMAKE_SHARED_LIBRARY_SUFFIX})
set(gmp_library_type SHARED)
else()
set(gmp_library_type STATIC)
endif()
message(STATUS "GMP: ${GMP_LIBRARY}, ${GMP_INCLUDE_DIR}")
add_library(gmp ${gmp_library_type} IMPORTED)
set_target_properties(
gmp PROPERTIES
IMPORTED_LOCATION ${GMP_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${GMP_INCLUDE_DIR}
)
# secp256k1
add_library(secp256k1 third_party/secp256k1/src/secp256k1.c)
if(MSVC)
target_link_libraries(secp256k1 PRIVATE gmp)
target_compile_definitions(secp256k1 PUBLIC USE_NUM_GMP USE_FIELD_INV_NUM USE_SCALAR_INV_NUM)
target_compile_definitions(secp256k1 PUBLIC USE_FIELD_10X26 USE_SCALAR_8X32)
target_compile_options(secp256k1 PRIVATE /w) # Not much we can do about warnings
else()
target_compile_definitions(secp256k1 PUBLIC USE_NUM_NONE USE_FIELD_INV_BUILTIN USE_SCALAR_INV_BUILTIN)
target_compile_definitions(secp256k1 PUBLIC USE_FIELD_5X52 USE_SCALAR_4X64 HAVE___INT128)
endif()
target_compile_definitions(secp256k1 PUBLIC ECMULT_WINDOW_SIZE=15 ECMULT_GEN_PREC_BITS=4 USE_ENDOMORPHISM)
target_compile_definitions(secp256k1 PUBLIC ENABLE_MODULE_ECDH)
target_compile_definitions(secp256k1 PUBLIC ENABLE_MODULE_RECOVERY)
target_include_directories(secp256k1 PRIVATE secp256k1 INTERFACE third_party/secp256k1/include)
# libff
set(CURVE "ALT_BN128" CACHE STRING "" FORCE)
option(WITH_PROCPS "" OFF)
option(IS_LIBFF_PARENT "" OFF)
if(MSVC)
option(MPIR_INSTEAD_OF_GMP "" ON)
endif()
add_subdirectory(third_party/libff)
add_subdirectory(lib)
if(SILKPRE_TESTING)
add_subdirectory(test)
endif()