add a gvr-interface target that uses native glue to make apk

This commit is contained in:
Stephen Birarda 2014-11-17 10:58:12 -08:00
parent f23b08971c
commit 05cab9a3ba
11 changed files with 262 additions and 34 deletions

View file

@ -55,9 +55,19 @@ if (APPLE)
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
endif ()
if (NOT HIFI_ANDROID)
set(HIFI_ANDROID $ENV{HIFI_ANDROID})
endif ()
if (ANDROID)
if (NOT ANDROID_QT_CMAKE_PREFIX_PATH)
set(QT_CMAKE_PREFIX_PATH $ENV{HIFI_ANDROID}/qt/5.3/android_armv7/lib/cmake)
set(QT_CMAKE_PREFIX_PATH ${HIFI_ANDROID}/qt/5.3/android_armv7/lib/cmake)
endif ()
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
if (HIFI_ANDROID)
list(APPEND CMAKE_FIND_ROOT_PATH ${HIFI_ANDROID})
endif ()
else ()
if (NOT QT_CMAKE_PREFIX_PATH)
@ -88,13 +98,14 @@ foreach(CUSTOM_MACRO ${HIFI_CUSTOM_MACROS})
endforeach()
# add subdirectories for all targets
add_subdirectory(assignment-client)
add_subdirectory(tools)
if (NOT ANDROID)
add_subdirectory(domain-server)
add_subdirectory(ice-server)
add_subdirectory(interface)
add_subdirectory(tests)
add_subdirectory(voxel-edit)
endif ()
add_subdirectory(assignment-client)
add_subdirectory(domain-server)
add_subdirectory(ice-server)
add_subdirectory(interface)
add_subdirectory(tests)
add_subdirectory(tools)
add_subdirectory(voxel-edit)
else ()
add_subdirectory(gvr-interface)
endif()

View file

@ -13,5 +13,11 @@ macro(AUTO_MTC)
file(GLOB INCLUDE_FILES src/*.h)
add_custom_command(OUTPUT ${AUTOMTC_SRC} COMMAND mtc -o ${AUTOMTC_SRC} ${INCLUDE_FILES} DEPENDS mtc ${INCLUDE_FILES})
if (NOT ANDROID)
set(MTC_EXECUTABLE mtc)
else ()
set(MTC_EXECUTABLE $ENV{MTC_PATH}/mtc)
endif ()
add_custom_command(OUTPUT ${AUTOMTC_SRC} COMMAND ${MTC_EXECUTABLE} -o ${AUTOMTC_SRC} ${INCLUDE_FILES} DEPENDS ${MTC_EXECUTABLE} ${INCLUDE_FILES})
endmacro()

View file

@ -16,8 +16,8 @@ macro(HIFI_LIBRARY_SEARCH_HINTS LIBRARY_FOLDER)
set(${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_ROOT_DIR}")
endif ()
if (ANDROID AND DEFINED ENV{HIFI_ANDROID})
set(${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_SEARCH_DIRS}" "$ENV{HIFI_ANDROID}/${LIBRARY_FOLDER}")
if (ANDROID)
set(${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_SEARCH_DIRS}" "/${LIBRARY_FOLDER}")
endif ()
if (DEFINED ENV{${LIBRARY_PREFIX}_ROOT_DIR})

View file

@ -208,16 +208,8 @@
#
# ------------------------------------------------------------------------------
# Modified by Lasse Oorni and Yao Wei Tjong for Urho3D
cmake_minimum_required( VERSION 2.6.3 )
# Urho3D: on Windows Cygwin-based NDK tools may fail in the linking phase with too long command line. Turn on response files to avoid this
if( CMAKE_HOST_WIN32 )
set( CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1 )
set( CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1 )
endif()
if( DEFINED CMAKE_CROSSCOMPILING )
# subsequent toolchain loading is not really needed
return()
@ -271,12 +263,11 @@ set( ANDROID_SUPPORTED_ABIS_mips "mips" )
set( ANDROID_SUPPORTED_ABIS_mips64 "mips64" )
# API level defaults
# Urho3D: default to API 12
set( ANDROID_DEFAULT_NDK_API_LEVEL 12 )
set( ANDROID_DEFAULT_NDK_API_LEVEL 8 )
set( ANDROID_DEFAULT_NDK_API_LEVEL_arm64 21 )
set( ANDROID_DEFAULT_NDK_API_LEVEL_x86 12)
set( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 )
set( ANDROID_DEFAULT_NDK_API_LEVEL_x86_64 21 )
set( ANDROID_DEFAULT_NDK_API_LEVEL_mips 12 )
set( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 )
set( ANDROID_DEFAULT_NDK_API_LEVEL_mips64 21 )
@ -1430,9 +1421,8 @@ endif()
# cache flags
set( CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags" )
set( CMAKE_C_FLAGS "" CACHE STRING "c flags" )
# Urho3D: optimise for size
set( CMAKE_CXX_FLAGS_RELEASE "-Os -DNDEBUG" CACHE STRING "c++ Release flags" )
set( CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG" CACHE STRING "c Release flags" )
set( CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c++ Release flags" )
set( CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c Release flags" )
set( CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c++ Debug flags" )
set( CMAKE_C_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c Debug flags" )
set( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "shared linker flags" )
@ -1534,8 +1524,7 @@ if(NOT _CMAKE_IN_TRY_COMPILE)
else()
set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" )
endif()
# Urho3D: All libraries are first generated in CMake default binary directory and only the main target library is later copied to below output path by Urho3D own build script
set( ANDROID_LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" FORCE )
set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" )
endif()
# copy shaed stl library to build directory

146
cmake/macros/apk.cmake Normal file
View file

@ -0,0 +1,146 @@
#*********************************************************#
#* File: Apk.cmake *
#* Android apk tools
#*
#* Copyright (C) 2002-2013 The PixelLight Team (http://www.pixellight.org/)
#*
#* This file is part of PixelLight.
#*
#* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
#* and associated documentation files (the "Software"), to deal in the Software without
#* restriction, including without limitation the rights to use, copy, modify, merge, publish,
#* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
#* Software is furnished to do so, subject to the following conditions:
#*
#* The above copyright notice and this permission notice shall be included in all copies or
#* substantial portions of the Software.
#*
#* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
#* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
#* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#*********************************************************#
##################################################
## Options
##################################################
set(ANDROID_APK_API_LEVEL "19" CACHE STRING "Android APK API level")
set(ANDROID_APK_INSTALL "0" CACHE BOOL "Install created apk file on the device automatically?")
set(ANDROID_APK_RUN "0" CACHE BOOL "Run created apk file on the device automatically? (installs it automatically as well, \"ANDROID_APK_INSTALL\"-option is ignored)")
set(ANDROID_APK_SIGNER_KEYSTORE "~/my-release-key.keystore" CACHE STRING "Keystore for signing the apk file (only required for release apk)")
set(ANDROID_APK_SIGNER_ALIAS "myalias" CACHE STRING "Alias for signing the apk file (only required for release apk)")
##################################################
## Variables
##################################################
set(ANDROID_THIS_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) # Directory this CMake file is in
##################################################
## MACRO: android_create_apk
##
## Create/copy Android apk related files
##
## @param name
## Name of the project (e.g. "MyProject"), this will also be the name of the created apk file
## @param apk_pacakge_name
## Pacakge name of the application
## @param apk_directory
## Directory were to construct the apk file in (e.g. "${CMAKE_BINARY_DIR}/apk")
## @param libs_directory
## Directory where the built android libraries will be POST_BUILD, e.g ${CMAKE_SOURCE_DIR}/libs
## @param assets_directory
## Directory where the assets for the application are locatated
##
## @remarks
## Requires the following tools to be found automatically
## - "android" (part of the Android SDK)
## - "adb" (part of the Android SDK)
## - "ant" (type e.g. "sudo apt-get install ant" on your Linux system to install Ant)
## - "jarsigner" (part of the JDK)
## - "zipalign" (part of the Android SDK)
##################################################
macro(android_create_apk name apk_package_name apk_directory libs_directory android_directory assets_directory)
set(ANDROID_NAME ${name})
set(ANDROID_APK_PACKAGE ${apk_package_name})
# Create the directory for the libraries
add_custom_command(TARGET ${ANDROID_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E remove_directory "${apk_directory}/libs")
add_custom_command(TARGET ${ANDROID_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${apk_directory}/libs")
add_custom_command(TARGET ${ANDROID_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${libs_directory}" "${apk_directory}/libs/")
# Create "build.xml", "default.properties", "local.properties" and "proguard.cfg" files
if(CMAKE_BUILD_TYPE MATCHES Release)
set(ANDROID_APK_DEBUGGABLE "false")
else()
set(ANDROID_APK_DEBUGGABLE "true")
endif()
add_custom_command(TARGET ${ANDROID_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${apk_directory}/res")
add_custom_command(TARGET ${ANDROID_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${android_directory}/res" "${apk_directory}/res/")
configure_file("${android_directory}/AndroidManifest.xml" "${apk_directory}/AndroidManifest.xml")
add_custom_command(TARGET ${ANDROID_NAME}
COMMAND android update project -t android-${ANDROID_APK_API_LEVEL} --name ${ANDROID_NAME} --path "${apk_directory}")
# Copy assets
add_custom_command(TARGET ${ANDROID_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E remove_directory "${apk_directory}/assets")
add_custom_command(TARGET ${ANDROID_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${apk_directory}/assets/")
add_custom_command(TARGET ${ANDROID_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_SOURCE_DIR}/assets" "${apk_directory}/assets/")
# Build the apk file
if(CMAKE_BUILD_TYPE MATCHES Release)
# Let Ant create the unsigned apk file
add_custom_command(TARGET ${ANDROID_NAME}
COMMAND ant release
WORKING_DIRECTORY "${apk_directory}")
# Sign the apk file
add_custom_command(TARGET ${ANDROID_NAME}
COMMAND jarsigner -verbose -keystore ${ANDROID_APK_SIGNER_KEYSTORE} bin/${ANDROID_NAME}-unsigned.apk ${ANDROID_APK_SIGNER_ALIAS}
WORKING_DIRECTORY "${apk_directory}")
# Align the apk file
add_custom_command(TARGET ${ANDROID_NAME}
COMMAND zipalign -v -f 4 bin/${ANDROID_NAME}-unsigned.apk bin/${ANDROID_NAME}.apk
WORKING_DIRECTORY "${apk_directory}")
# Install current version on the device/emulator
if(ANDROID_APK_INSTALL OR ANDROID_APK_RUN)
add_custom_command(TARGET ${ANDROID_NAME}
COMMAND adb install -r bin/${ANDROID_NAME}.apk
WORKING_DIRECTORY "${apk_directory}")
endif()
else()
# Let Ant create the unsigned apk file
add_custom_command(TARGET ${ANDROID_NAME}
COMMAND ant debug
WORKING_DIRECTORY "${apk_directory}")
# Install current version on the device/emulator
if(ANDROID_APK_INSTALL OR ANDROID_APK_RUN)
add_custom_command(TARGET ${ANDROID_NAME}
COMMAND adb install -r bin/${ANDROID_NAME}-debug.apk
WORKING_DIRECTORY "${apk_directory}")
endif()
endif()
# Start the application
if(ANDROID_APK_RUN)
add_custom_command(TARGET ${ANDROID_NAME}
COMMAND adb shell am start -n ${ANDROID_APK_PACKAGE}/android.app.NativeActivity)
endif()
endmacro(android_create_apk name apk_directory libs_directory assets_directory)

View file

@ -54,7 +54,6 @@ endif ()
find_path(OPENSSL_INCLUDE_DIR NAMES openssl/ssl.h HINTS ${_OPENSSL_ROOT_HINTS_AND_PATHS} ${_OPENSSL_INCLUDEDIR}
PATH_SUFFIXES include
NO_CMAKE_FIND_ROOT_PATH
)
if (WIN32 AND NOT CYGWIN)
@ -134,12 +133,10 @@ else()
find_library(OPENSSL_SSL_LIBRARY NAMES ssl ssleay32 ssleay32MD HINTS ${_OPENSSL_ROOT_HINTS_AND_PATHS} ${_OPENSSL_LIBDIR}
PATH_SUFFIXES lib
NO_CMAKE_FIND_ROOT_PATH
)
find_library(OPENSSL_CRYPTO_LIBRARY NAMES crypto HINTS ${_OPENSSL_ROOT_HINTS_AND_PATHS} ${_OPENSSL_LIBDIR}
PATH_SUFFIXES lib
NO_CMAKE_FIND_ROOT_PATH
)
mark_as_advanced(OPENSSL_CRYPTO_LIBRARY OPENSSL_SSL_LIBRARY)

View file

@ -115,6 +115,14 @@ if (UNIX)
endif (APPLE)
endif (UNIX)
if (ANDROID)
set(_TBB_DEFAULT_INSTALL_DIR "/tbb")
set(_TBB_LIB_NAME "tbb")
set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc")
set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug")
set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug")
endif ()
if (CMAKE_SYSTEM MATCHES "SunOS.*")
# SUN
# not yet supported
@ -189,7 +197,6 @@ find_path(TBB_INCLUDE_DIR
)
mark_as_advanced(TBB_INCLUDE_DIR)
#-- Look for libraries
# GvdB: $ENV{TBB_ARCH_PLATFORM} is set by the build script tbbvars[.bat|.sh|.csh]
if (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "")

View file

@ -0,0 +1,19 @@
project(gvr-builder)
include_directories(${ANDROID_NDK}/sources/android/native_app_glue)
set(GVR_SRC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c
src/main.cpp
)
add_library(gvr-interface SHARED ${GVR_SRC})
target_link_libraries(gvr-interface log android)
set_target_properties(gvr-interface PROPERTIES COMPILE_DEFINITIONS "ANDROID")
android_create_apk(gvr-interface "io.highfidelity.interface"
"${CMAKE_BINARY_DIR}/apk"
"${CMAKE_BINARY_DIR}/libs"
"${CMAKE_CURRENT_SOURCE_DIR}/android"
"${CMAKE_CURRENT_SOURCE_DIR}/assets"
)

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="${ANDROID_APK_PACKAGE}"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="${ANDROID_APK_API_LEVEL}" />
<application android:label="@string/app_name"
android:hasCode="false"
android:debuggable="${ANDROID_APK_DEBUGGABLE}"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
<activity android:name="android.app.NativeActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden">
<meta-data android:name="android.app.lib_name" android:value="${ANDROID_NAME}" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Interface</string>
</resources>

View file

@ -0,0 +1,23 @@
//
// main.cpp
// gvr-interface/src
//
// Created by Stephen Birarda on 11/17/14.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <android_native_app_glue.h>
#include <android/log.h>
#define APPNAME "Interface"
void android_main(struct android_app* state) {
app_dummy();
__android_log_print(ANDROID_LOG_INFO, APPNAME, "GearVR Interface, reporting for duty");
ANativeActivity_finish(state->activity);
}