Commit 9c744b13 authored by Brad King's avatar Brad King

Android: Port build system to CMake 3.7 capabilities

CMake 3.7 adds support for cross-compiling to Android without a complex
toolchain file.  Port our main CMake build system to work without the
`android.toolchain.cmake` file:

```
$ cmake ../VTK \
    -DCMAKE_SYSTEM_NAME=Android \
    -DCMAKE_ANDROID_NDK=/path/to/ndk \
    -DVTKCompileTools_DIR=/path/to/vtk-compile-tools \
    -DOPENGL_ES_VERSION=3.0 \
    -DVTK_Group_StandAlone=OFF
```
parent c7d54635
Pipeline #30203 passed with stage
......@@ -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
)
......
......@@ -309,8 +309,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
......@@ -360,7 +359,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