-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added build support for Android platforms
- Loading branch information
1 parent
7e43c5d
commit 53f037e
Showing
17 changed files
with
543 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
|
||
# build directory | ||
build*/ | ||
# extern directory | ||
extern/* | ||
|
||
# CMake | ||
CMakeCache.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
get_filename_component(Boost_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) | ||
|
||
if(NOT TARGET Boost::boost) | ||
include("${Boost_CMAKE_DIR}/BoostTargets.cmake") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
include(CMakeFindDependencyMacro) | ||
set(DEPENDENCY_NAME "@DEPENDENCY_NAME@") | ||
if(ANDROID AND ANDROID_ARM_NEON) | ||
set(PREFIX "${DEPENDENCY_NAME}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI}-NEON") | ||
elseif(ANDROID AND NOT ANDROID_ARM_NEON) | ||
set(PREFIX "${DEPENDENCY_NAME}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI}") | ||
else() | ||
set(PREFIX "${DEPENDENCY_NAME}") | ||
endif() | ||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${PREFIX}/${PREFIX}Config.cmake") | ||
include("${CMAKE_CURRENT_LIST_DIR}/${PREFIX}/${PREFIX}Config.cmake") | ||
else() | ||
set(${DEPENDENCY_NAME}_FOUND FALSE) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
set(TARGETS "@DEPENDENCY_TARGETS@") | ||
function(import_into_android_studio IMPORT_LOCATION) | ||
if(ANDROID AND EXISTS "${IMPORT_LOCATION}") | ||
foreach(target ${TARGETS}) | ||
get_target_property(library_type ${target} TYPE) | ||
if("${library_type}" STREQUAL "SHARED_LIBRARY") | ||
get_target_property(lib_location ${target} LOCATION) | ||
file(COPY "${lib_location}" DESTINATION "${IMPORT_LOCATION}") | ||
endif() | ||
endforeach() | ||
endif() | ||
endfunction() | ||
|
||
if(NOT IMPORT_LOCATION) | ||
import_into_android_studio("${PROJECT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}") | ||
else() | ||
import_into_android_studio("${IMPORT_LOCATION}") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
|
||
if(NOT TARGET ENCRYPTO_utils::encrypto_utils) | ||
if(NOT ENCRYPTO_utils_LIBRARY_TYPE) | ||
set(ENCRYPTO_utils_LIBRARY_TYPE ${OTExtension_LIBRARY_TYPE}) | ||
endif() | ||
file(GLOB ENCRYPTO_utils_FILE_LIST "${PROJECT_SOURCE_DIR}/extern/ENCRYPTO_utils/*") | ||
list(LENGTH ENCRYPTO_utils_FILE_LIST ENCRYPTO_utils_NUM_FILES) | ||
#if ENCRYPTO_utils directory is empty | ||
if(ENCRYPTO_utils_NUM_FILES EQUAL 0) | ||
message(STATUS "ENCRYPTO_utils was not found. Fetching ENCRYPTO_utils...") | ||
include(FetchENCRYPTO_utils) | ||
else() | ||
message(STATUS "ENCRYPTO_utils was found in: ${PROJECT_SOURCE_DIR}/extern/ENCRYPTO_utils") | ||
set(ENCRYPTO_utils_SOURCE "${PROJECT_SOURCE_DIR}/extern/ENCRYPTO_utils" | ||
CACHE PATH | ||
"Path to ENCRYPTO_utils source." | ||
FORCE | ||
) | ||
include(FetchENCRYPTO_utils) | ||
endif() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
|
||
find_package(Relic QUIET) | ||
if(Relic_FOUND OR TARGET Relic::relic) | ||
message(STATUS "Found Relic.") | ||
elseif(NOT Relic_FOUND AND NOT TARGET Relic::relic) | ||
if("${Relic_SOURCE}" STREQUAL "") | ||
file(GLOB Relic_FILE_LIST "${PROJECT_SOURCE_DIR}/extern/Relic/*") | ||
list(LENGTH Relic_FILE_LIST Relic_NUM_FILES) | ||
#if Relic directory is empty | ||
if(Relic_NUM_FILES EQUAL 0) | ||
message(STATUS "Relic was not found. Fetching Relic...") | ||
else() | ||
message(STATUS "Relic was found in: ${PROJECT_SOURCE_DIR}/extern/Relic") | ||
set(Relic_SOURCE "${PROJECT_SOURCE_DIR}/extern/Relic") | ||
endif() | ||
endif() | ||
include(FetchRelic) | ||
if(ANDROID AND Relic_LIBRARY_TYPE STREQUAL "SHARED") | ||
set(CMAKE_SHARED_LINKER_FLAGS ${TMP}) | ||
endif() | ||
include(ExternalBuildHelper) | ||
install_imported_library(Relic::relic "Relic") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
set(ANDROID_NDK CACHE PATH "Path to Android NDK.") | ||
set(ANDROID_NATIVE_API_LEVEL CACHE STRING "Android API level to compile for. Acceptable values are: [0-9]+ or android-[0-9]+") | ||
set(ANDROID_PLATFORM CACHE STRING "Alternative way to set Android API level. Acceptable values are: latest or android-[0-9]+") | ||
set(ANDROID_TOOLCHAIN_FILE CACHE PATH "Android toolchain file.") | ||
set(ANDROID_ABI CACHE STRING "Target CPU of android device, like e.g. \"armeabi-v7a\".") | ||
set_property(CACHE ANDROID_ABI PROPERTY STRINGS | ||
"armeabi-v7a" | ||
"armeabi-v7a with NEON" | ||
"arm64-v8a" | ||
"x86" | ||
"x86_64" | ||
) | ||
|
||
#Check if user wants to build for Android | ||
if(NOT "${CMAKE_ANDROID_NDK}" STREQUAL "") | ||
set(ANDROID_NDK "${CMAKE_ANDROID_NDK}") | ||
endif() | ||
if(NOT "${ANDROID_NDK}" STREQUAL "") | ||
set(ANDROID ON) | ||
elseif(NOT "${ANDROID_TOOLCHAIN_FILE}" STREQUAL "" AND EXISTS "${ANDROID_TOOLCHAIN_FILE}") | ||
set(ANDROID ON) | ||
elseif(NOT "${CMAKE_TOOLCHAIN_FILE}" STREQUAL "" AND EXISTS "${CMAKE_TOOLCHAIN_FILE}") | ||
set(ANDROID ON) | ||
endif() | ||
|
||
#Set CMAKE_TOOLCHAIN_FILE and CMAKE_INSTALL_PREFIX for Android builds | ||
if(ANDROID) | ||
#CMAKE_TOOLCHAIN_FILE was not set, but ANDROID_TOOLCHAIN_FILE was set | ||
if("${CMAKE_TOOLCHAIN_FILE}" STREQUAL "" AND NOT "${ANDROID_TOOLCHAIN_FILE}" STREQUAL "") | ||
set(CMAKE_TOOLCHAIN_FILE "${ANDROID_TOOLCHAIN_FILE}") | ||
#Neither toolchain file was set, use toolchain in NDK | ||
elseif("${CMAKE_TOOLCHAIN_FILE}" STREQUAL "" AND "${ANDROID_TOOLCHAIN_FILE}" STREQUAL "") | ||
set(CMAKE_TOOLCHAIN_FILE "${ANDROID_NDK}/build/cmake/android.toolchain.cmake") | ||
else() | ||
set(ANDROID_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}") | ||
endif() | ||
if(NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}") | ||
message(FATAL_ERROR | ||
"Could not find file: ${CMAKE_TOOLCHAIN_FILE}. Your NDK might be outdated." | ||
) | ||
endif() | ||
if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) | ||
set(CMAKE_INSTALL_PREFIX "${ANDROID_NDK}" CACHE PATH "Default install directory for android builds." FORCE) | ||
endif() | ||
endif(ANDROID) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
|
||
include(FetchHelper) | ||
fetch_helper(ENCRYPTO_utils) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
macro(fetch_helper content_name) | ||
string(TOLOWER "${content_name}" LOWER_CASE_${content_name}) | ||
if(NOT "${DEPENDENCY_DIR}" STREQUAL "") | ||
set(${content_name}_DOWNLOAD_DIR_COMMAND DOWNLOAD_DIR ${DEPENDENCY_DIR}) | ||
else() | ||
set(${content_name}_DOWNLOAD_DIR_COMMAND "") | ||
endif() | ||
if(NOT "${${content_name}_SOURCE}" STREQUAL "") | ||
set(${content_name}_DOWNLOAD_COMMAND1 URL ${${content_name}_SOURCE}) | ||
set(${content_name}_DOWNLOAD_COMMAND2 "") | ||
else() | ||
set(${content_name}_DOWNLOAD_COMMAND1 GIT_REPOSITORY ${${content_name}_REPOSITORY}) | ||
set(${content_name}_DOWNLOAD_COMMAND2 GIT_TAG ${${content_name}_TAG}) | ||
endif() | ||
include(FetchContent) | ||
FetchContent_Declare(${content_name} | ||
${${content_name}_DOWNLOAD_COMMAND1} | ||
${${content_name}_DOWNLOAD_COMMAND2} | ||
${${content_name}_DOWNLOAD_DIR_COMMAND} | ||
) | ||
FetchContent_GetProperties(${content_name}) | ||
if(NOT ${LOWER_CASE_${content_name}}_POPULATED) | ||
FetchContent_Populate(${content_name}) | ||
if(NOT "${ARGV1}" STREQUAL "") | ||
message(STATUS "Applying patches to ${content_name}...") | ||
include("Patch${content_name}") | ||
endif() | ||
if(NOT "${ARGV2}" STREQUAL "") | ||
add_subdirectory( | ||
${${LOWER_CASE_${content_name}}_SOURCE_DIR} | ||
${${LOWER_CASE_${content_name}}_BINARY_DIR} | ||
EXCLUDE_FROM_ALL | ||
) | ||
else() | ||
add_subdirectory( | ||
${${LOWER_CASE_${content_name}}_SOURCE_DIR} | ||
${${LOWER_CASE_${content_name}}_BINARY_DIR} | ||
) | ||
endif() | ||
endif() | ||
endmacro() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
|
||
set(Relic_SOURCE | ||
CACHE PATH | ||
"Path to Relic source." | ||
) | ||
set(Relic_URL | ||
https://github.com/relic-toolkit/relic/archive/a13dcefef1b81a51f2661910200aa76ab3599273.zip | ||
CACHE STRING | ||
"URL of Relic project." | ||
) | ||
set(Relic_URL_HASH | ||
SHA256=fb327f7350c563433797b5c9ac4e8d08a6989afec5f8f58dbe5d44d621240d65 | ||
CACHE STRING | ||
"Hash of Relic archive." | ||
) | ||
|
||
include(FetchHelper) | ||
#EXCLUDE_FROM_ALL to prevent some rogue config files to be installed | ||
fetch_helper(Relic patch EXCLUDE_FROM_ALL) | ||
|
||
set(Relic_INCLUDE_DIRS "${relic_SOURCE_DIR}/include" "${relic_SOURCE_DIR}/include/low" "${relic_BINARY_DIR}/include") | ||
set(Relic_LIB_DIR "${CMAKE_BINARY_DIR}/lib") | ||
if(Relic_LIBRARY_TYPE STREQUAL "STATIC") | ||
if(LABEL) | ||
set(Relic_TARGET "relic_s_${LABEL}") | ||
else() | ||
set(Relic_TARGET "relic_s") | ||
endif() | ||
elseif(${Relic_LIBRARY_TYPE} STREQUAL "SHARED") | ||
if(LABEL) | ||
set(Relic_TARGET "relic_${LABEL}") | ||
else() | ||
set(Relic_TARGET "relic") | ||
endif() | ||
endif() | ||
set(Relic_LIB_NAME "${Relic_TARGET}") | ||
#Allow relic target to be installed (but keep install deactivated for config files etc.) | ||
set_target_properties(${Relic_TARGET} PROPERTIES EXCLUDE_FROM_ALL 0) | ||
add_library(Relic::relic ${Relic_LIBRARY_TYPE} IMPORTED GLOBAL) | ||
add_dependencies(Relic::relic ${Relic_TARGET}) | ||
target_include_directories(Relic::relic INTERFACE "${Relic_INCLUDE_DIRS}") | ||
set_target_properties(Relic::relic PROPERTIES IMPORTED_LOCATION "${Relic_LIB_DIR}/${CMAKE_${Relic_LIBRARY_TYPE}_LIBRARY_PREFIX}${Relic_TARGET}${CMAKE_${Relic_LIBRARY_TYPE}_LIBRARY_SUFFIX}") | ||
if(ANDROID) | ||
find_library(ANDROID_LOG_LIB log) | ||
target_link_libraries(Relic::relic INTERFACE "${ANDROID_LOG_LIB}") | ||
endif() |
Oops, something went wrong.