Commit d9d3fc3b authored by Tim Thirion's avatar Tim Thirion

Create iOS framework in one pass through CMake config

First, build VTK for vtkCompileTools. Then build two more times, once for all
device architectures and once for all simulator architectures.

When the user specifies -DVTK_IOS_BUILD=ON, the following options are presented:

CMAKE_FRAMEWORK_INSTALL_PREFIX - final location of vtk.framework
IOS_DEVICE_ARCHITECTURES - device architectures, e.g., arm64
IOS_SIMULATOR_ARCHITECTURES - simulator architectures, e.g. x86_64
OPENGL_ES_VERSION - 2.0 or 3.0

Future commits will improve the available options and hide more unnecessary
ones.

Change-Id: Id27e547e3758e186ec85502dbb12cdb63ab8539c
parent a8d8b475
file(GLOB INSTALLED_VTK_LIBS
"@CMAKE_INSTALL_PREFIX@/lib/libvtk*.a")
set(FRAMEWORK_PATH
"@CMAKE_FRAMEWORK_INSTALL_PREFIX@/vtk.framework")
set(INSTALLED_HEADERS
"@CMAKE_INSTALL_PREFIX@/@VTK_INSTALL_INCLUDE_DIR@")
#
# Before calling this, ensure that the following variables are set:
#
# VTK_DEVICE_LIBS - a path containing a wildcard suitable for globbing
# VTK_SIMULATOR_LIBS - a path containing a wildcard suitable for globbing
# VTK_INSTALLED_HEADERS - the path containing all headers for the framework
# CMAKE_FRAMEWORK_INSTALL_PREFIX - the path in which to make vtk.framework
#
# Make sure VTK is installed.
if (NOT EXISTS ${INSTALLED_HEADERS})
if (NOT EXISTS @VTK_INSTALLED_HEADERS@)
message(FATAL_ERROR
"VTK not installed. Build the source then build the 'install' target.")
endif()
# Ensure a framework path is set
if (NOT EXISTS @CMAKE_FRAMEWORK_INSTALL_PREFIX@)
message(FATAL_ERROR
"Please specifiy a CMAKE_FRAMEWORK_INSTALL_PREFIX.")
endif()
# Glob all input libs
file(GLOB VTK_LIB_GLOB
"@VTK_DEVICE_LIBS@"
"@VTK_SIMULATOR_LIBS@"
)
# Set framework output path
set(FRAMEWORK_PATH "@CMAKE_FRAMEWORK_INSTALL_PREFIX@/vtk.framework")
# Do these individually, as we don't want them piped
execute_process(COMMAND mkdir -p "${FRAMEWORK_PATH}")
execute_process(COMMAND mkdir -p "${FRAMEWORK_PATH}/Headers")
execute_process(COMMAND cp -r "${INSTALLED_HEADERS}/"
execute_process(COMMAND cp -r "@VTK_INSTALLED_HEADERS@/"
"${FRAMEWORK_PATH}/Headers/.")
execute_process(COMMAND libtool -static -o
"${FRAMEWORK_PATH}/lib_device"
${INSTALLED_VTK_LIBS})
execute_process(COMMAND lipo -create "${FRAMEWORK_PATH}/lib_device"
"${FRAMEWORK_PATH}/vtk_lib"
${VTK_LIB_GLOB})
execute_process(COMMAND lipo -create "${FRAMEWORK_PATH}/vtk_lib"
-output "${FRAMEWORK_PATH}/vtk")
execute_process(COMMAND rm "${FRAMEWORK_PATH}/lib_device")
execute_process(COMMAND rm "${FRAMEWORK_PATH}/vtk_lib")
message(STATUS "Created ${FRAMEWORK_PATH}")
message(STATUS "Created ${FRAMEWORK_PATH}")
\ No newline at end of file
include(ExternalProject)
# Convenience variables
set(PREFIX_DIR ${CMAKE_BINARY_DIR}/CMakeExternals/Prefix)
set(BUILD_DIR ${CMAKE_BINARY_DIR}/CMakeExternals/Build)
set(INSTALL_DIR ${CMAKE_BINARY_DIR}/CMakeExternals/Install)
# 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()
# Compile a minimal VTK for its compile tools
macro(compile_vtk_tools)
ExternalProject_Add(
vtk-compile-tools
SOURCE_DIR ${CMAKE_SOURCE_DIR}
PREFIX ${PREFIX_DIR}/vtk-compile-tools
BINARY_DIR ${BUILD_DIR}/vtk-compile-tools
${VTK_BUILD_COMMAND} vtkCompileTools
CMAKE_ARGS
-DCMAKE_BUILD_TYPE:STRING=Release
-DVTK_BUILD_ALL_MODULES:BOOL=OFF
-DVTK_Group_Rendering:BOOL=OFF
-DVTK_Group_StandAlone:BOOL=ON
-DBUILD_SHARED_LIBS:BOOL=ON
-DBUILD_EXAMPLES:BOOL=OFF
-DBUILD_TESTING:BOOL=OFF
)
endmacro()
compile_vtk_tools()
# Okay, now set options for iOS
set(OPENGL_ES_VERSION "2.0" CACHE STRING "OpenGL ES version (2.0 or 3.0)")
set_property(CACHE OPENGL_ES_VERSION PROPERTY STRINGS 2.0 3.0)
set(IOS_SIMULATOR_ARCHITECTURES "i386;x86_64"
CACHE STRING "iOS Simulator Architectures")
set(IOS_DEVICE_ARCHITECTURES "arm64;armv7;armv7s"
CACHE STRING "iOS Device Architectures")
set(CMAKE_FRAMEWORK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/frameworks"
CACHE PATH "Framework install path")
# Hide some CMake configs from the user
mark_as_advanced(
BUILD_SHARED_LIBS
CMAKE_INSTALL_PREFIX
CMAKE_OSX_ARCHITECTURES
CMAKE_OSX_DEPLOYMENT_TARGET
CMAKE_OSX_ROOT
VTK_RENDERING_BACKEND
)
# Now cross-compile VTK with custom toolchains
set(ios_cmake_flags
-DBUILD_SHARED_LIBS:BOOL=OFF
-DBUILD_TESTING:BOOL=OFF
-DBUILD_EXAMPLES:BOOL=ON
-DVTK_RENDERING_BACKEND:STRING=OpenGL2
-DVTK_Group_Rendering:BOOL=OFF
-DVTK_Group_StandAlone:BOOL=OFF
-DVTK_Group_Imaging:BOOL=OFF
-DVTK_Group_MPI:BOOL=OFF
-DVTK_Group_Views:BOOL=OFF
-DVTK_Group_Qt:BOOL=OFF
-DVTK_Group_Tk:BOOL=OFF
-DVTK_Group_Web:BOOL=OFF
-DModule_vtkFiltersCore:BOOL=ON
-DModule_vtkFiltersModeling:BOOL=ON
-DModule_vtkFiltersSources:BOOL=ON
-DModule_vtkFiltersGeometry:BOOL=ON
-DModule_vtkIOGeometry:BOOL=ON
-DModule_vtkIOLegacy:BOOL=ON
-DModule_vtkIOImage:BOOL=ON
-DModule_vtkIOPLY:BOOL=ON
-DModule_vtkIOInfovis:BOOL=ON
-DModule_vtkImagingCore:BOOL=ON
-DModule_vtkParallelCore:BOOL=ON
-DModule_vtkRenderingCore:BOOL=ON
-DModule_vtkRenderingFreeType:BOOL=OFF
)
macro(crosscompile target toolchain_file archs)
ExternalProject_Add(
vtk-${target}
SOURCE_DIR ${CMAKE_SOURCE_DIR}
PREFIX ${PREFIX_DIR}/vtk-${target}
BINARY_DIR ${BUILD_DIR}/vtk-${target}
INSTALL_DIR ${INSTALL_DIR}/vtk-${target}
DEPENDS vtk-compile-tools
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_DIR}/vtk-${target}
-DCMAKE_CROSSCOMPILING:BOOL=ON
#-DCMAKE_OSX_ARCHITECTURES:STRING=${archs}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_TOOLCHAIN_FILE:FILEPATH=CMake/${toolchain_file}
-DVTKCompileTools_DIR:PATH=${BUILD_DIR}/vtk-compile-tools
${ios_cmake_flags}
)
endmacro()
crosscompile(ios-simulator
ios.simulator.toolchain.cmake
"${IOS_SIMULATOR_ARCHITECTURES}"
)
crosscompile(ios-device
ios.device.toolchain.cmake
"${IOS_DEVICE_ARCHITECTURES}"
)
# Pile it all into a framework
set(VTK_DEVICE_LIBS
"${INSTALL_DIR}/vtk-ios-device/lib/libvtk*.a")
set(VTK_SIMULATOR_LIBS
"${INSTALL_DIR}/vtk-ios-simulator/lib/libvtk*.a")
set(VTK_INSTALLED_HEADERS
"${INSTALL_DIR}/vtk-ios-device/${VTK_INSTALL_INCLUDE_DIR}")
configure_file(CMake/MakeFramework.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/CMake/MakeFramework.cmake
@ONLY)
add_custom_target(vtk-framework ALL COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/CMake/MakeFramework.cmake)
......@@ -82,6 +82,12 @@ mark_as_advanced(CMAKE_RUNTIME_OUTPUT_DIRECTORY
CMAKE_ARCHIVE_OUTPUT_DIRECTORY
)
option(VTK_IOS_BUILD "Build vtk.framework for iOS" OFF)
if (VTK_IOS_BUILD)
include(vtkiOS)
return()
endif()
# some specific defaults for Andriod to give folks
# a reasonable starting point
if (ANDROID OR APPLE_IOS)
......@@ -124,7 +130,6 @@ if (ANDROID OR APPLE_IOS)
endif()
if (APPLE_IOS)
option(Module_vtkInteractionStyle "needed for multitouch" ON)
unset(OPENGL_INCLUDE_DIR CACHE)
if (${OPENGL_ES_VERSION} MATCHES 2.0)
find_path(OPENGL_INCLUDE_DIR ES2/gl.h
......@@ -523,17 +528,6 @@ endforeach()
configure_file("${VTK_CMAKE_DIR}/CTestCustom.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake" @ONLY)
# For iOS builds, allow user to 'make framework' with a custom destination
if (APPLE_IOS)
set(CMAKE_FRAMEWORK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/frameworks"
CACHE PATH "Framework install path")
configure_file(${VTK_CMAKE_DIR}/MakeFramework.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/CMake/MakeFramework.cmake
@ONLY)
add_custom_target(framework COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/CMake/MakeFramework.cmake)
endif()
#-----------------------------------------------------------------------------
# Export all targets at once from the build tree in their final configuration.
get_property(_vtk_targets GLOBAL PROPERTY VTK_TARGETS)
......
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