Commit d4623bd9 authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'update-android-build'

b7308935 Android: Remove unused toolchain file
982ba05a Android: Port superbuild to CMake 3.7 capabilities
971c3705 Android: Simplify superbuild compile tools target build
fc19439b Android: Require CMake 3.7 for superbuild
9c744b13 Android: Port build system to CMake 3.7 capabilities
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Ken Martin's avatarKen Martin <ken.martin@kitware.com>
Merge-request: !2062
parents b85de06d b7308935
This diff is collapsed.
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION "@_ANDROID_API@")
set(CMAKE_ANDROID_ARCH_ABI "@_ANDROID_ABI@")
set(CMAKE_ANDROID_NDK "@ANDROID_NDK@")
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
#
# Instructions:
# 1. Download and install the Android NDK.
......@@ -24,7 +26,7 @@ else()
set(ANDROID_NDK "/opt/android-ndk" CACHE PATH "Path to the Android NDK")
endif()
set(ANDROID_NATIVE_API_LEVEL "21" CACHE STRING "Android Native API Level")
set(ANDROID_ARCH_NAME "arm" CACHE STRING "Target Android architecture")
set(ANDROID_ARCH_ABI "armeabi" CACHE STRING "Target Android architecture/abi")
# find android
find_program(ANDROID_EXECUTABLE
......@@ -49,20 +51,6 @@ if (NOT EXISTS ${CMAKE_INSTALL_PREFIX})
"Install path ${CMAKE_INSTALL_PREFIX} does not exist.")
endif()
# First, determine how to build
if (CMAKE_GENERATOR MATCHES "NMake Makefiles")
set(VTK_BUILD_COMMAND BUILD_COMMAND nmake)
elseif (CMAKE_GENERATOR MATCHES "Ninja")
set(VTK_BUILD_COMMAND BUILD_COMMAND ninja)
else()
set(VTK_BUILD_COMMAND BUILD_COMMAND make)
endif()
set(BUILD_ALWAYS_STRING)
if(${CMAKE_VERSION} GREATER 3.0)
set(BUILD_ALWAYS_STRING BUILD_ALWAYS 1)
endif()
# Compile a minimal VTK for its compile tools
macro(compile_vtk_tools)
ExternalProject_Add(
......@@ -71,8 +59,8 @@ macro(compile_vtk_tools)
PREFIX ${CMAKE_BINARY_DIR}/CompileTools
BINARY_DIR ${CMAKE_BINARY_DIR}/CompileTools
INSTALL_COMMAND ""
${VTK_BUILD_COMMAND} vtkCompileTools
${BUILD_ALWAYS_STRING}
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIGURATION> --target vtkCompileTools
BUILD_ALWAYS 1
CMAKE_CACHE_ARGS
-DCMAKE_BUILD_TYPE:STRING=Release
-DVTK_BUILD_ALL_MODULES:BOOL=OFF
......@@ -87,21 +75,15 @@ compile_vtk_tools()
# Hide some CMake configs from the user
mark_as_advanced(
VTK_IOS_BUILD
BUILD_SHARED_LIBS
CMAKE_INSTALL_PREFIX
CMAKE_OSX_ARCHITECTURES
CMAKE_OSX_DEPLOYMENT_TARGET
CMAKE_OSX_ROOT
VTK_RENDERING_BACKEND
)
# Now cross-compile VTK with the android toolchain
set(android_cmake_flags
-DANDROID_NDK:PATH=${ANDROID_NDK}
-DANDROID_NATIVE_API_LEVEL:STRING=${ANDROID_NATIVE_API_LEVEL}
-DANDROID_DEFAULT_NDK_API_LEVEL:STRING=${ANDROID_NATIVE_API_LEVEL}
-DANDROID_ARCH_NAME:STRING=${ANDROID_ARCH_NAME}
-DANDROID_EXECUTABLE:FILE=${ANDROID_EXECUTABLE}
-DANT_EXECUTABLE:FILE=${ANT_EXECUTABLE}
-DBUILD_SHARED_LIBS:BOOL=OFF
......@@ -142,29 +124,35 @@ if (OPENGL_ES_VERSION STREQUAL "3.0")
)
endif()
macro(crosscompile target toolchain_file)
macro(crosscompile target api abi out_build_dir)
set(_ANDROID_API "${api}")
set(_ANDROID_ABI "${abi}")
set(_ANDROID_DIR "${target}-${api}-${abi}")
set(_ANDROID_TOOLCHAIN ${BUILD_DIR}/${_ANDROID_DIR}-toolchain.cmake)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMake/vtkAndroid-toolchain.cmake.in
${_ANDROID_TOOLCHAIN} @ONLY)
ExternalProject_Add(
${target}
SOURCE_DIR ${CMAKE_SOURCE_DIR}
PREFIX ${PREFIX_DIR}/${target}
BINARY_DIR ${BUILD_DIR}/${target}
INSTALL_DIR ${INSTALL_DIR}/${target}
PREFIX ${PREFIX_DIR}/${_ANDROID_DIR}
BINARY_DIR ${BUILD_DIR}/${_ANDROID_DIR}
INSTALL_DIR ${INSTALL_DIR}/${_ANDROID_DIR}
DEPENDS vtk-compile-tools
${BUILD_ALWAYS_STRING}
BUILD_ALWAYS 1
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_DIR}/${target}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_TOOLCHAIN_FILE:PATH=CMake/${toolchain_file}
-DANDROID_NDK:PATH=${ANDROID_NDK}
-DCMAKE_TOOLCHAIN_FILE:PATH=${_ANDROID_TOOLCHAIN}
-DVTKCompileTools_DIR:PATH=${CMAKE_BINARY_DIR}/CompileTools
${android_cmake_flags}
)
set(${out_build_dir} "${BUILD_DIR}/${_ANDROID_DIR}")
endmacro()
crosscompile(vtk-android android.toolchain.cmake)
crosscompile(vtk-android "${ANDROID_NATIVE_API_LEVEL}" "${ANDROID_ARCH_ABI}" vtk_android_build_dir)
add_test(NAME AndroidNative
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeExternals/Build/vtk-android/Examples/Android/NativeVTK/bin
WORKING_DIRECTORY ${vtk_android_build_dir}/Examples/Android/NativeVTK/bin
COMMAND ${CMAKE_COMMAND}
-DWORKINGDIR=${CMAKE_CURRENT_BINARY_DIR}/CMakeExternals/Build/vtk-android/Examples/Android/NativeVTK/bin
-DWORKINGDIR=${vtk_android_build_dir}/Examples/Android/NativeVTK/bin
-P ${CMAKE_CURRENT_SOURCE_DIR}/Examples/Android/NativeVTK/runtest.cmake
)
......@@ -27,6 +27,10 @@ if(NOT DEFINED CMAKE_MACOSX_RPATH)
set(CMAKE_MACOSX_RPATH 0)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Android" AND CMAKE_VERSION VERSION_LESS 3.7)
message(FATAL_ERROR "CMake 3.7 or above is required to build for Android")
endif()
project(VTK)
if (NOT CMAKE_VERSION VERSION_LESS "3.1")
......@@ -152,20 +156,20 @@ if (ANDROID OR APPLE_IOS)
CACHE STRING "Output from TRY_RUN" FORCE)
# need int version for CPP
if (${OPENGL_ES_VERSION} MATCHES 2.0)
if (OPENGL_ES_VERSION STREQUAL "2.0")
set(OPENGL_ES_VERSION_INT 20)
endif()
if (${OPENGL_ES_VERSION} MATCHES 3.0)
if (OPENGL_ES_VERSION STREQUAL "3.0")
set(OPENGL_ES_VERSION_INT 30)
endif()
if (APPLE_IOS)
unset(OPENGL_INCLUDE_DIR CACHE)
if (${OPENGL_ES_VERSION} MATCHES 2.0)
if (OPENGL_ES_VERSION STREQUAL "2.0")
find_path(OPENGL_INCLUDE_DIR ES2/gl.h
${CMAKE_OSX_SYSROOT}/System/Library/Frameworks/OpenGLES.framework/Headers
${_OPENGL_INCLUDE_DIR})
elseif (${OPENGL_ES_VERSION} MATCHES 3.0)
elseif (OPENGL_ES_VERSION STREQUAL "3.0")
find_path(OPENGL_INCLUDE_DIR ES3/gl.h
${CMAKE_OSX_SYSROOT}/System/Library/Frameworks/OpenGLES.framework/Headers
${_OPENGL_INCLUDE_DIR})
......@@ -181,36 +185,14 @@ if (ANDROID OR APPLE_IOS)
unset(OPENGL_gl_LIBRARY CACHE)
unset(OPENGL_egl_LIBRARY CACHE)
if (${OPENGL_ES_VERSION} MATCHES 2.0)
find_path(OPENGL_INCLUDE_DIR GLES2/gl2.h
${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include
${_OPENGL_INCLUDE_PATH}
NO_DEFAULT_PATH
)
find_library(OPENGL_gl_LIBRARY
NAMES GLESv2
PATHS
${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/lib
${_OPENGL_LIB_PATH}
)
elseif (${OPENGL_ES_VERSION} MATCHES 3.0)
find_path(OPENGL_INCLUDE_DIR GLES3/gl3.h
${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include
${_OPENGL_INCLUDE_PATH}
)
find_library(OPENGL_gl_LIBRARY
NAMES GLESv3
PATHS
${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/lib
${_OPENGL_LIB_PATH}
)
if (OPENGL_ES_VERSION STREQUAL "2.0")
find_path(OPENGL_INCLUDE_DIR GLES2/gl2.h)
find_library(OPENGL_gl_LIBRARY NAMES GLESv2)
elseif (OPENGL_ES_VERSION STREQUAL "3.0")
find_path(OPENGL_INCLUDE_DIR GLES3/gl3.h)
find_library(OPENGL_gl_LIBRARY NAMES GLESv3)
endif()
find_library(OPENGL_egl_LIBRARY
NAMES EGL
PATHS
${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/lib
${_OPENGL_LIB_PATH}
)
find_library(OPENGL_egl_LIBRARY NAMES EGL)
endif()
else()
# Choose static or shared libraries.
......
......@@ -720,3 +720,7 @@ endif()
vtk_module_library(vtkCommonCore ${Module_SRCS})
vtk_module_link_libraries(vtkCommonCore LINK_PRIVATE ${CMAKE_THREAD_LIBS} LINK_PUBLIC ${VTK_SMP_IMPLEMENTATION_LIBRARIES})
if(ANDROID)
target_link_libraries(vtkCommonCore LINK_PRIVATE log)
endif()
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.7)
project(JavaVTK)
if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
......@@ -12,7 +12,7 @@ find_package(VTK COMPONENTS
)
include(${VTK_USE_FILE})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libs/${ANDROID_NDK_ABI_NAME})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libs/${CMAKE_ANDROID_ARCH_ABI})
message(${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
add_subdirectory(jni)
......@@ -39,7 +39,7 @@ add_custom_target(JavaVTK-ant-configure ALL
update project
--name JavaVTK
--path "${CMAKE_CURRENT_SOURCE_DIR}"
--target "android-${ANDROID_NATIVE_API_LEVEL}"
--target "android-${CMAKE_SYSTEM_VERSION}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/build.xml"
"${CMAKE_CURRENT_BINARY_DIR}/build.xml"
......
include_directories(
"${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include"
)
set(sources
main.cxx
)
......
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.7)
project(NativeVTK)
if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
......@@ -14,7 +14,7 @@ find_package(VTK COMPONENTS
)
include(${VTK_USE_FILE})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libs/${ANDROID_NDK_ABI_NAME})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libs/${CMAKE_ANDROID_ARCH_ABI})
message(${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
add_subdirectory(jni)
......@@ -41,7 +41,7 @@ add_custom_target(NativeVTK-ant-configure ALL
update project
--name NativeVTK
--path "${CMAKE_CURRENT_SOURCE_DIR}"
--target "android-${ANDROID_NATIVE_API_LEVEL}"
--target "android-${CMAKE_SYSTEM_VERSION}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/build.xml"
"${CMAKE_CURRENT_BINARY_DIR}/build.xml"
......
include_directories(
"${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include"
"${ANDROID_NDK}/sources/android/native_app_glue"
"${CMAKE_ANDROID_NDK}/sources/android/native_app_glue"
)
set(sources
main.cxx
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c
${CMAKE_ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c
)
add_library(NativeVTK SHARED ${sources})
......
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.7)
project(VolumeRender)
if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
......@@ -13,7 +13,7 @@ find_package(VTK COMPONENTS
)
include(${VTK_USE_FILE})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libs/${ANDROID_NDK_ABI_NAME})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libs/${CMAKE_ANDROID_ARCH_ABI})
message(${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
add_subdirectory(jni)
......@@ -40,7 +40,7 @@ add_custom_target(VolumeRender-ant-configure ALL
update project
--name VolumeRender
--path "${CMAKE_CURRENT_SOURCE_DIR}"
--target "android-${ANDROID_NATIVE_API_LEVEL}"
--target "android-${CMAKE_SYSTEM_VERSION}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/build.xml"
"${CMAKE_CURRENT_BINARY_DIR}/build.xml"
......
include_directories(
"${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include"
)
set(sources
main.cxx
)
......
......@@ -310,8 +310,7 @@ elseif(ANDROID)
vtkEGLRenderWindow.cxx
)
include_directories(
"${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include"
"${ANDROID_NDK}/sources/android/native_app_glue"
"${CMAKE_ANDROID_NDK}/sources/android/native_app_glue"
)
elseif(APPLE_IOS)
# Add some custom overrides
......@@ -361,7 +360,9 @@ endif()
if(ANDROID)
target_link_libraries(${vtk-module}
LINK_PUBLIC ${OPENGL_egl_LIBRARY})
LINK_PUBLIC ${OPENGL_egl_LIBRARY}
LINK_PRIVATE android
)
endif()
if (APPLE_IOS)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment