-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
183 lines (152 loc) · 5.72 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# Copyright 2024 Jamie Cui
#
# 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.
cmake_minimum_required(VERSION 3.20)
project(
yacl_r
VERSION 0.4.5
DESCRIPTION "YACL-r (Yet Another Crypto Library for Research)"
HOMEPAGE_URL "https://github.com/Jamie-Cui/yacl-r"
LANGUAGES CXX C)
# option(BUILD_TESTING "Build the testing binaries (On/Off)." On)
# ------------------------------------------------------------------------------
# Project Generic Configuration
# ------------------------------------------------------------------------------
# Configure build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING "Build type" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug"
"MinSizeRel" "RelWithDebInfo")
endif()
message(STATUS "Build type (CMAKE_BUILD_TYPE): ${CMAKE_BUILD_TYPE}")
# Set module path
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
# Enable compile_commands.json for lsp
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
# This policy was introduced in CMake 3.13; OLD by default until CMake 3.21
cmake_policy(SET CMP0077 NEW)
cmake_policy(SET CMP0135 NEW)
# Generic this project's CMake modules
include(AddCompilerFlags)
include(AddYaclTest)
# Generic CMake modules
include(CheckCXXCompilerFlag)
include(CheckCXXSourceRuns)
include(CheckLanguage)
include(CMakeDependentOption)
include(CTest)
include(ExternalProject)
include(GNUInstallDirs)
include(FetchContent)
# ------------------------------------------------------------------------------
# Toolchain Configuration
# ------------------------------------------------------------------------------
# CMake arguments
set(CMAKE_POSITION_INDEPENDENT_CODE On) # Enable position-independent-code
set(CMAKE_CXX_STANDARD 17) # Enable C++17
set(CMAKE_C_STANDARD_REQUIRED Yes) # Force C standard to be present
# Additional compiler flags
add_compiler_flags("-Wall")
add_compiler_flags("-Wextra")
add_compiler_flags("-Werror")
add_compiler_flags("-Wno-sign-compare")
# FIXME try removing the following flags
add_compiler_flags("-Wno-unused-function")
add_compiler_flags("-Wno-vla") # no variable length error warning
add_compiler_flags("-Wno-shift-count-overflow")
add_compiler_flags("-Wno-deprecated-declarations") # for butil
add_compiler_flags("-Wno-unused-parameter") # for butil
# For cryptos
add_compiler_flags("-maes")
add_compiler_flags("-mavx")
add_compiler_flags("-mpclmul")
# make it colorful under ninja-build
if(CMAKE_GENERATOR STREQUAL Ninja)
add_compiler_flags(-fdiagnostics-color=always)
endif()
# ------------------------------------------------------------------------------
# External Dependencies Configuration
# ------------------------------------------------------------------------------
# prefer -pthread instead of -lpthread or -lpthreads
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
find_package(GMP REQUIRED)
set(CMAKE_THIRDPARTY_PREFIX ${CMAKE_BINARY_DIR}/thirdparty)
set(CMAKE_THIRDPARTY_LIBDIR ${CMAKE_THIRDPARTY_PREFIX}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_THIRDPARTY_BINDIR ${CMAKE_THIRDPARTY_PREFIX}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_THIRDPARTY_INCLUDEDIR
${CMAKE_THIRDPARTY_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
include(deps/abseil)
include(deps/blake3)
include(deps/brpc)
include(deps/cpu_features)
include(deps/fmt)
include(deps/fourq)
include(deps/gtest)
include(deps/protobuf)
include(deps/gflags)
include(deps/leveldb)
include(deps/libsodium)
include(deps/libtommath)
include(deps/mcl)
include(deps/msgpack)
include(deps/openssl)
include(deps/spdlog)
include(deps/sse2neon)
# ------------------------------------------------------------------------------
# Project Target Configuration
# ------------------------------------------------------------------------------
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
enable_testing()
add_library(yacl STATIC)
add_library(yacl_all INTERFACE)
target_include_directories(
yacl
PUBLIC ${CMAKE_THIRDPARTY_INCLUDEDIR}
# these dirs are only used when building inside the build tree
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>"
# these dirs are only used when linking against a prebuilt package
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
set(YACL_SOURCE_FILES "")
add_subdirectory(yacl/base)
add_subdirectory(yacl/crypto)
# add_subdirectory(yacl/engine)
add_subdirectory(yacl/io)
# add_subdirectory(yacl/kernel) add_subdirectory(yacl/link)
add_subdirectory(yacl/math)
add_subdirectory(yacl/utils)
target_sources(yacl PRIVATE ${YACL_SOURCE_FILES})
target_link_libraries(
yacl
PUBLIC Thirdparty::absl
Thirdparty::blake3
Thirdparty::cpu_features
Thirdparty::fmt
Thirdparty::fourq
Thirdparty::leveldb
Thirdparty::libsodium
Thirdparty::libtommath
Thirdparty::mcl
Thirdparty::msgpack
Thirdparty::openssl
Thirdparty::protobuf
Thirdparty::spdlog
Thirdparty::sse2neon
Thirdparty::brpc
Thirdparty::gmp)
target_link_libraries(yacl_all INTERFACE yacl)
add_library(Yacl::yacl ALIAS yacl_all)