Skip to content

Commit 2a51d22

Browse files
committed
GMP and OpenSSL are only built, when corresponding options are activated (default: deactivated) and Boost libraries are only downloaded when corresponding variable is set.
1 parent 6325d0a commit 2a51d22

27 files changed

+330
-193
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cmake_minimum_required(VERSION 3.13)
22
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
33
include(ABYCacheVariables)
4+
set(CMAKE_CXX_STANDARD 14)
45
project(ABY LANGUAGES C CXX)
56
# Write built executables and libraries to bin/ and lib/, respectively.
67
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
@@ -12,9 +13,10 @@ endif()
1213
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
1314
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
1415
endif()
16+
if(ANDROID)
17+
add_definitions(-DANDROID)
18+
endif()
1519

16-
17-
include(AddENCRYPTO_utils)
1820
add_subdirectory(src/abycore)
1921

2022
if(ABY_BUILD_EXE)

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ By *Daniel Demmler, Thomas Schneider and Michael Zohner* ([ENCRYPTO](http://www.
2020
- [Build Options](#build-options)
2121
- [Cleaning the Build Directory](#cleaning-the-build-directory)
2222
- [Installation](#installation)
23-
- [Developer Guide and Documentation](#developer-guide-and-documentation)
23+
- [Building for Android](#building-for-android)
24+
- [Developer Guide and Documentation](#developer-guide-and-documentation)
2425
- [ABY Applications](#aby-applications)
2526
- [Included Example Applications](#included-example-applications)
2627
- [Running Applications](#running-applications)
2728
- [Creating and Building your own ABY Application](#creating-and-building-your-own-aby-application)
2829

29-
3030
### Features
3131
---
3232
ABY efficiently combines secure computation schemes based on **Arithmetic sharing**, **Boolean sharing**, and **Yao’s garbled circuits** and makes available best-practice solutions in secure two-party computation.
@@ -182,12 +182,36 @@ make
182182
make install
183183
```
184184
185-
186185
#### Developer Guide and Documentation
187186
We provide an extensive [developer guide](https://www.informatik.tu-darmstadt.de/media/encrypto/encrypto_code/abydevguide.pdf) with many examples and explanations of how to use ABY.
188187
189188
Also, see the [online doxygen documentation of ABY](http://encryptogroup.github.io/ABY/docs/index.html) for further information and comments on the code.
190189
190+
## Building for Android
191+
192+
1. Clone the ABY git repository by running:
193+
```
194+
git clone https://github.com/encryptogroup/ABY.git
195+
```
196+
197+
2. Enter the Framework directory: `cd ABY/`
198+
199+
3. Create and enter the build directory: `mkdir build && cd build`
200+
201+
4. Use CMake to configure the build and setting android variables:
202+
```
203+
cmake -DANDROID_NDK=<path/to/ndk> -DANDROID_NATIVE_API_LEVEL=<TargetAPI> -DANDROID_ABI=<TargetABI> ..
204+
```
205+
where <TargetAPI> is a number between 16 and the latest Android API and <TargetABI> is the target platform (one of armeabi-v7a, arm64-v8a, x86 and x86_64 respectively).
206+
207+
Please note that when using ABY with Android Studio that <path/to/ndk> needs to be the path to the NDK used by Android Studio (often located at $HOME/Android/Sdk/ndk-bundle on Linux).
208+
209+
210+
5. Call `make` in the build directory.
211+
You can find the build executables and libraries in the directories `bin/`
212+
and `lib/`, respectively.
213+
214+
6. Call 'make install' after the build has finished. This will install the libraries into the provided NDK.
191215
192216
### ABY Applications
193217
---
@@ -234,6 +258,8 @@ Also, see the [online doxygen documentation of ABY](http://encryptogroup.github.
234258
add_executable(my_application my_application.cpp)
235259
target_link_libraries(my_application ABY::aby)
236260
```
261+
* If you are using ABY for Android in Android Studio and you encounter the "library libc++_shared.so not found" error, make sure to pass '-DANDROID_STL=c++_shared' as an argument to cmake within the gradle script. Setting ANDROID_STL within the cmake script won't work.
262+
237263
* Otherwise, setup the include path such that the headers of ABY and its
238264
dependencies can be found and link your application to the `libaby.a`
239265
library and the other dependencies (see above).

cmake/ABYConfig.cmake.in

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ include(CMakeFindDependencyMacro)
44

55
find_dependency(OTExtension)
66
find_dependency(ENCRYPTO_utils)
7-
find_dependency(MIRACL)
87
find_dependency(GMP)
98
find_dependency(Threads)
109

1110
if(NOT TARGET ABY::aby)
1211
include("${ABY_CMAKE_DIR}/ABYTargets.cmake")
1312
endif()
13+
14+
if(NOT "${ABY_LIBRARY_TYPE}" STREQUAL "STATIC" AND NOT "${ABY_LIBRARY_TYPE}" STREQUAL "SHARED")
15+
set(ABY_LIBRARY_TYPE "@ABY_LIBRARY_TYPE@")
16+
endif()
17+
set(LIB_PREFIX "${CMAKE_${ABY_LIBRARY_TYPE}_LIBRARY_PREFIX}")
18+
set(LIB_SUFFIX "${CMAKE_${ABY_LIBRARY_TYPE}_LIBRARY_SUFFIX}")
19+
20+
set(LIBRARIES_FULL_PATH "@ANDROID_NDK@/@ABY_INSTALL_LIB@/${LIB_PREFIX}aby${LIB_SUFFIX}")
21+
set(LIB_NAME "ABY")

cmake/GMPConfig.cmake.in

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
if(NOT "${GMP_LIBRARY_TYPE}" STREQUAL "STATIC" AND NOT "${GMP_LIBRARY_TYPE}" STREQUAL "SHARED")
2+
set(GMP_LIBRARY_TYPE "@GMP_LIBRARY_TYPE@")
3+
endif()
4+
set(LIB_PREFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_PREFIX}")
5+
set(LIB_SUFFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_SUFFIX}")
6+
7+
find_path(GMP_INCLUDE_DIR gmp.h PATHS "@ANDROID_NDK@/@ABY_INSTALL_INCLUDE@")
8+
9+
set(GMP_LIBRARY "@ANDROID_NDK@/@ABY_INSTALL_LIB@/${LIB_PREFIX}gmp${LIB_SUFFIX}")
10+
if(EXISTS "${GMP_INCLUDE_DIR}" AND EXISTS "${GMP_LIBRARY}")
11+
set(GMP_FOUND TRUE)
12+
else()
13+
set(GMP_LIBRARY )
14+
set(GMP_FOUND FALSE)
15+
endif()
16+
17+
if(GMP_FOUND AND NOT TARGET GMP::GMP)
18+
add_library(GMP::GMP UNKNOWN IMPORTED)
19+
set_target_properties(GMP::GMP PROPERTIES
20+
IMPORTED_LOCATION "${GMP_LIBRARY}"
21+
INTERFACE_INCLUDE_DIRECTORIES "${GMP_INCLUDE_DIR}"
22+
)
23+
endif()
24+
25+
mark_as_advanced(
26+
GMP_INCLUDE_DIR
27+
GMP_LIBRARY
28+
)
29+
30+
set(LIBRARIES_FULL_PATH "@ANDROID_NDK@/@ABY_INSTALL_LIB@/${LIB_PREFIX}gmp${LIB_SUFFIX}")
31+
set(LIB_NAME "GMP")

cmake/GMPXXConfig.cmake.in

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
if(NOT "${GMP_LIBRARY_TYPE}" STREQUAL "STATIC" AND NOT "${GMP_LIBRARY_TYPE}" STREQUAL "SHARED")
2+
set(GMP_LIBRARY_TYPE "@GMP_LIBRARY_TYPE@")
3+
endif()
4+
set(LIB_PREFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_PREFIX}")
5+
set(LIB_SUFFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_SUFFIX}")
6+
7+
find_path(GMPXX_INCLUDE_DIR gmpxx.h PATHS "@ANDROID_NDK@/@ABY_INSTALL_INCLUDE@")
8+
9+
set(GMPXX_LIBRARY "@ANDROID_NDK@/@ABY_INSTALL_LIB@/${LIB_PREFIX}gmpxx${LIB_SUFFIX}")
10+
if(EXISTS "${GMPXX_INCLUDE_DIR}" AND EXISTS "${GMPXX_LIBRARY}")
11+
set(GMPXX_FOUND TRUE)
12+
else()
13+
set(GMPXX_LIBRARY )
14+
set(GMPXX_FOUND FALSE)
15+
endif()
16+
17+
if(GMPXX_FOUND AND NOT TARGET GMP::GMPXX)
18+
add_library(GMP::GMPXX UNKNOWN IMPORTED)
19+
set_target_properties(GMP::GMPXX PROPERTIES
20+
IMPORTED_LOCATION "${GMPXX_LIBRARY}"
21+
INTERFACE_INCLUDE_DIRECTORIES "${GMPXX_INCLUDE_DIR}"
22+
)
23+
endif()
24+
25+
mark_as_advanced(
26+
GMPXX_INCLUDE_DIR
27+
GMPXX_LIBRARY
28+
)
29+
30+
set(LIBRARIES_FULL_PATH "@ANDROID_NDK@/@ABY_INSTALL_LIB@/${LIB_PREFIX}gmpxx${LIB_SUFFIX}")
31+
set(LIB_NAME "GMP")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
function(import_into_android_studio IMPORT_LOCATION)
3+
if(ANDROID AND "${${LIB_NAME}_LIBRARY_TYPE}" STREQUAL "SHARED" AND EXISTS "${IMPORT_LOCATION}")
4+
foreach(lib IN LISTS LIBRARIES_FULL_PATH)
5+
get_filename_component(lib_name "${lib}" NAME)
6+
file(COPY "${lib}" DESTINATION "${IMPORT_LOCATION}")
7+
endforeach()
8+
endif()
9+
endfunction()
10+
11+
if(NOT IMPORT_LOCATION)
12+
import_into_android_studio("${PROJECT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}")
13+
else()
14+
import_into_android_studio("${IMPORT_LOCATION}")
15+
endif()

cmake/Modules/ABYCacheVariables.cmake

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
option(ABY_BUILD_EXE "Build executables" OFF)
22
set(ABY_LIBRARY_TYPE "${ABY_LIBRARY_TYPE}" CACHE STRING
3-
"[STATIC | SHARED | MODULE] The type of library in which ABY will be built. Default: SHARED"
3+
"[STATIC | SHARED | MODULE] The type of library in which ABY will be built. Default: STATIC"
44
)
55
set_property(CACHE ABY_LIBRARY_TYPE PROPERTY STRINGS "STATIC" "SHARED" "MODULE")
66
string(TOUPPER "${ABY_LIBRARY_TYPE}" ABY_LIBRARY_TYPE)
@@ -16,11 +16,12 @@ elseif(NOT "${ABY_LIBRARY_TYPE}" STREQUAL "STATIC" AND
1616
set(ABY_LIBRARY_TYPE "SHARED")
1717
endif()
1818

19-
set(DEPENDENCY_DIR "${DEPENDENCY_DIR}" CACHE PATH
20-
"Path to directory, where dependencies will be downloaded."
21-
)
22-
if("${DEPENDENCY_DIR}" STREQUAL "" AND EXISTS "${PROJECT_SOURCE_DIR}/dependencies")
23-
set(DEPENDENCY_DIR "${PROJECT_SOURCE_DIR}/dependencies")
19+
set(DEPENDENCY_DIR "${DEPENDENCY_DIR}" CACHE PATH "Path to directory, where dependencies will be downloaded.")
20+
if(DEPENDENCY_DIR STREQUAL "")
21+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/extern/dependencies")
22+
file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/extern/dependencies")
23+
endif()
24+
set(DEPENDENCY_DIR "${CMAKE_SOURCE_DIR}/extern/dependencies")
2425
endif()
2526

2627
# Set build type to `Release` if none was specified:

cmake/Modules/AndroidCacheVariables.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ endif()
3838
if(ANDROID)
3939
set(CMAKE_TOOLCHAIN_FILE ${ANDROID_TOOLCHAIN_FILE})
4040
endif(ANDROID)
41-
if(ANDROID AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
41+
if(ANDROID AND NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
4242
set(CMAKE_INSTALL_PREFIX "${ANDROID_NDK}"
4343
CACHE PATH
4444
"Default install directory for android builds."
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
3+
function(import_shared_libs)
4+
set(DEFAULT_IMPORT_LOCATION "${PROJECT_SOURCE_DIR}/../jniLibs")
5+
if(${ARGC} LESS 1)
6+
set(IMPORT_LOCATION "${DEFAULT_IMPORT_LOCATION}")
7+
else()
8+
set(IMPORT_LOCATION "${ARGV0}")
9+
endif()
10+
if(NOT EXISTS "${IMPORT_LOCATION}")
11+
file(MAKE_DIRECTORY "${IMPORT_LOCATION}")
12+
endif()
13+
foreach(lib IN LISTS SHARED_LIBS)
14+
file(COPY "${lib}" DESTINATION "${IMPORT_LOCATION}")
15+
endforeach()
16+
endfunction()

extern/boost-cmake

Submodule boost-cmake deleted from f0f64ad

0 commit comments

Comments
 (0)