Skip to content

Commit

Permalink
Added install support for Android (installing in android ndk)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-schick committed Feb 14, 2019
1 parent b21faaf commit 6a83dc2
Show file tree
Hide file tree
Showing 30 changed files with 866 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
README.html
docs/*
*.dump

*.bak

# build directory
build*/
Expand Down
7 changes: 5 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[submodule "extern/boost-cmake"]
path = extern/boost-cmake
url = https://github.com/Orphis/boost-cmake.git
[submodule "extern/ENCRYPTO_utils"]
path = extern/ENCRYPTO_utils
url = https://github.com/encryptogroup/ENCRYPTO_utils.git
url = https://github.com/oliver-schick/ENCRYPTO_utils.git
[submodule "extern/OTExtension"]
path = extern/OTExtension
url = https://github.com/encryptogroup/OTExtension.git
url = https://github.com/oliver-schick/OTExtension.git
82 changes: 35 additions & 47 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
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)
cmake_minimum_required(VERSION 3.13)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
include(ABYCacheVariables)
if(ANDROID)
message(STATUS "Compiling ABY for Android.")
set(CMAKE_TOOLCHAIN_FILE ${ANDROID_TOOLCHAIN_FILE})
endif(ANDROID)
project(ABY LANGUAGES C CXX)

if(ANDROID)
get_filename_component(ABY_DEPENDENCIES_SYSROOT
"${ABY_DEPENDENCIES_SYSROOT}"
REALPATH
BASE_DIR "${CMAKE_BINARY_DIR}"
)
if(NOT "${ABY_DEPENDENCIES_SYSROOT}" STREQUAL "")
if(EXISTS "${ABY_DEPENDENCIES_SYSROOT}/${ANDROID_ABI}")
list(APPEND CMAKE_FIND_ROOT_PATH "${ABY_DEPENDENCIES_SYSROOT}/${ANDROID_ABI}")
elseif(EXISTS "${ABY_DEPENDENCIES_SYSROOT}")
list(APPEND CMAKE_FIND_ROOT_PATH "${ABY_DEPENDENCIES_SYSROOT}")
else()
message(SEND_ERROR "Invalid ANDROID_SYSROOT provided")
endif()
else()
message(STATUS "No dependencies sysroot provided.")
endif()
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${ANDROID_NDK}"
CACHE PATH
"Default install directory for android builds."
FORCE
)
endif()
endif()

# Write built executables and libraries to bin/ and lib/, respectively.
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
Expand All @@ -24,41 +44,9 @@ 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")
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/ENCRYPTO_utils/CMakeLists.txt")
find_package(Git REQUIRED)
message("initialize Git submodule: extern/ENCRYPTO_utils")
execute_process(COMMAND git submodule update --init extern/ENCRYPTO_utils
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
endif()
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")
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/OTExtension/CMakeLists.txt")
find_package(Git REQUIRED)
message("initialize Git submodule: extern/OTExtension")
execute_process(COMMAND git submodule update --init extern/OTExtension
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
endif()
add_subdirectory(extern/OTExtension)
endif()

find_package(GMP REQUIRED)
find_package(Threads REQUIRED)
find_package(Boost REQUIRED)

include(AddENCRYPTO_utils)
add_subdirectory(src/abycore)


if(ABY_BUILD_EXE)
add_subdirectory(src/test)
add_subdirectory(src/examples)
Expand Down
2 changes: 0 additions & 2 deletions cmake/ABYConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
get_filename_component(ABY_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

list(APPEND CMAKE_MODULE_PATH "${ABY_CMAKE_DIR}")

include(CMakeFindDependencyMacro)

find_dependency(OTExtension)
Expand Down
5 changes: 5 additions & 0 deletions cmake/ForwardConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include(CMakeFindDependencyMacro)
set(ORIGINAL_PROJECT_NAME @PROJECT_NAME@)
if(ANDROID)
find_dependency(Android${ORIGINAL_PROJECT_NAME}-${ANDROID_PLATFORM_LEVEL})
endif()
60 changes: 60 additions & 0 deletions cmake/Modules/ABYCacheVariables.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
option(ABY_BUILD_EXE "Build executables" OFF)
set(ABY_LIBRARY_TYPE ${ABY_LIBRARY_TYPE} CACHE STRING
"[STATIC | SHARED | MODULE] The type of library in which ABY will be built. Default: SHARED"
)
set_property(CACHE ABY_LIBRARY_TYPE PROPERTY STRINGS STATIC SHARED MODULE)
string(TOUPPER "${ABY_LIBRARY_TYPE}" ABY_LIBRARY_TYPE)
if("${ABY_LIBRARY_TYPE}" STREQUAL "")
set(ABY_LIBRARY_TYPE "SHARED")
elseif(NOT "${ABY_LIBRARY_TYPE}" STREQUAL "STATIC" AND
NOT "${ABY_LIBRARY_TYPE}" STREQUAL "SHARED" AND
NOT "${ABY_LIBRARY_TYPE}" STREQUAL "MODULE")
message(WARNING
"Unknown library type: ${ABY_LIBRARY_TYPE}. "
"Setting ABY_LIBRARY_TYPE to default value."
)
set(ABY_LIBRARY_TYPE "SHARED")
endif()

option(ANDROID "Build for Android")

set(ABY_DEPENDENCIES_SYSROOT CACHE PATH
[=["Path to the target platform root, where prebuilt ABY dependencies reside "
"Hint: The prebuilt libraries must be built for the current Android ABI. "
"It is not necessary to point to the specific ABI root, if it is a subfolder "
"and the folder's name is equal to the variable ANDROID_ABI for the corresponding ABI"
"(ignored if ANDROID is not set)."]=]
)
set(ANDROID_NDK CACHE PATH
"Path to Android NDK (ignored if ANDROID is not set)."
)
set(ANDROID_ABI CACHE STRING
"Target CPU of android device, like e.g. \"armeabi-v7a\" (ignored if ANDROID is not set)."
)
set(ANDROID_TOOLCHAIN_FILE CACHE FILEPATH
"Android toolchain file (ignored if ANDROID is not set)."
)
mark_as_advanced(ANDROID_TOOLCHAIN_FILE)
if("${ANDROID_TOOLCHAIN_FILE}" STREQUAL "")
set(ANDROID_TOOLCHAIN_FILE "${ANDROID_NDK}/build/cmake/android.toolchain.cmake")
endif()
if(ANDROID AND (NOT EXISTS "${ANDROID_NDK}" OR NOT EXISTS "${ANDROID_TOOLCHAIN_FILE}"))
if(NOT EXISTS "${ANDROID_NDK}")
message(FATAL_ERROR "Path: ${ANDROID_NDK} does not exist.")
elseif(NOT EXISTS "${ANDROID_TOOLCHAIN_FILE}")
message(FATAL_ERROR
"Could not find file: ${ANDROID_TOOLCHAIN_FILE}. "
"Your NDK might be outdated."
)
else()
message(FATAL_ERROR "Unknown error.")
endif()
endif()

# Set build type to `Release` if none 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)
18 changes: 18 additions & 0 deletions cmake/Modules/AddENCRYPTO_utils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.13)

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)
set(ENCRYPTO_utils_LIBRARY_TYPE ${ABY_LIBRARY_TYPE})
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/ENCRYPTO_utils/CMakeLists.txt")
message(STATUS "ENCRYPTO_utils was not found. Fetching ENCRYPTO_utils...")
if(NOT ENCRYPTO_utils_LIBRARY_TYPE)
set(ENCRYPTO_utils_LIBRARY_TYPE ${ABY_LIBRARY_TYPE})
endif()
include(FetchENCRYPTO_utils)
else()
message(STATUS "ENCRYPTO_utils was found as a submodule. Adding subdirectory.")
add_subdirectory(${PROJECT_SOURCE_DIR}/extern/ENCRYPTO_utils)
endif()
endif()
33 changes: 33 additions & 0 deletions cmake/Modules/FetchENCRYPTO_utils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.13)

option(FORCE_ENCRYPTO_utils_URL_DOWNLOAD "Force download over URL instead of git." OFF)
set(ENCRYPTO_utils_SOURCE_LOCATION
CACHE PATH
"Path to the ENCRYPTO_utils source."
)
set(ENCRYPTO_utils_REPOSITORY
https://github.com/oliver-schick/ENCRYPTO_utils.git
CACHE STRING
[=["Git repository of 'ENCRYPTO_utils'. If Git is not available on your computer "
"or option FORCE_ENCRYPTO_utils_URL is set, define ENCRYPTO_utils_URL instead."]=]
)
set(ENCRYPTO_utils_GIT_TAG
4c3f1427efa12a971d576faa64861035e01e706d
CACHE STRING
"Git tag of latest verified ENCRYPTO_utils release."
)
set(ENCRYPTO_utils_URL
https://github.com/oliver-schick/ENCRYPTO_utils/archive/4c3f1427efa12a971d576faa64861035e01e706d.zip
CACHE STRING
[=["URL to zip of latest verified ENCRYPTO_utils commit. "
"Ignored if git is available and FORCE_ENCRYPTO_utils_URL is not set."]=]
)
set(ENCRYPTO_utils_URL_HASH
SHA1=832bac4604f34a7b3616949c3a3a69719d5996ac
CACHE STRING
"Hash of contents of ENCRYPTO_utils_URL."
)
mark_as_advanced(FORCE_ENCRYPTO_utils_URL_DOWNLOAD ENCRYPTO_utils_URL ENCRYPTO_utils_URL_HASH)

include(FetchHelper)
fetch_helper(ENCRYPTO_utils)
45 changes: 45 additions & 0 deletions cmake/Modules/FetchHelper.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.13)
macro(fetch_helper content_name)
string(TOLOWER ${content_name} LOWER_CASE_${content_name})
if(NOT ${${content_name}_SOURCE_LOCATION} STREQUAL "")
set(FORCE_${content_name}_URL_DOWNLOAD ON)
set(${content_name}_URL_COMMAND
URL ${${content_name}_SOURCE_LOCATION}
)
set(${content_name}_URL_HASH_COMMAND
URL_HASH ${${content_name}_URL_HASH}
)
else()
set(${content_name}_URL_COMMAND
URL ${${content_name}_CMAKE_URL}
)
set(${content_name}_URL_HASH_COMMAND
URL_HASH ${${content_name}_URL_HASH_COMMAND})
endif()
if(NOT FORCE_${content_name}_URL_DOWNLOAD)
find_package(Git VERSION 1.6.5 QUIET)
endif()
include(FetchContent)
if(Git_FOUND AND NOT FORCE_${content_name}_URL_DOWNLOAD)
FetchContent_Declare(${content_name}
GIT_REPOSITORY ${${content_name}_REPOSITORY}
GIT_TAG ${${content_name}_GIT_TAG}
)
else()
FetchContent_Declare(${content_name}
${${content_name}_URL_COMMAND}
${${content_name}_URL_HASH_COMMAND}
)
endif()
if(NOT LOWER_CASE_${content_name}_POPULATED)
FetchContent_Populate(${content_name})
if(${ARGV2})
message(STATUS "Applying patches to ${content_name}.")
include("Patch${content_name}")
endif()
add_subdirectory(
${${LOWER_CASE_${content_name}}_SOURCE_DIR}
${${LOWER_CASE_${content_name}}_BINARY_DIR}
)
endif()
endmacro()
1 change: 1 addition & 0 deletions extern/boost-cmake
Submodule boost-cmake added at f0f64a
Loading

0 comments on commit 6a83dc2

Please sign in to comment.