Skip to content

Commit

Permalink
add CMake build for the ABY library and examples
Browse files Browse the repository at this point in the history
* Defines libaby target in src/abycore.  This allows to make clean only
abycore (without the dependencies).
* Build artifacts are put into bin/, lib/ inside the build directory.
* Use Release as default build type.
  • Loading branch information
lenerd committed Jul 17, 2018
1 parent 7f0a2f3 commit 6c45132
Show file tree
Hide file tree
Showing 36 changed files with 263 additions and 296 deletions.
58 changes: 58 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
cmake_minimum_required(VERSION 3.10)
project(ABY LANGUAGES CXX)

option(ABY_BUILD_EXE "Build executables" OFF)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

# Set build type to `Release` if non was specified:
# (cf. https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-can-i-change-the-default-build-mode-and-see-it-reflected-in-the-gui)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif(NOT CMAKE_BUILD_TYPE)

# Write built executables and libraries to bin/ and lib/, respectively.
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
endif()

find_package(ENCRYPTO_utils QUIET)
if(ENCRYPTO_utils_FOUND)
message(STATUS "Found ENCRYPTO_utils")
elseif(NOT ENCRYPTO_utils_FOUND AND NOT TARGET ENCRYPTO_utils::encrypto_utils)
message("ENCRYPTO_utils was not found: add ENCRYPTO_utils subdirectory")
find_package(Git REQUIRED)
execute_process(COMMAND git submodule update --init extern/ENCRYPTO_utils
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_subdirectory(extern/ENCRYPTO_utils)
endif()

find_package(OTExtension QUIET)
if(OTExtension_FOUND)
message(STATUS "Found OTExtension")
elseif (NOT OTExtension_FOUND AND NOT TARGET OTExtension::otextension)
message("OTExtension was not found: add OTExtension subdirectory")
find_package(Git REQUIRED)
execute_process(COMMAND git submodule update --init extern/OTExtension
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_subdirectory(extern/OTExtension)
endif()

find_package(GMP REQUIRED)
find_package(Threads REQUIRED)

add_subdirectory(src/abycore)


if(ABY_BUILD_EXE)
add_subdirectory(src/test)
add_subdirectory(src/examples)
endif(ABY_BUILD_EXE)
46 changes: 0 additions & 46 deletions Example_Makefile

This file was deleted.

111 changes: 0 additions & 111 deletions Makefile

This file was deleted.

15 changes: 15 additions & 0 deletions cmake/ABYConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
get_filename_component(ABY_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

list(APPEND CMAKE_MODULE_PATH "${ABY_CMAKE_DIR}")

include(CMakeFindDependencyMacro)

find_dependency(OTExtension)
find_dependency(ENCRYPTO_utils)
find_dependency(MIRACL)
find_dependency(GMP)
find_dependency(Threads)

if(NOT TARGET ABY::aby)
include("${ABY_CMAKE_DIR}/ABYTargets.cmake")
endif()
27 changes: 27 additions & 0 deletions cmake/FindGMP.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

find_path(GMP_INCLUDE_DIR gmp.h)

# TODO: get version

find_library(GMP_LIBRARY NAMES gmp)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GMP
FOUND_VAR GMP_FOUND
REQUIRED_VARS
GMP_LIBRARY
GMP_INCLUDE_DIR
)

if(GMP_FOUND AND NOT TARGET GMP::GMP)
add_library(GMP::GMP UNKNOWN IMPORTED)
set_target_properties(GMP::GMP PROPERTIES
IMPORTED_LOCATION "${GMP_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${GMP_INCLUDE_DIR}"
)
endif()

mark_as_advanced(
GMP_INCLUDE_DIR
GMP_LIBRARY
)
27 changes: 27 additions & 0 deletions cmake/FindGMPXX.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

find_path(GMPXX_INCLUDE_DIR gmpxx.h)

# TODO: get version

find_library(GMPXX_LIBRARY NAMES gmpxx)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GMPXX
FOUND_VAR GMPXX_FOUND
REQUIRED_VARS
GMPXX_LIBRARY
GMPXX_INCLUDE_DIR
)

if(GMPXX_FOUND AND NOT TARGET GMP::GMPXX)
add_library(GMP::GMPXX UNKNOWN IMPORTED)
set_target_properties(GMP::GMPXX PROPERTIES
IMPORTED_LOCATION "${GMPXX_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${GMPXX_INCLUDE_DIR}"
)
endif()

mark_as_advanced(
GMPXX_INCLUDE_DIR
GMPXX_LIBRARY
)
4 changes: 2 additions & 2 deletions runtest_scr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exitfn () {

trap "exitfn" INT # Set up SIGINT trap to call function.

./bin/test-aby.exe -r 0 -R &
./bin/abytest -r 0 -R &
CLIENT_PID=$!
./bin/test-aby.exe -r 1 -R
./bin/abytest -r 1 -R

66 changes: 66 additions & 0 deletions src/abycore/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
add_library(aby
aby/abyparty.cpp
aby/abysetup.cpp
circuit/abycircuit.cpp
circuit/arithmeticcircuits.cpp
circuit/booleancircuits.cpp
circuit/circuit.cpp
circuit/share.cpp
DGK/dgkparty.cpp
DJN/djnparty.cpp
sharing/arithsharing.cpp
sharing/boolsharing.cpp
sharing/sharing.cpp
sharing/splut.cpp
sharing/yaoclientsharing.cpp
sharing/yaoserversharing.cpp
sharing/yaosharing.cpp
)
add_library(ABY::aby ALIAS aby)

target_compile_features(aby PUBLIC cxx_std_17)
target_compile_options(aby PRIVATE "-Wall" "-Wextra" "-Weffc++")

target_include_directories(aby
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
)


target_link_libraries(aby
PUBLIC OTExtension::otextension
PUBLIC ENCRYPTO_utils::encrypto_utils
PUBLIC GMP::GMP
PUBLIC Threads::Threads
)


install(TARGETS aby
EXPORT "${PROJECT_NAME}Targets"
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
INCLUDES DESTINATION lib
)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DESTINATION include
FILES_MATCHING PATTERN "*.h"
)

export(TARGETS aby NAMESPACE "${PROJECT_NAME}::" FILE "${PROJECT_NAME}Targets.cmake")
install(EXPORT "${PROJECT_NAME}Targets"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "lib/cmake/${PROJECT_NAME}"
)

include(CMakePackageConfigHelpers)

configure_package_config_file("${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION "lib/cmake/${PROJECT_NAME}"
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION "lib/cmake/${PROJECT_NAME}"
)
14 changes: 7 additions & 7 deletions src/abycore/aby/abysetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
#include <ENCRYPTO_utils/typedefs.h>
#include <ENCRYPTO_utils/crypto/crypto.h>
#include "../ABY_utils/ABYconstants.h"
#include "../ot/naor-pinkas.h"
#include "../ot/ot-ext.h"
#include "../ot/xormasking.h"
#include <ot/naor-pinkas.h>
#include <ot/ot-ext.h>
#include <ot/xormasking.h>
#include "../ot/arithmtmasking.h"
#include "../ot/iknp-ot-ext-snd.h"
#include "../ot/iknp-ot-ext-rec.h"
#include "../ot/kk-ot-ext-snd.h"
#include "../ot/kk-ot-ext-rec.h"
#include <ot/iknp-ot-ext-snd.h>
#include <ot/iknp-ot-ext-rec.h>
#include <ot/kk-ot-ext-snd.h>
#include <ot/kk-ot-ext-rec.h>
#include "../DJN/djnparty.h"
#include "../DGK/dgkparty.h"
#include <ENCRYPTO_utils/constants.h>
Expand Down
Loading

0 comments on commit 6c45132

Please sign in to comment.