diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d8f668..7988d03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2024 Ant Group Co., Ltd. +# 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 @@ -14,17 +14,17 @@ cmake_minimum_required(VERSION 3.20) -project( - yacl +project(yacl_r VERSION 0.4.5 - DESCRIPTION - "YACL (Yet Another Common crypto library) is a C++ library that contains cryptography, network and io modules which other SecretFlow code depends on." - HOMEPAGE_URL "https://github.com/secretflow/yacl" + DESCRIPTION "YACL-r (Yet Another Crypto Library for Research)" + HOMEPAGE_URL "https://github.com/Jamie-Cui/yacl-r" LANGUAGES CXX C) -set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/") -set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) +# ------------------------------------------------------------------------------ +# Project Generic Configuration +# ------------------------------------------------------------------------------ +# Configure build type if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" @@ -34,103 +34,129 @@ if(NOT CMAKE_BUILD_TYPE) 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) -# CMake modules +# Generic CMake modules +include(AddCompilerFlags) include(CMakeDependentOption) include(CheckCXXCompilerFlag) include(CheckCXXSourceRuns) include(CheckLanguage) -include(FetchContent) include(ExternalProject) +include(GNUInstallDirs) + +# ------------------------------------------------------------------------------ +# 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 -# Always build position-independent-code -set(CMAKE_POSITION_INDEPENDENT_CODE ON) +# HACK CMAKE_ARGS should only be used in external project to reuse main +# project's cmake args +set(CMAKE_ARGS + -DCMAKE_POSITION_INDEPENDENT_CODE=On + -DCMAKE_CXX_STANDARD=17 + -DCMAKE_C_STANDARD_REQUIRED=Yes) -# Enable C++17 -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_C_STANDARD_REQUIRED YES) # set(CMAKE_EXE_LINKER_FLAGS # "${CMAKE_EXE_LINKER_FLAGS} -undefined dynamic_lookup") -include(GNUInstallDirs) -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}) -include(AddCompilerFlags) +# Additional compiler flags +add_compiler_flags("-Wall") +add_compiler_flags("-Wextra") +add_compiler_flags("-Werror") + +add_compiler_flags("-Wno-sign-compare") + +# FIXME remove this flag +add_compiler_flags("-Wno-unused-function") +add_compiler_flags("-Wno-vla") # no variable length error warning + +# 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() -# set fetch content base directory -set(FETCHCONTENT_BASE_DIR ${CMAKE_BINARY_DIR}/external_cmake) +# ------------------------------------------------------------------------------ +# External Dependencies Configuration +# ------------------------------------------------------------------------------ # prefer -pthread instead of -lpthread or -lpthreads set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads REQUIRED) -include(ExternalAbseil) -include(ExternalBlake3) -include(ExternalFmt) -include(ExternalSPDLog) -include(ExternalGTest) -include(ExternalGflags) -include(ExternalMsgpack) -include(ExternalOpenSSL) -include(ExternalLibTommath) -include(ExternalSse2neon) -include(ExternalMcl) -include(ExternalFourQ) -include(ExternalLibSodium) +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(abseil) +include(blake3) +include(fmt) +include(gtest) +include(gflags) +include(spdlog) +include(msgpack) + +# ---------------------------- +# 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) -target_include_directories( - yacl - PUBLIC - "$" # these dirs are only used - # when building inside the - # build tree - "$" # these dirs are only - # used when linking - # against a prebuilt - # version of your package -) +target_include_directories(yacl PUBLIC + # these dirs are only used when building inside the build tree + "$" + # these dirs are only used when linking against a prebuilt package + "$") -target_include_directories(yacl PUBLIC ${CMAKE_BINARY_DIR}/include) +target_include_directories(yacl PUBLIC ${CMAKE_THIRDPARTY_INCLUDEDIR}) set(YACL_SOURCE_FILES "") -add_subdirectory(yacl) +# add_subdirectory(yacl) add_subdirectory(yacl/base) -add_subdirectory(yacl/crypto) +# add_subdirectory(yacl/crypto) add_subdirectory(yacl/io) add_subdirectory(yacl/utils) -add_subdirectory(yacl/math) +# add_subdirectory(yacl/math) target_sources(yacl PRIVATE ${YACL_SOURCE_FILES}) -target_link_libraries( - yacl - PUBLIC fmt::fmt - absl::stacktrace - absl::symbolize - absl::int128 - BLAKE3::blake3 - mcl::mcl - ExtLibsodium::libsodium - ExtLibtommath::libtommath - ExtFourQ::fourq) - -if(YACL_WITH_EXT_OPENSSL) - target_link_libraries(yacl PUBLIC Extossl::Crypto Extossl::SSL) -else() - target_link_libraries(yacl PUBLIC ossl::Crypto ossl::SSL) -endif() +target_link_libraries(yacl PUBLIC + External::absl + External::fmt + External::spdlog + External::blake3 + # mcl::mcl + # ExtLibsodium::libsodium + # ExtLibtommath::libtommath + # ExtFourQ::fourq +) diff --git a/README.md b/README.md index 9026c40..78c2186 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ Yacl-r is a fork and extension of the C++ crypto library [secretflow/yacl](https://github.com/secretflow/yacl). The crypto modules in Yacl implement many state-of-art secure computation protocols, including primitives like OT, VOLE, TPRE, and tools like PRG, RO. Check the full list of Yacl's supported algorithms in [ALGORITHMS.md](ALGORITHMS.md). +> [!WARNING] +> Yacl-r is under heavy development, please use at your own risk + ## Repo Layout - [base](yacl/base/): some basic types and utils in yacl. diff --git a/cmake/AddCompilerFlags.cmake b/cmake/AddCompilerFlags.cmake index 4dd0903..7409a17 100644 --- a/cmake/AddCompilerFlags.cmake +++ b/cmake/AddCompilerFlags.cmake @@ -29,15 +29,3 @@ function(add_compiler_flags flag) endif() endfunction() -add_compiler_flags("-Wall") -add_compiler_flags("-Wextra") -add_compiler_flags("-Werror") - -# FIXME remove this flag -add_compiler_flags("-Wno-unused-function") -add_compiler_flags("-Wno-vla") # no variable length error warning - -# For cryptos -add_compiler_flags("-maes") -add_compiler_flags("-mavx") -add_compiler_flags("-mpclmul") diff --git a/cmake/ExternalFmt.cmake b/cmake/ExternalFmt.cmake deleted file mode 100644 index 2166420..0000000 --- a/cmake/ExternalFmt.cmake +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2024 Ant Group Co., Ltd. -# -# 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. - -FetchContent_Declare(fmt - URL https://github.com/fmtlib/fmt/archive/refs/tags/11.0.2.tar.gz - URL_HASH SHA256=6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f - ) - -SET(FMT_TEST OFF CACHE INTERNAL "") -FetchContent_MakeAvailable(fmt) - -include_directories(${fmt_SOURCE_DIR}/include) diff --git a/cmake/ExternalGTest.cmake b/cmake/ExternalGTest.cmake deleted file mode 100644 index cdae437..0000000 --- a/cmake/ExternalGTest.cmake +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2024 Ant Group Co., Ltd. -# -# 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. - -FetchContent_Declare(googletest - URL https://github.com/google/googletest/archive/refs/tags/v1.15.2.tar.gz - URL_HASH SHA256=7b42b4d6ed48810c5362c265a17faebe90dc2373c885e5216439d37927f02926 - ) - -FetchContent_MakeAvailable(googletest) diff --git a/cmake/ExternalGflags.cmake b/cmake/ExternalGflags.cmake deleted file mode 100644 index 49ee05f..0000000 --- a/cmake/ExternalGflags.cmake +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2024 Ant Group Co., Ltd. -# -# 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. - -FetchContent_Declare(gflags - URL https://github.com/gflags/gflags/archive/v2.2.2.tar.gz - URL_HASH SHA256=34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf - ) - -set(CMAKE_CXX_FLAGS_OLD "${CMAKE_CXX_FLAGS}") - -# Add other flags here. -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter") -set(BUILD_TESTING OFF CACHE INTERNAL "") - -FetchContent_MakeAvailable(gflags) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_OLD}") -unset(BUILD_TESTING) diff --git a/cmake/ExternalMsgpack.cmake b/cmake/ExternalMsgpack.cmake deleted file mode 100644 index 2c880d7..0000000 --- a/cmake/ExternalMsgpack.cmake +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2024 Ant Group Co., Ltd. -# -# 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. - -FetchContent_Declare(msgpack - URL https://github.com/msgpack/msgpack-c/archive/refs/tags/cpp-6.1.0.tar.gz - URL_HASH SHA256=5e63e4d9b12ab528fccf197f7e6908031039b1fc89cd8da0e97fbcbf5a6c6d3a - ) - -SET(MSGPACK_CXX17 ON CACHE INTERNAL "") -SET(MSGPACK_USE_BOOST OFF CACHE INTERNAL "") -SET(MSGPACK_BUILD_EXAMPLES OFF CACHE INTERNAL "") -SET(BUILD_SHARED_LIBS OFF CACHE INTERNAL "") -SET(MSGPACK_BUILD_TESTS OFF CACHE INTERNAL "") - -FetchContent_MakeAvailable(msgpack) - -add_definitions(-DMSGPACK_NO_BOOST) -include_directories(${msgpack_SOURCE_DIR}/include) - diff --git a/cmake/ExternalSPDLog.cmake b/cmake/ExternalSPDLog.cmake deleted file mode 100644 index 48c7626..0000000 --- a/cmake/ExternalSPDLog.cmake +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2024 Ant Group Co., Ltd. -# -# 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. - -FetchContent_Declare(spdlog - URL https://github.com/gabime/spdlog/archive/refs/tags/v1.14.1.tar.gz - URL_HASH SHA256=1586508029a7d0670dfcb2d97575dcdc242d3868a259742b69f100801ab4e16b - ) - -SET(SPDLOG_BUILD_EXAMPLE OFF CACHE INTERNAL "") -SET(SPDLOG_FMT_EXTERNAL ON CACHE INTERNAL "") -SET(SPDLOG_NO_TLS ON CACHE INTERNAL "") -SET(SPDLOG_BUILD_PIC ON CACHE INTERNAL "") - -FetchContent_MakeAvailable(spdlog) - -include_directories(${spdlog_SOURCE_DIR}/include) -add_definitions(-DSPDLOG_FMT_EXTERNAL) diff --git a/cmake/abseil.cmake b/cmake/abseil.cmake new file mode 100644 index 0000000..10bb784 --- /dev/null +++ b/cmake/abseil.cmake @@ -0,0 +1,36 @@ +# 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. + +ExternalProject_Add(abseil + URL + https://github.com/abseil/abseil-cpp/archive/refs/tags/20240722.0.tar.gz + URL_HASH + SHA256=f50e5ac311a81382da7fa75b97310e4b9006474f9560ac46f54a9967f07d4ae3 + CMAKE_ARGS ${CMAKE_ARGS} + -DCMAKE_INSTALL_PREFIX=${CMAKE_THIRDPARTY_PREFIX} + -DABSL_BUILD_MONOLITHIC_SHARED_LIBS=On + -DBUILD_SHARED_LIBS=On + PREFIX ${CMAKE_THIRDPARTY_PREFIX} + LOG_DOWNLOAD On + LOG_CONFIGURE On + LOG_BUILD On + LOG_INSTALL On) + +add_library(libabseil SHARED IMPORTED) +set_property( + TARGET libabseil PROPERTY + IMPORTED_LOCATION ${CMAKE_THIRDPARTY_LIBDIR}/libabseil_dll.dylib) +add_dependencies(libabseil abseil) + +add_library(External::absl ALIAS libabseil) diff --git a/cmake/ExternalBlake3.cmake b/cmake/blake3.cmake similarity index 53% rename from cmake/ExternalBlake3.cmake rename to cmake/blake3.cmake index c34f1dc..663d07f 100644 --- a/cmake/ExternalBlake3.cmake +++ b/cmake/blake3.cmake @@ -1,4 +1,4 @@ -# Copyright 2024 Ant Group Co., Ltd. +# 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 @@ -12,14 +12,24 @@ # License for the specific language governing permissions and limitations under # the License. -FetchContent_Declare( - blake3 - URL https://github.com/BLAKE3-team/BLAKE3/archive/refs/tags/1.5.4.tar.gz +ExternalProject_Add(blake3 + URL + https://github.com/BLAKE3-team/BLAKE3/archive/refs/tags/1.5.4.tar.gz URL_HASH SHA256=ddd24f26a31d23373e63d9be2e723263ac46c8b6d49902ab08024b573fd2a416 - SOURCE_SUBDIR c) + CMAKE_ARGS + ${CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX=${CMAKE_THIRDPARTY_PREFIX} + PREFIX ${CMAKE_THIRDPARTY_PREFIX} + SOURCE_SUBDIR c + LOG_DOWNLOAD On + LOG_CONFIGURE On + LOG_BUILD On + LOG_INSTALL On) -FetchContent_MakeAvailable(blake3) - -include_directories(${blake3_SOURCE_DIR}) +add_library(libblake3 STATIC IMPORTED) +set_property( + TARGET libblake3 PROPERTY + IMPORTED_LOCATION ${CMAKE_THIRDPARTY_LIBDIR}/libblake3.a) +add_dependencies(libblake3 blake3) +add_library(External::blake3 ALIAS libblake3) diff --git a/cmake/fmt.cmake b/cmake/fmt.cmake new file mode 100644 index 0000000..e15e8b7 --- /dev/null +++ b/cmake/fmt.cmake @@ -0,0 +1,34 @@ +# 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. + +ExternalProject_Add(fmt + URL + https://github.com/fmtlib/fmt/archive/refs/tags/11.0.2.tar.gz + URL_HASH + SHA256=6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f + CMAKE_ARGS + ${CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX=${CMAKE_THIRDPARTY_PREFIX} + PREFIX ${CMAKE_THIRDPARTY_PREFIX} + LOG_DOWNLOAD On + LOG_CONFIGURE On + LOG_BUILD On + LOG_INSTALL On) + +add_library(libfmt STATIC IMPORTED) +set_property( + TARGET libfmt PROPERTY + IMPORTED_LOCATION ${CMAKE_THIRDPARTY_LIBDIR}/libfmt.a) +add_dependencies(libfmt fmt) + +add_library(External::fmt ALIAS libfmt) diff --git a/cmake/ExternalFourQ.cmake b/cmake/fourq.cmake similarity index 97% rename from cmake/ExternalFourQ.cmake rename to cmake/fourq.cmake index 7520ded..b27b0ac 100644 --- a/cmake/ExternalFourQ.cmake +++ b/cmake/fourq.cmake @@ -1,4 +1,4 @@ -# Copyright 2024 Ant Group Co., Ltd. +# 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 @@ -34,6 +34,7 @@ ExternalProject_Add( PATCH_COMMAND patch -p1 -l --binary -i ${PROJECT_SOURCE_DIR}/bazel/patches/FourQlib.patch CONFIGURE_COMMAND "" # no configure + EXCLUDE_FROM_ALL true BUILD_COMMAND ${YACL_EXT_FOURQ_BUILD_COMMAND} INSTALL_COMMAND ${YACL_EXT_FOURQ_INSTALL_COMMAND}) diff --git a/cmake/ExternalAbseil.cmake b/cmake/gflags.cmake similarity index 52% rename from cmake/ExternalAbseil.cmake rename to cmake/gflags.cmake index 12192bf..e45c435 100644 --- a/cmake/ExternalAbseil.cmake +++ b/cmake/gflags.cmake @@ -1,4 +1,4 @@ -# Copyright 2024 Ant Group Co., Ltd. +# 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. @@ -12,14 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -FetchContent_Declare( - abseil - URL https://github.com/abseil/abseil-cpp/archive/refs/tags/20240722.0.tar.gz - URL_HASH SHA256=f50e5ac311a81382da7fa75b97310e4b9006474f9560ac46f54a9967f07d4ae3 -) - -SET(ABSL_PROPAGATE_CXX_STD ON CACHE INTERNAL "") -SET(ABSL_USE_SYSTEM_INCLUDES ON CACHE INTERNAL "") -FetchContent_MakeAvailable(abseil) - -include_directories(${abseil_SOURCE_DIR}) +ExternalProject_Add(gflags + URL + https://github.com/gflags/gflags/archive/v2.2.2.tar.gz + URL_HASH + SHA256=34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf + CMAKE_ARGS ${CMAKE_ARGS} + -DCMAKE_INSTALL_PREFIX=${CMAKE_THIRDPARTY_PREFIX} + -DSPDLOG_FMT_EXTERNAL=On + -DCMAKE_CXX_FLAGS=-isystem\ ${CMAKE_THIRDPARTY_INCLUDEDIR} + PREFIX ${CMAKE_THIRDPARTY_PREFIX} + LOG_DOWNLOAD On + LOG_CONFIGURE On + LOG_BUILD On + LOG_INSTALL On) diff --git a/cmake/gtest.cmake b/cmake/gtest.cmake new file mode 100644 index 0000000..7581d6f --- /dev/null +++ b/cmake/gtest.cmake @@ -0,0 +1,41 @@ +# 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. + +ExternalProject_Add(googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.15.2.tar.gz + URL_HASH SHA256=7b42b4d6ed48810c5362c265a17faebe90dc2373c885e5216439d37927f02926 + CMAKE_ARGS + ${CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX=${CMAKE_THIRDPARTY_PREFIX} -DBUILD_GMOCK=Off + PREFIX ${CMAKE_THIRDPARTY_PREFIX} + LOG_DOWNLOAD On + LOG_CONFIGURE On + LOG_BUILD On + LOG_INSTALL On) + +add_library(libgtest STATIC IMPORTED) +set_property( + TARGET libgtest PROPERTY + IMPORTED_LOCATION ${CMAKE_THIRDPARTY_LIBDIR}/libgtest.a) +add_dependencies(libgtest googletest) + +add_library(libgtest_main STATIC IMPORTED) +set_property( + TARGET libgtest_main PROPERTY + IMPORTED_LOCATION ${CMAKE_THIRDPARTY_LIBDIR}/libgtest_main.a) +add_dependencies(libgtest_main googletest) + +add_library(libgtest_interface INTERFACE) +target_link_libraries(libgtest_interface + INTERFACE libgtest_main libgtest) +add_library(External::gtest ALIAS libgtest_interface) diff --git a/cmake/ExternalLibSodium.cmake b/cmake/libsodium.cmake similarity index 96% rename from cmake/ExternalLibSodium.cmake rename to cmake/libsodium.cmake index c11b24e..6e80b7b 100644 --- a/cmake/ExternalLibSodium.cmake +++ b/cmake/libsodium.cmake @@ -20,6 +20,8 @@ ExternalProject_Add( URL_HASH SHA256=6f504490b342a4f8a4c4a02fc9b866cbef8622d5df4e5452b46be121e46636c1 BUILD_IN_SOURCE true + DOWNLOAD_NO_PROGRESS true + EXCLUDE_FROM_ALL true CONFIGURE_COMMAND ./configure --prefix=${CMAKE_BINARY_DIR} BUILD_COMMAND make INSTALL_COMMAND make install diff --git a/cmake/ExternalLibTommath.cmake b/cmake/libtommath.cmake similarity index 94% rename from cmake/ExternalLibTommath.cmake rename to cmake/libtommath.cmake index ec876d7..a7e50d4 100644 --- a/cmake/ExternalLibTommath.cmake +++ b/cmake/libtommath.cmake @@ -19,6 +19,9 @@ ExternalProject_Add( URL https://github.com/libtom/libtommath/archive/42b3fb07e7d504f61a04c7fca12e996d76a25251.tar.gz URL_HASH SHA256=7cfbdb64431129de4257e7d3349200fdbd4f229b470ff3417b30d0f39beed41f + BUILD_IN_SOURCE true + DOWNLOAD_NO_PROGRESS true + EXCLUDE_FROM_ALL true INSTALL_COMMAND cmake --install . --prefix ${CMAKE_BINARY_DIR} EXCLUDE_FROM_ALL) diff --git a/cmake/ExternalMcl.cmake b/cmake/mcl.cmake similarity index 95% rename from cmake/ExternalMcl.cmake rename to cmake/mcl.cmake index e444c85..0964f03 100644 --- a/cmake/ExternalMcl.cmake +++ b/cmake/mcl.cmake @@ -16,7 +16,9 @@ FetchContent_Declare( mcl URL https://github.com/herumi/mcl/archive/refs/tags/v1.99.tar.gz URL_HASH - SHA256=5ff9702c1f1b021925d1334ca0a03c87783174075aeaf87801842d3c08b3d39e) + SHA256=5ff9702c1f1b021925d1334ca0a03c87783174075aeaf87801842d3c08b3d39e + EXCLUDE_FROM_ALL) + FetchContent_MakeAvailable(mcl) diff --git a/cmake/msgpack.cmake b/cmake/msgpack.cmake new file mode 100644 index 0000000..b65311b --- /dev/null +++ b/cmake/msgpack.cmake @@ -0,0 +1,37 @@ +# Copyright 2024 Ant Group Co., Ltd. +# +# 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. + +ExternalProject_Add(msgpack + URL + https://github.com/msgpack/msgpack-c/archive/refs/tags/cpp-6.1.0.tar.gz + URL_HASH + SHA256=5e63e4d9b12ab528fccf197f7e6908031039b1fc89cd8da0e97fbcbf5a6c6d3a + CMAKE_ARGS ${CMAKE_ARGS} + -DCMAKE_INSTALL_PREFIX=${CMAKE_THIRDPARTY_PREFIX} + -DMSGPACK_CXX17=On + -DMSGPACK_USE_BOOST=Off + -DMSGPACK_BUILD_EXAMPLES=Off + -DMSGPACK_BUILD_EXAMPLES=Off + -DBUILD_SHARED_LIBS=Off + -DMSGPACK_BUILD_TESTS=Off + PREFIX ${CMAKE_THIRDPARTY_PREFIX} + LOG_DOWNLOAD On + LOG_CONFIGURE On + LOG_BUILD On + LOG_INSTALL On) + +# msgpack is header-only, therefore no need to link + +# HACK +add_compile_definitions(MSGPACK_NO_BOOST) diff --git a/cmake/ExternalOpenSSL.cmake b/cmake/openssl.cmake similarity index 98% rename from cmake/ExternalOpenSSL.cmake rename to cmake/openssl.cmake index a7fc751..69cc99a 100644 --- a/cmake/ExternalOpenSSL.cmake +++ b/cmake/openssl.cmake @@ -47,7 +47,7 @@ if(YACL_WITH_EXT_OPENSSL) -w BUILD_COMMAND make -j4 build_sw INSTALL_COMMAND make install_sw - EXCLUDE_FROM_ALL) + EXCLUDE_FROM_ALL true) add_library(ExtOpenSSL_Crypto STATIC IMPORTED) set_target_properties( diff --git a/cmake/spdlog.cmake b/cmake/spdlog.cmake new file mode 100644 index 0000000..350b055 --- /dev/null +++ b/cmake/spdlog.cmake @@ -0,0 +1,41 @@ +# Copyright 2024 Ant Group Co., Ltd. +# +# 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. + +ExternalProject_Add(spdlog + URL + https://github.com/gabime/spdlog/archive/refs/tags/v1.14.1.tar.gz + URL_HASH + SHA256=1586508029a7d0670dfcb2d97575dcdc242d3868a259742b69f100801ab4e16b + CMAKE_ARGS ${CMAKE_ARGS} + -DCMAKE_INSTALL_PREFIX=${CMAKE_THIRDPARTY_PREFIX} + -DSPDLOG_FMT_EXTERNAL=On + -DCMAKE_CXX_FLAGS=-isystem\ ${CMAKE_THIRDPARTY_INCLUDEDIR} + PREFIX ${CMAKE_THIRDPARTY_PREFIX} + LOG_DOWNLOAD On + LOG_CONFIGURE On + LOG_BUILD On + LOG_INSTALL On) + +add_dependencies(spdlog fmt) + +add_library(libspdlog STATIC IMPORTED) +set_property( + TARGET libspdlog PROPERTY + IMPORTED_LOCATION ${CMAKE_THIRDPARTY_LIBDIR}/libspdlog.a) +add_dependencies(libspdlog spdlog) + +add_library(External::spdlog ALIAS libspdlog) + +# HACK https://github.com/gabime/spdlog/issues/1897 +add_compile_definitions(SPDLOG_FMT_EXTERNAL) diff --git a/cmake/ExternalSse2neon.cmake b/cmake/sse2neon.cmake similarity index 97% rename from cmake/ExternalSse2neon.cmake rename to cmake/sse2neon.cmake index 3b499d2..6f27b36 100644 --- a/cmake/ExternalSse2neon.cmake +++ b/cmake/sse2neon.cmake @@ -20,6 +20,7 @@ ExternalProject_Add( SHA256=787e0a7a64f1461b48232a7f9b9e9c14fa4a35a30875f2fb91aec6ddeaddfc0f BUILD_IN_SOURCE true CONFIGURE_COMMAND "" + EXCLUDE_FROM_ALL true INSTALL_COMMAND "") ExternalProject_Get_Property(sse2neon SOURCE_DIR) diff --git a/yacl/base/CMakeLists.txt b/yacl/base/CMakeLists.txt index a80cbed..2c6efc9 100644 --- a/yacl/base/CMakeLists.txt +++ b/yacl/base/CMakeLists.txt @@ -34,11 +34,9 @@ set(YACL_SOURCE_FILES PARENT_SCOPE) add_executable(buffer_test buffer_test.cc) -target_link_libraries(buffer_test PRIVATE yacl gtest_main) -target_link_options(buffer_test PRIVATE "-all_load") # for spi +target_link_libraries(buffer_test PRIVATE yacl External::gtest) add_test(NAME buffer_test COMMAND buffer_test) add_executable(secparam_test secparam_test.cc) -target_link_libraries(secparam_test PRIVATE yacl gtest_main) -target_link_options(secparam_test PRIVATE "-all_load") # for spi +target_link_libraries(secparam_test PRIVATE yacl External::gtest) add_test(NAME secparam_test COMMAND secparam_test) diff --git a/yacl/io/msgpack/CMakeLists.txt b/yacl/io/msgpack/CMakeLists.txt index 7dc7c53..fbb326c 100644 --- a/yacl/io/msgpack/CMakeLists.txt +++ b/yacl/io/msgpack/CMakeLists.txt @@ -28,5 +28,5 @@ install( set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} PARENT_SCOPE) add_executable(msgpack_buffer_test buffer_test.cc) -target_link_libraries(msgpack_buffer_test PRIVATE yacl gtest_main) +target_link_libraries(msgpack_buffer_test PRIVATE yacl External::gtest) add_test(NAME msgpack_buffer_test COMMAND msgpack_buffer_test) diff --git a/yacl/io/rw/CMakeLists.txt b/yacl/io/rw/CMakeLists.txt index a2e718a..e12a36e 100644 --- a/yacl/io/rw/CMakeLists.txt +++ b/yacl/io/rw/CMakeLists.txt @@ -33,6 +33,6 @@ install( set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} PARENT_SCOPE) -add_executable(rw_test rw_test.cc) -target_link_libraries(rw_test PRIVATE yacl gtest_main gflags) -add_test(NAME rw_test COMMAND rw_test WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) +# add_executable(rw_test rw_test.cc) +# target_link_libraries(rw_test PRIVATE yacl gtest_main gflags) +# add_test(NAME rw_test COMMAND rw_test WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) diff --git a/yacl/io/stream/CMakeLists.txt b/yacl/io/stream/CMakeLists.txt index 5055d51..55af0b1 100644 --- a/yacl/io/stream/CMakeLists.txt +++ b/yacl/io/stream/CMakeLists.txt @@ -30,5 +30,5 @@ install( set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} PARENT_SCOPE) add_executable(io_stream_test test.cc) -target_link_libraries(io_stream_test PRIVATE yacl gtest_main) +target_link_libraries(io_stream_test PRIVATE yacl External::gtest) add_test(NAME io_stream_test COMMAND io_stream_test) diff --git a/yacl/utils/CMakeLists.txt b/yacl/utils/CMakeLists.txt index dda4c53..9f50184 100644 --- a/yacl/utils/CMakeLists.txt +++ b/yacl/utils/CMakeLists.txt @@ -28,10 +28,10 @@ install( ${CMAKE_INSTALL_INCLUDEDIR}/yacl/utils ) -add_subdirectory(spi) +# add_subdirectory(spi) set(YACL_SOURCE_FILES ${YACL_SOURCE_FILES} PARENT_SCOPE) add_executable(parallel_test parallel_test.cc) -target_link_libraries(parallel_test PRIVATE yacl gtest_main) +target_link_libraries(parallel_test PRIVATE yacl External::gtest) add_test(NAME parallel_test COMMAND parallel_test)