|
| 1 | +cmake_minimum_required (VERSION 3.2) |
| 2 | +# project(<name> VERSION <ver> LANGUAGES CXX) |
| 3 | +project(libutt VERSION 0.1.0.0 LANGUAGES CXX) |
| 4 | +message(STATUS "Building UTT") |
| 5 | +# |
| 6 | +# Configuration options |
| 7 | +# |
| 8 | +set( |
| 9 | + CURVE |
| 10 | + "BN128" |
| 11 | + CACHE |
| 12 | + STRING |
| 13 | + "Default curve: one of ALT_BN128, BN128, EDWARDS, MNT4, MNT6" |
| 14 | +) |
| 15 | + |
| 16 | +option( |
| 17 | + BINARY_OUTPUT |
| 18 | + "In serialization of elliptic curve points, output raw binary data (instead of decimal), which is smaller and faster." |
| 19 | + OFF |
| 20 | +) |
| 21 | + |
| 22 | +add_definitions( |
| 23 | + -DCURVE_${CURVE} |
| 24 | +) |
| 25 | + |
| 26 | +option( |
| 27 | + USE_MULTITHREADING |
| 28 | + "Enable parallelized execution of DKG protocols using OpenMP" |
| 29 | + OFF |
| 30 | +) |
| 31 | + |
| 32 | +if(${CURVE} STREQUAL "BN128") |
| 33 | + add_definitions( |
| 34 | + -DBN_SUPPORT_SNARK=1 |
| 35 | + ) |
| 36 | +endif() |
| 37 | + |
| 38 | +# |
| 39 | +# Configure CCache if available |
| 40 | +# |
| 41 | +# find_program(CCACHE_FOUND ccache) |
| 42 | +# if(CCACHE_FOUND) |
| 43 | +# set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) |
| 44 | +# set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) |
| 45 | +# endif(CCACHE_FOUND) |
| 46 | + |
| 47 | +#find_package(Threads REQUIRED) |
| 48 | +#find_package(Boost 1.65 COMPONENTS program_options REQUIRED) |
| 49 | +#include_directories(${Boost_INCLUDE_DIR}) |
| 50 | + |
| 51 | +# OS X Catalina fix |
| 52 | +include_directories(SYSTEM "/usr/local/include") |
| 53 | +link_directories("/usr/local/lib") |
| 54 | + |
| 55 | +# Note: xassert and xutils are part of utt source code |
| 56 | +# set(utt_packages |
| 57 | +# xassert |
| 58 | +# xutils |
| 59 | +# ) |
| 60 | + |
| 61 | +# |
| 62 | +# Dependencies |
| 63 | +# |
| 64 | +# TODO: Find ate-pairing, libff, libfqfft too or issue error with pointer to install script |
| 65 | +# foreach(package ${utt_packages}) |
| 66 | +# find_package(${package} QUIET) |
| 67 | + |
| 68 | +# if(${package}_FOUND) |
| 69 | +# message("${package} library is installed!") |
| 70 | +# else() |
| 71 | +# message("${package} library not installed locally, please download from https//github.com/alinush/lib${package}") |
| 72 | +# endif() |
| 73 | +# endforeach() |
| 74 | + |
| 75 | +# |
| 76 | +# C++ options |
| 77 | +# TODO: change to set_target_properties? |
| 78 | +# https://crascit.com/2015/03/28/enabling-cxx11-in-cmake/ |
| 79 | +# |
| 80 | +set(CMAKE_CXX_STANDARD 17) |
| 81 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 82 | +set(CMAKE_CXX_EXTENSIONS OFF) |
| 83 | +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake") |
| 84 | +# |
| 85 | +# Compiler flags |
| 86 | +# |
| 87 | + |
| 88 | +# When you do 'a > b in 'C/C++, if a is unsigned and b is signed and equal to -1, C/C++ |
| 89 | +# actually casts b to unsigned (probably because casting unsigned to signed would require a bigger data type) |
| 90 | +# Thus, 1 > -1 will evaluate to false because during the cast -1 will be set to to 2^32 - 1 |
| 91 | +# |
| 92 | +# WARNING: For the love of god, do not remove this flag or you will regret it. Instead, |
| 93 | +# just use signed types everywhere and cast your unsigned to signed when mixing unsigned |
| 94 | +# variables with signed ones. See: http://soundsoftware.ac.uk/c-pitfall-unsigned |
| 95 | +set(CXX_FLAGS_INTEGER_CORRECTNESS |
| 96 | + "-Wconversion -Wsign-conversion -Wsign-compare") |
| 97 | +set(CXX_FLAGS_FORMAT |
| 98 | + "-Wformat-y2k -Wno-format-extra-args -Wno-format-zero-length -Wformat-nonliteral -Wformat-security -Wformat=2") |
| 99 | +set(CXX_FLAGS_OPTIMIZATIONS "-O3") |
| 100 | + |
| 101 | +string(APPEND CXX_FLAGS " ${CXX_FLAGS_OPTIMIZATIONS}") |
| 102 | +string(APPEND CXX_FLAGS " ${CXX_FLAGS_FORMAT}") |
| 103 | +string(APPEND CXX_FLAGS " ${CXX_FLAGS_INTEGER_CORRECTNESS}") |
| 104 | +# TODO: use target_compile_features instead: |
| 105 | +# https://cmake.org/cmake/help/v3.1/command/target_compile_features.html#command:target_compile_features |
| 106 | +# https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#prop_gbl:CMAKE_CXX_KNOWN_FEATURES |
| 107 | +string(APPEND CXX_FLAGS " -Wall") |
| 108 | +string(APPEND CXX_FLAGS " -Werror") |
| 109 | +string(APPEND CXX_FLAGS " -Wextra") |
| 110 | + |
| 111 | + |
| 112 | +# TODO: Figure out right way to deal with -fstrict-overflow / -Wstrict-overflow related errors |
| 113 | +string(APPEND CXX_FLAGS |
| 114 | + " -fno-strict-overflow") |
| 115 | +string(APPEND CXX_FLAGS_DEBUG |
| 116 | + " -O1") |
| 117 | +# "It turns out that some gcc builds (depends on the distro) set _FORTIFY_SOURCE internally, so you need to undefine it first. So if you used CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2", it might go better." |
| 118 | +# https://github.com/neovim/neovim/issues/2557 |
| 119 | +string(APPEND CXX_FLAGS_DEBUG |
| 120 | + " -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2") |
| 121 | + |
| 122 | +if("${USE_MULTITHREADING}") |
| 123 | + add_definitions(-DUSE_MULTITHREADING) |
| 124 | + string(APPEND CMAKE_CXX_FLAGS " -fopenmp") |
| 125 | +endif() |
| 126 | + |
| 127 | +# GNU and Clang-specific flags |
| 128 | +string(APPEND CMAKE_CXX_FLAGS |
| 129 | + " ${CXX_FLAGS}") |
| 130 | +string(APPEND CMAKE_CXX_FLAGS_DEBUG |
| 131 | + " ${CXX_FLAGS_DEBUG} -DUTT_LOG_DEBUG") |
| 132 | +# When building with 'cmake -DCMAKE_BUILD_TYPE=Trace' |
| 133 | +string(APPEND CMAKE_CXX_FLAGS_TRACE |
| 134 | + " ${CXX_FLAGS_DEBUG} -DUTT_LOG_TRACE") |
| 135 | + |
| 136 | +# using Clang |
| 137 | +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 138 | + # Clang-specific options |
| 139 | + string(APPEND CMAKE_CXX_FLAGS |
| 140 | + " -ferror-limit=3") |
| 141 | + string(APPEND CMAKE_CXX_FLAGS_DEBUG |
| 142 | + # " -fstack-protector-all -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls") |
| 143 | + " -fstack-protector-all -fno-omit-frame-pointer -fno-optimize-sibling-calls -ggdb -O0") |
| 144 | + # TODO: doesn't seem to work on MacOS, getting strange linking errors |
| 145 | + #string(APPEND CMAKE_CXX_FLAGS_DEBUG |
| 146 | + # " -D_LIBCPP_DEBUG=0") |
| 147 | + #string(APPEND CMAKE_CXX_FLAGS_DEBUG |
| 148 | + # " -D_LIBCPP_DEBUG=1") |
| 149 | + |
| 150 | +# using GCC |
| 151 | +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
| 152 | + # GCC-specific options |
| 153 | + string(APPEND CMAKE_CXX_FLAGS |
| 154 | + " -fmax-errors=3") |
| 155 | + string(APPEND CMAKE_CXX_FLAGS_DEBUG |
| 156 | + " -fstack-protector-all") |
| 157 | + # NOTE: define _GLIBCXX_DEBUG if you want bounds checking for std::vector::operator[] (but it seems to cause a segfault at the end of execution) |
| 158 | + # only works for libstdc++ from the GNU compiler, I think |
| 159 | + string(APPEND CMAKE_CXX_FLAGS_DEBUG |
| 160 | + " -D_GLIBCXX_DEBUG") |
| 161 | + |
| 162 | +# TODO: using Intel C++ |
| 163 | +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") |
| 164 | + |
| 165 | +# TODO: using Visual Studio C++ |
| 166 | +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") |
| 167 | + |
| 168 | +endif() |
| 169 | + |
| 170 | +# |
| 171 | +# Testing flags |
| 172 | +# |
| 173 | +enable_testing() |
| 174 | + |
| 175 | +include(dependencies.cmake) |
| 176 | +# Subdirectories |
| 177 | +add_subdirectory(libutt) |
| 178 | +add_subdirectory(libxassert) |
| 179 | +add_subdirectory(libxutils) |
| 180 | +add_subdirectory(wallet-cli) |
| 181 | + |
| 182 | +set(newutt_src |
| 183 | + libutt/src/api/UTTParams.cpp |
| 184 | + libutt/src/api/commitment.cpp |
| 185 | + libutt/src/api/client.cpp |
| 186 | + libutt/src/api/coinsSigner.cpp |
| 187 | + libutt/src/api/mint.cpp |
| 188 | + libutt/src/api/coin.cpp |
| 189 | + libutt/src/api/registrator.cpp |
| 190 | + libutt/src/api/common.cpp |
| 191 | + libutt/src/api/burn.cpp |
| 192 | + libutt/src/api/transaction.cpp |
| 193 | + libutt/src/api/budget.cpp |
| 194 | + ) |
| 195 | +add_library(utt_api STATIC ${newutt_src}) |
| 196 | +target_link_libraries(utt_api PUBLIC utt) |
| 197 | +target_include_directories(utt_api PUBLIC include) |
| 198 | +add_subdirectory(tests) |
| 199 | + |
| 200 | + |
| 201 | + |
0 commit comments