Skip to content

Commit

Permalink
Better explanation and display (cmake gui) of cache variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-schick committed Feb 16, 2019
1 parent ce69efa commit fc64adb
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 69 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if(ANDROID)
set(CMAKE_TOOLCHAIN_FILE ${ANDROID_TOOLCHAIN_FILE})
endif(ANDROID)
project(ABY LANGUAGES C CXX)
include(UpdateAndroidCache)

if(ANDROID)
get_filename_component(ABY_DEPENDENCIES_SYSROOT
Expand Down
10 changes: 6 additions & 4 deletions cmake/ForwardConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include(CMakeFindDependencyMacro)
set(FILE_NAME_PREFIX @INSTALL_NAME@)
if(ANDROID)
find_dependency(${FILE_NAME_PREFIX}-android-${ANDROID_PLATFORM_LEVEL}-${ANDROID_SYSROOT_ABI})
endif(ANDROID)
set(PREFIX @INSTALL_NAME@)
if(ANDROID AND ANDROID_ARM_NEON)
find_dependency(${PREFIX}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI}-neon)
elseif(ANDROID AND NOT ANDROID_ARM_NEON)
find_dependency(${PREFIX}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI})
endif()
44 changes: 7 additions & 37 deletions cmake/Modules/ABYCacheVariables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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)
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")
Expand All @@ -16,45 +16,15 @@ elseif(NOT "${ABY_LIBRARY_TYPE}" STREQUAL "STATIC" AND
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."
"Choose the type of build."
FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"None" "Debug" "Release" "RelWithDebInfo" "MinSizeRel"
)
endif(NOT CMAKE_BUILD_TYPE)

include(AndroidCacheVariables)
37 changes: 37 additions & 0 deletions cmake/Modules/AndroidCacheVariables.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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_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"
)
if(NOT "${ANDROID_NDK}" STREQUAL "")
set(ANDROID ON)
endif()
if(ANDROID AND NOT EXISTS "${ANDROID_NDK}")
message(FATAL_ERROR "Path: ${ANDROID_NDK} does not exist.")
endif()
if(ANDROID AND "${ANDROID_TOOLCHAIN_FILE}" STREQUAL "")
set(ANDROID_TOOLCHAIN_FILE "${ANDROID_NDK}/build/cmake/android.toolchain.cmake"
CACHE INTERNAL
"Android toolchain file."
)
endif()
if(ANDROID AND NOT EXISTS "${ANDROID_TOOLCHAIN_FILE}")
message(FATAL_ERROR
"Could not find file: ${ANDROID_TOOLCHAIN_FILE}. "
"Your NDK might be outdated."
)
endif()
4 changes: 2 additions & 2 deletions cmake/Modules/FetchENCRYPTO_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ set(ENCRYPTO_utils_SOURCE
"Path to the ENCRYPTO_utils source."
)
set(ENCRYPTO_utils_URL
https://github.com/oliver-schick/ENCRYPTO_utils/archive/41ed7053a0fa7b3ed5d740fe837fd7e37823a266.zip
https://github.com/oliver-schick/ENCRYPTO_utils/archive/fe6858c1cee19034d0b027013a78247737e84114.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=b1d777cfefef142459a7686e7af83e2a1376d233
SHA1=fba6c38abbe4e7f9c8484c08b0ce2d3c2a6ec959
CACHE STRING
"Hash of contents of ENCRYPTO_utils_URL."
)
Expand Down
13 changes: 13 additions & 0 deletions cmake/Modules/UpdateAndroidCache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

set(ANDROID_NATIVE_API_LEVEL ${ANDROID_NATIVE_API_LEVEL} CACHE STRING
"Android API level to compile for. Acceptable values are: [0-9]+ or android-[0-9]+"
FORCE
)
set(ANDROID_PLATFORM ${ANDROID_PLATFORM} CACHE STRING
"Alternative way to set Android API level. Acceptable values are: latest or android-[0-9]+"
FORCE
)
set(ANDROID_ABI ${ANDROID_ABI} CACHE STRING
"Target CPU of android device, like e.g. \"armeabi-v7a\"."
FORCE
)
27 changes: 14 additions & 13 deletions src/abycore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ find_package(Threads REQUIRED)
set(INSTALL_NAME ${PROJECT_NAME})

if(ANDROID)
set(INSTALL_BOOST_DEPENDENCIES TRUE)
set(ABY_INSTALL_PREFIX "platforms/${ANDROID_PLATFORM}/arch-${ANDROID_SYSROOT_ABI}/")
set(ABY_CONFIG_NAME "${INSTALL_NAME}-android-${ANDROID_PLATFORM_LEVEL}-${ANDROID_SYSROOT_ABI}")
else()
set(INSTALL_BOOST_DEPENDENCIES FALSE)
set(ABY_INSTALL_PREFIX "")
set(ABY_CONFIG_NAME "${INSTALL_NAME}")
endif()

set(ABY_INSTALL_INCLUDE "${ABY_INSTALL_PREFIX}include")
set(ABY_INSTALL_LIB "${ABY_INSTALL_PREFIX}lib")
set(ABY_INSTALL_ARCHIVE "${ABY_INSTALL_PREFIX}lib")
set(ABY_INSTALL_CONFIG "sysroot/share/cmake")
set(INSTALL_BOOST_DEPENDENCIES TRUE)
set(ABY_INSTALL_PREFIX "platforms/${ANDROID_PLATFORM}/arch-${ANDROID_SYSROOT_ABI}")
set(ABY_INSTALL_INCLUDE "${ABY_INSTALL_PREFIX}/include")
set(ABY_INSTALL_LIB "${ABY_INSTALL_PREFIX}/lib")
set(ABY_INSTALL_ARCHIVE "${ABY_INSTALL_PREFIX}/lib")
set(ABY_INSTALL_CONFIG "sysroot/share/cmake")
else(ANDROID)
set(INSTALL_BOOST_DEPENDENCIES FALSE)
set(ABY_INSTALL_PREFIX "")
set(ABY_INSTALL_INCLUDE "include")
set(ABY_INSTALL_LIB "lib")
set(ABY_INSTALL_ARCHIVE "lib")
set(ABY_INSTALL_CONFIG "share/cmake")
endif(ANDROID)

add_library(aby ${ABY_LIBRARY_TYPE}
aby/abyparty.cpp
Expand Down
10 changes: 6 additions & 4 deletions src/abycore/cmake/ForwardConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include(CMakeFindDependencyMacro)
set(FILE_NAME_PREFIX @INSTALL_NAME@)
if(ANDROID)
find_dependency(${FILE_NAME_PREFIX}-android-${ANDROID_PLATFORM_LEVEL}-${ANDROID_SYSROOT_ABI})
endif(ANDROID)
set(PREFIX @INSTALL_NAME@)
if(ANDROID AND ANDROID_ARM_NEON)
find_dependency(${PREFIX}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI}-neon)
elseif(ANDROID AND NOT ANDROID_ARM_NEON)
find_dependency(${PREFIX}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI})
endif()
4 changes: 2 additions & 2 deletions src/abycore/cmake/Modules/FetchOTExtension.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ set(OTExtension_SOURCE
"Path to the OTExtension source."
)
set(OTExtension_URL
https://github.com/oliver-schick/OTExtension/archive/22dcb2254bfe3855e8af880318b9bc5033a9d6ba.zip
https://github.com/oliver-schick/OTExtension/archive/a25f906ebc93db3e9930a7cbb3ffe374d9050823.zip
CACHE STRING
[=["URL to zip of latest verified OTExtension commit. "
"Ignored if git is available and FORCE_OTExtension_URL is not set."]=]
)
set(OTExtension_URL_HASH
SHA1=331607cc683d9f14083bd82e85c699b5aee164f3
SHA1=0d4c2e3371feb02cbe42424c6368f0ba3af6bd8e
CACHE STRING
"Hash of contents of OTExtension_URL."
)
Expand Down
16 changes: 10 additions & 6 deletions src/abycore/cmake/Modules/InstallConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
function(install_config CONFIG_LOCATION INSTALL_NAME INSTALL_DIR)
if(ANDROID)
set(CONFIG_NAME
"${INSTALL_NAME}-android-${ANDROID_PLATFORM_LEVEL}-${ANDROID_SYSROOT_ABI}"
)
else(ANDROID)
if(ANDROID AND ANDROID_ARM_NEON)
set(CONFIG_NAME
"${INSTALL_NAME}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI}-neon"
)
elseif(ANDROID AND NOT ANDROID_ARM_NEON)
set(CONFIG_NAME
"${INSTALL_NAME}-${ANDROID_PLATFORM}-${ANDROID_SYSROOT_ABI}"
)
else()
set(CONFIG_NAME "${INSTALL_NAME}")
endif(ANDROID)
endif()

configure_file("${PROJECT_SOURCE_DIR}/cmake/${INSTALL_NAME}Config.cmake.in"
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}Config.cmake
Expand Down
2 changes: 1 addition & 1 deletion src/abycore/cmake/Modules/NDKMakeStandaloneBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mark_as_advanced(NDK_MAKE_STANDALONE_TOOLCHAIN_PY NDK_MAKE_STANDALONE_TOOLCHAIN_

set(NDK_STANDALONE_TOOLCHAIN_PATH "<INSTALL_DIR>/standalone_toolchain/${ANDROID_PLATFORM}")

find_package(Python COMPONENTS Interpreter)
find_package(Python QUIET REQUIRED COMPONENTS Interpreter)
if(${Python_FOUND} AND EXISTS ${NDK_MAKE_STANDALONE_TOOLCHAIN_PY})
set(NDK_MAKE_STANDALONE_TOOLCHAIN_COMMAND
"${Python_EXECUTABLE}"
Expand Down

0 comments on commit fc64adb

Please sign in to comment.