Skip to content

Commit 36d7aef

Browse files
committed
Added cross-compilation support for Android.
1 parent bae46a0 commit 36d7aef

34 files changed

Lines changed: 1105 additions & 160 deletions

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
README.html
1212
docs/*
1313
*.dump
14-
14+
*.bak
1515

1616
# build directory
1717
build*/
18+
# extern directory
19+
extern/*
1820

1921
# CMake
2022
CMakeCache.txt

.gitmodules

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "extern/ENCRYPTO_utils"]
2-
path = extern/ENCRYPTO_utils
3-
url = https://github.com/encryptogroup/ENCRYPTO_utils.git
4-
[submodule "extern/OTExtension"]
5-
path = extern/OTExtension
6-
url = https://github.com/encryptogroup/OTExtension.git
1+
[submodule "extern/boost-cmake"]
2+
path = extern/boost-cmake
3+
url = https://github.com/Orphis/boost-cmake.git

CMakeLists.txt

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
1-
cmake_minimum_required(VERSION 3.12)
2-
project(ABY LANGUAGES CXX)
3-
4-
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
5-
message(FATAL_ERROR "ABY requires at least g++-8")
6-
endif()
7-
8-
option(ABY_BUILD_EXE "Build executables" OFF)
9-
10-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
11-
12-
# Set build type to `Release` if non was specified:
13-
# (cf. https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-can-i-change-the-default-build-mode-and-see-it-reflected-in-the-gui)
14-
if(NOT CMAKE_BUILD_TYPE)
15-
set(CMAKE_BUILD_TYPE Release CACHE STRING
16-
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
17-
FORCE)
18-
endif(NOT CMAKE_BUILD_TYPE)
19-
1+
cmake_minimum_required(VERSION 3.13)
2+
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
3+
include(ABYCacheVariables)
4+
set(CMAKE_CXX_STANDARD 14)
5+
project(ABY LANGUAGES C CXX)
206
# Write built executables and libraries to bin/ and lib/, respectively.
217
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
228
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
@@ -27,43 +13,14 @@ endif()
2713
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
2814
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
2915
endif()
30-
31-
find_package(ENCRYPTO_utils QUIET)
32-
if(ENCRYPTO_utils_FOUND)
33-
message(STATUS "Found ENCRYPTO_utils")
34-
elseif(NOT ENCRYPTO_utils_FOUND AND NOT TARGET ENCRYPTO_utils::encrypto_utils)
35-
message("ENCRYPTO_utils was not found: add ENCRYPTO_utils subdirectory")
36-
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/ENCRYPTO_utils/CMakeLists.txt")
37-
find_package(Git REQUIRED)
38-
message("initialize Git submodule: extern/ENCRYPTO_utils")
39-
execute_process(COMMAND git submodule update --init extern/ENCRYPTO_utils
40-
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
41-
endif()
42-
add_subdirectory(extern/ENCRYPTO_utils)
43-
endif()
44-
45-
find_package(OTExtension QUIET)
46-
if(OTExtension_FOUND)
47-
message(STATUS "Found OTExtension")
48-
elseif (NOT OTExtension_FOUND AND NOT TARGET OTExtension::otextension)
49-
message("OTExtension was not found: add OTExtension subdirectory")
50-
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/OTExtension/CMakeLists.txt")
51-
find_package(Git REQUIRED)
52-
message("initialize Git submodule: extern/OTExtension")
53-
execute_process(COMMAND git submodule update --init extern/OTExtension
54-
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
55-
endif()
56-
add_subdirectory(extern/OTExtension)
16+
if(ANDROID)
17+
add_definitions(-DANDROID)
5718
endif()
5819

59-
find_package(GMP REQUIRED)
60-
find_package(Threads REQUIRED)
61-
find_package(Boost 1.66.0 REQUIRED COMPONENTS thread system)
62-
6320
add_subdirectory(src/abycore)
6421

65-
6622
if(ABY_BUILD_EXE)
6723
add_subdirectory(src/test)
6824
add_subdirectory(src/examples)
6925
endif(ABY_BUILD_EXE)
26+

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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
get_filename_component(ABY_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
22

3-
list(APPEND CMAKE_MODULE_PATH "${ABY_CMAKE_DIR}")
4-
53
include(CMakeFindDependencyMacro)
64

5+
find_dependency(Boost)
76
find_dependency(OTExtension)
87
find_dependency(ENCRYPTO_utils)
9-
find_dependency(MIRACL)
108
find_dependency(GMP)
119
find_dependency(Threads)
1210

1311
if(NOT TARGET ABY::aby)
1412
include("${ABY_CMAKE_DIR}/ABYTargets.cmake")
1513
endif()
14+
15+
if(TARGET ABY::aby)
16+
set(ABY_FOUND TRUE)
17+
set(TARGETS ABY::aby)
18+
endif()
19+
20+

cmake/BoostConfig.cmake.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
get_filename_component(Boost_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
2+
3+
if(NOT TARGET Boost::boost)
4+
include("${Boost_CMAKE_DIR}/BoostTargets.cmake")
5+
endif()

cmake/FindGMP.cmake

Lines changed: 0 additions & 27 deletions
This file was deleted.

cmake/FindGMPXX.cmake

Lines changed: 0 additions & 27 deletions
This file was deleted.

cmake/ForwardConfig.cmake.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
include(CMakeFindDependencyMacro)
2+
set(INSTALL_NAME "@INSTALL_NAME@")
3+
if(ANDROID AND ANDROID_ARM_NEON)
4+
set(PREFIX "${INSTALL_NAME}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI}-NEON")
5+
elseif(ANDROID AND NOT ANDROID_ARM_NEON)
6+
set(PREFIX "${INSTALL_NAME}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI}")
7+
else()
8+
set(PREFIX "${INSTALL_NAME}")
9+
endif()
10+
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${PREFIX}/${PREFIX}Config.cmake")
11+
include("${CMAKE_CURRENT_LIST_DIR}/${PREFIX}/${PREFIX}Config.cmake")
12+
else()
13+
set(${INSTALL_NAME}_FOUND FALSE)
14+
endif()

cmake/GMPConfig.cmake.in

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
set(GMP_INCLUDE_PATHS "@INSTALL_CONFIG_INCLUDE_PATHS@")
8+
set(GMP_LIB_PATHS "@INSTALL_CONFIG_LIB_PATHS@")
9+
10+
unset(GMP_INCLUDE_DIR CACHE)
11+
unset(GMP_LIBRARY CACHE)
12+
13+
find_path(GMP_INCLUDE_DIR gmp.h PATHS ${GMP_INCLUDE_PATHS})
14+
find_library(GMP_LIBRARY NAMES ${LIB_PREFIX}gmp${LIB_SUFFIX} PATHS ${GMP_LIB_PATHS})
15+
16+
if(EXISTS "${GMP_INCLUDE_DIR}" AND EXISTS "${GMP_LIBRARY}")
17+
set(GMP_FOUND TRUE)
18+
else()
19+
set(GMP_LIBRARY )
20+
set(GMP_FOUND FALSE)
21+
endif()
22+
23+
if(GMP_FOUND AND NOT TARGET GMP::GMP)
24+
add_library(GMP::GMP "${GMP_LIBRARY_TYPE}" IMPORTED)
25+
set_target_properties(GMP::GMP PROPERTIES
26+
IMPORTED_LOCATION "${GMP_LIBRARY}"
27+
INTERFACE_INCLUDE_DIRECTORIES "${GMP_INCLUDE_DIR}")
28+
endif()
29+
30+
mark_as_advanced(
31+
GMP_INCLUDE_DIR
32+
GMP_LIBRARY
33+
)
34+
35+
set(TARGETS GMP::GMP)

0 commit comments

Comments
 (0)