Skip to content

Commit

Permalink
chore(build): more fixes on cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie-Cui committed Dec 26, 2024
1 parent aff79f5 commit a88eb1f
Show file tree
Hide file tree
Showing 18 changed files with 527 additions and 38 deletions.
23 changes: 18 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ endif()
# 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
Expand All @@ -115,6 +116,7 @@ set(CMAKE_THIRDPARTY_INCLUDEDIR

include(tp_abseil)
include(tp_blake3)
include(tp_cpu_features)
include(tp_fmt)
include(tp_fourq)
include(tp_gtest)
Expand All @@ -131,6 +133,8 @@ include(tp_sse2neon)
# Project Target Configuration
# ----------------------------

include(yacl_custom_def)

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})
Expand All @@ -145,13 +149,16 @@ target_include_directories(yacl PUBLIC
# these dirs are only used when linking against a prebuilt package
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")

target_include_directories(yacl PUBLIC ${CMAKE_THIRDPARTY_INCLUDEDIR})
target_include_directories(yacl PUBLIC
${CMAKE_THIRDPARTY_INCLUDEDIR}
${GMP_INCLUDE_DIR}
)

set(YACL_SOURCE_FILES "")

add_subdirectory(yacl/base)
add_subdirectory(yacl/crypto)
add_subdirectory(yacl/io)
# add_subdirectory(yacl/crypto)
# add_subdirectory(yacl/io)
add_subdirectory(yacl/utils)
add_subdirectory(yacl/math)

Expand All @@ -160,10 +167,16 @@ target_sources(yacl PRIVATE ${YACL_SOURCE_FILES})
target_link_libraries(yacl PUBLIC
Thirdparty::absl
Thirdparty::blake3
Thirdparty::cpu_features
Thirdparty::fmt
Thirdparty::fourq
Thirdparty::spdlog
Thirdparty::gflags
Thirdparty::libsodium
Thirdparty::libtommath
Thirdparty::mcl
Thirdparty::msgpack
Thirdparty::openssl
Thirdparty::spdlog
Thirdparty::sse2neon
Thirdparty::mcl)
${GMP_LIBRARIES}
)
67 changes: 67 additions & 0 deletions cmake/FindGMP.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (c) 2006, Laurent Montel, <[email protected]>
# Copyright (c) 2007, Francesco Biscani, <[email protected]>

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ------------------------------------------------------------------------------------------

# Try to find the GMP libraries:
# GMP_FOUND - System has GMP lib
# GMP_INCLUDE_DIR - The GMP include directory
# GMP_LIBRARIES - Libraries needed to use GMP

if (GMP_INCLUDE_DIR AND GMP_LIBRARIES)
# Force search at every time, in case configuration changes
unset(GMP_INCLUDE_DIR CACHE)
unset(GMP_LIBRARIES CACHE)
endif (GMP_INCLUDE_DIR AND GMP_LIBRARIES)

find_path(GMP_INCLUDE_DIR gmp.h
PATHS
ENV GMP_ROOT
ENV GMP_INCLUDE_DIR
${GMP_ROOT}
/usr
/usr/local
$ENV{HOME}/.local
PATH_SUFFIXES
include
)

if(STBIN)
find_library(GMP_LIBRARIES NAMES libgmp.a libgmp.dll.a gmp.lib libgmp-10 libgmp gmp)
else(STBIN)
find_library(GMP_LIBRARIES NAMES libgmp.so libgmp.dll.so gmp.lib libgmp-10 libgmp gmp)
endif(STBIN)

if(GMP_INCLUDE_DIR AND GMP_LIBRARIES)
set(GMP_FOUND TRUE)
endif()

if(GMP_FOUND)
message(STATUS "Configured GMP: -I${GMP_INCLUDE_DIR} -L${GMP_LIBRARIES}")
else(GMP_FOUND)
message(STATUS "Could NOT find GMP!")
endif(GMP_FOUND)

mark_as_advanced(GMP_INCLUDE_DIR GMP_LIBRARIES)
3 changes: 1 addition & 2 deletions cmake/tp_libsodium.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ libsodium-1.0.18.tar.gz"
LOG_BUILD On
LOG_INSTALL On)


add_library(liblibsodium STATIC IMPORTED)
set_target_properties(
liblibsodium PROPERTIES
IMPORTED_LOCATION
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX})
${CMAKE_THIRDPARTY_LIBDIR}/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX})
add_dependencies(liblibsodium libsodium)

# -----------------------------
Expand Down
19 changes: 19 additions & 0 deletions cmake/yacl_custom_def.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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.

macro(add_yacl_test NAME)
add_executable(${NAME} ${NAME}.cc)
target_link_libraries(${NAME} PRIVATE yacl Thirdparty::gtest)
add_test(NAME ${NAME} COMMAND ${NAME})
endmacro()
9 changes: 2 additions & 7 deletions yacl/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,5 @@ set(YACL_SOURCE_FILES
${YACL_SOURCE_FILES}
PARENT_SCOPE)

add_executable(buffer_test buffer_test.cc)
target_link_libraries(buffer_test PRIVATE yacl Thirdparty::gtest)
add_test(NAME buffer_test COMMAND buffer_test)

add_executable(secparam_test secparam_test.cc)
target_link_libraries(secparam_test PRIVATE yacl Thirdparty::gtest)
add_test(NAME secparam_test COMMAND secparam_test)
add_yacl_test(buffer_test)
add_yacl_test(secparam_test)
2 changes: 1 addition & 1 deletion yacl/base/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// pclmul
#include <wmmintrin.h>
#else
#include "sse2neon.h"
#include "sse2neon/sse2neon.h"
#endif

// block code from
Expand Down
2 changes: 1 addition & 1 deletion yacl/crypto/tools/crhash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// pclmul
#include <wmmintrin.h>
#else
#include "sse2neon.h"
#include "sse2neon/sse2neon.h"
#endif

namespace yacl::crypto {
Expand Down
2 changes: 1 addition & 1 deletion yacl/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ install(FILES ${CMAKE_CURRENT_LIST_DIR}/gadget.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yacl/crypto/math)

add_subdirectory(galois_field)
# add_subdirectory(mpint)
add_subdirectory(mpint)

set(YACL_SOURCE_FILES
${YACL_SOURCE_FILES}
Expand Down
4 changes: 2 additions & 2 deletions yacl/math/galois_field/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ set(YACL_SOURCE_FILES
PARENT_SCOPE)

add_executable(gf_test gf_test.cc)
target_link_libraries(gf_test PRIVATE yacl gtest_main)
target_link_libraries(gf_test PRIVATE yacl Thirdparty::gtest)
target_link_options(gf_test PRIVATE "-all_load") # for spi
add_test(NAME gf_test COMMAND gf_test)

add_executable(gf_intrinsic_test gf_intrinsic_test.cc)
target_link_libraries(gf_intrinsic_test PRIVATE yacl gtest_main)
target_link_libraries(gf_intrinsic_test PRIVATE yacl Thirdparty::gtest)
target_link_options(gf_intrinsic_test PRIVATE "-all_load") # for spi
add_test(NAME gf_intrinsic_test COMMAND gf_intrinsic_test)
6 changes: 3 additions & 3 deletions yacl/math/galois_field/factory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ set(YACL_SOURCE_FILES
PARENT_SCOPE)

add_executable(mcl_factory_test mcl_factory_test.cc)
target_link_libraries(mcl_factory_test PRIVATE yacl gtest_main)
target_link_libraries(mcl_factory_test PRIVATE yacl Thirdparty::gtest)
target_link_options(mcl_factory_test PRIVATE "-all_load") # for spi
add_test(NAME mcl_factory_test COMMAND mcl_factory_test)

add_executable(mpint_factory_test mpint_factory_test.cc)
target_link_libraries(mpint_factory_test PRIVATE yacl gtest_main)
target_link_libraries(mpint_factory_test PRIVATE yacl Thirdparty::gtest)
target_link_options(mpint_factory_test PRIVATE "-all_load") # for spi
add_test(NAME mpint_factory_test COMMAND mpint_factory_test)

add_executable(intel_factory_test intel_factory_test.cc)
target_link_libraries(intel_factory_test PRIVATE yacl gtest_main)
target_link_libraries(intel_factory_test PRIVATE yacl Thirdparty::gtest)
target_link_options(intel_factory_test PRIVATE "-all_load") # for spi
add_link_options("-lc++") # for spi
add_test(NAME intel_factory_test COMMAND intel_factory_test)
2 changes: 1 addition & 1 deletion yacl/math/galois_field/factory/intel_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// pclmul
#include <wmmintrin.h>
#else
#include "sse2neon.h"
#include "sse2neon/sse2neon.h"
#endif

namespace yacl::math {
Expand Down
6 changes: 3 additions & 3 deletions yacl/math/mpint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ set(YACL_SOURCE_FILES
PARENT_SCOPE)

add_executable(montgomery_math_test montgomery_math_test.cc)
target_link_libraries(montgomery_math_test PRIVATE yacl gtest_main)
target_link_libraries(montgomery_math_test PRIVATE yacl Thirdparty::gtest)
target_link_options(montgomery_math_test PRIVATE "-all_load") # for spi
add_test(NAME montgomery_math_test COMMAND montgomery_math_test)

add_executable(mp_int_test mp_int_test.cc)
target_link_libraries(mp_int_test PRIVATE yacl gtest_main)
target_link_libraries(mp_int_test PRIVATE yacl Thirdparty::gtest)
target_link_options(mp_int_test PRIVATE "-all_load") # for spi
add_test(NAME mp_int_test COMMAND mp_int_test)

add_executable(tommath_ext_test tommath_ext_test.cc)
target_link_libraries(tommath_ext_test PRIVATE yacl gtest_main)
target_link_libraries(tommath_ext_test PRIVATE yacl Thirdparty::gtest)
target_link_options(tommath_ext_test PRIVATE "-all_load") # for spi
add_test(NAME tommath_ext_test COMMAND tommath_ext_test)

Expand Down
1 change: 1 addition & 0 deletions yacl/math/mpint/mp_int.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "yacl/math/mpint/tommath_ext_features.h"
#include "yacl/math/mpint/tommath_ext_types.h"
#include "yacl/math/mpint/mp_int_private.h"

// extern "C" {
// #include "libtommath/tommath_private.h"
Expand Down
Loading

0 comments on commit a88eb1f

Please sign in to comment.