Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MaterialX builds on iOS #1435

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ jobs:
python: 3.11
test_shaders: ON

- name: MacOS_iOS_14_Python311
os: macos-13
compiler: xcode
compiler_version: "14.3"
python: None
cmake_config: -DMATERIALX_BUILD_IOS=ON -DMATERIALX_BUILD_PYTHON=OFF -DMATERIALX_BUILD_VIEWER=OFF -DMATERIALX_BUILD_GRAPH_EDITOR=OFF
-DCMAKE_OSX_SYSROOT=`xcrun --sdk iphoneos --show-sdk-path`
-DCMAKE_OSX_ARCHITECTURES=arm64

- name: Windows_VS2019_Win32_Python37
os: windows-2019
architecture: x86
Expand Down
25 changes: 17 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,38 @@ if (MATERIALX_BUILD_JS)
endif()
endif()

option(MATERIALX_BUILD_IOS "Build the MaterialX for iOS." OFF)
if (MATERIALX_BUILD_IOS)
set(CMAKE_SYSTEM_NAME iOS)
add_definitions(-DTARGET_OS_IOS=1)
endif()

project(MaterialX)

if(NOT MATERIALX_BUILD_IOS)
option(MATERIALX_BUILD_PYTHON "Build the MaterialX Python package from C++ bindings. Requires Python 3.6 or greater." OFF)
option(MATERIALX_BUILD_VIEWER "Build the MaterialX Viewer." OFF)
option(MATERIALX_BUILD_GRAPH_EDITOR "Build the MaterialX Graph Editor." OFF)
option(MATERIALX_BUILD_DOCS "Create HTML documentation using Doxygen. Requires that Doxygen be installed." OFF)

option(MATERIALX_BUILD_GEN_GLSL "Build the GLSL shader generator back-end." ON)
option(MATERIALX_BUILD_GEN_OSL "Build the OSL shader generator back-end." ON)
option(MATERIALX_BUILD_GEN_MDL "Build the MDL shader generator back-end." ON)
option(MATERIALX_BUILD_GEN_MSL "Build the MSL shader generator back-end." ON)
option(MATERIALX_BUILD_RENDER "Build the MaterialX Render modules." ON)
option(MATERIALX_BUILD_OIIO "Build OpenImageIO support for MaterialXRender." OFF)
option(MATERIALX_PYTHON_LTO "Enable link-time optimizations for MaterialX Python." ON)
option(MATERIALX_INSTALL_PYTHON "Install the MaterialX Python package as a third-party library when the install target is built." ON)
option(MATERIALX_DYNAMIC_ANALYSIS "Build MaterialX libraries with dynamic analysis on supporting platforms." OFF)
option(MATERIALX_OSL_LEGACY_CLOSURES "Build OSL shader generation supporting the legacy OSL closures." ON)
option(MATERIALX_BUILD_TESTS "Build unit tests." ON)
option(MATERIALX_TEST_RENDER "Run rendering tests for MaterialX Render module. GPU required for graphics validation." ON)
endif()

option(MATERIALX_BUILD_GEN_MSL "Build the MSL shader generator back-end." ON)
option(MATERIALX_BUILD_RENDER "Build the MaterialX Render modules." ON)

option(MATERIALX_BUILD_SHARED_LIBS "Build MaterialX libraries as shared rather than static." OFF)
option(MATERIALX_PYTHON_LTO "Enable link-time optimizations for MaterialX Python." ON)
option(MATERIALX_INSTALL_PYTHON "Install the MaterialX Python package as a third-party library when the install target is built." ON)

option(MATERIALX_INSTALL_RESOURCES "Install the resources folder when building render modules." ON)
option(MATERIALX_TEST_RENDER "Run rendering tests for MaterialX Render module. GPU required for graphics validation." ON)
option(MATERIALX_WARNINGS_AS_ERRORS "Interpret all compiler warnings as errors." OFF)
option(MATERIALX_DYNAMIC_ANALYSIS "Build MaterialX libraries with dynamic analysis on supporting platforms." OFF)
option(MATERIALX_OSL_LEGACY_CLOSURES "Build OSL shader generation supporting the legacy OSL closures." ON)

set(MATERIALX_PYTHON_VERSION "" CACHE STRING
"Python version to be used in building the MaterialX Python package (e.g. '3.9').")
Expand Down
9 changes: 8 additions & 1 deletion source/MaterialXRenderHw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ file(GLOB materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*")

if(APPLE)
if (NOT MATERIALX_BUILD_IOS)
find_library(COCOA_FRAMEWORK Cocoa)
endif()
file(GLOB materialx_source_oc "${CMAKE_CURRENT_SOURCE_DIR}/*.m")
message("Objective C files: " ${materialx_source_oc})
set_source_files_properties(${materialx_source_oc} PROPERTIES
Expand All @@ -26,6 +28,12 @@ add_library(${MATERIALX_MODULE_NAME} ${materialx_source} ${materialx_headers})

add_definitions(-DMATERIALX_RENDERHW_EXPORTS)

if(APPLE AND NOT MATERIALX_BUILD_IOS)
set(CMAKE_DL_LIBS
${CMAKE_DL_LIBS}
"-framework Cocoa")
endif()

# Create version resource
if(MATERIALX_BUILD_SHARED_LIBS AND MSVC)
configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/MaterialXVersion.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
Expand All @@ -43,7 +51,6 @@ elseif(APPLE)
MaterialXRender
${CMAKE_DL_LIBS}
"-framework Foundation"
"-framework Cocoa"
"-framework Metal")
elseif(UNIX)
target_link_libraries(
Expand Down
40 changes: 40 additions & 0 deletions source/MaterialXRenderHw/SimpleWindowIOS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Copyright Contributors to the MaterialX Project
// SPDX-License-Identifier: Apache-2.0
//

#if defined(__APPLE__)

#ifdef TARGET_OS_IOS

#include <MaterialXRenderHw/SimpleWindow.h>

MATERIALX_NAMESPACE_BEGIN

SimpleWindow::SimpleWindow() :
_width(0),
_height(0)
{
// Give a unique identifier to this window.
static unsigned int windowCount = 1;
_id = windowCount;
windowCount++;
}

bool SimpleWindow::initialize(const char* title,
unsigned int width, unsigned int height,
void* /*applicationShell*/)
{
_windowWrapper = WindowWrapper::create(nullptr);
return true;
}

SimpleWindow::~SimpleWindow()
{
}

MATERIALX_NAMESPACE_END

#endif

#endif
4 changes: 4 additions & 0 deletions source/MaterialXRenderHw/SimpleWindowMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#if defined(__APPLE__)

#ifndef TARGET_OS_IOS

#include <MaterialXRenderHw/SimpleWindow.h>
#include <MaterialXRenderHw/WindowCocoaWrappers.h>

Expand Down Expand Up @@ -42,3 +44,5 @@ SimpleWindow::~SimpleWindow()
MATERIALX_NAMESPACE_END

#endif

#endif
4 changes: 4 additions & 0 deletions source/MaterialXRenderHw/WindowCocoaWrappers.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#if defined (__APPLE__)

#ifndef TARGET_OS_IOS

#import <Cocoa/Cocoa.h>
#import <AppKit/NSApplication.h>
#import <MaterialXRenderHw/WindowCocoaWrappers.h>
Expand Down Expand Up @@ -72,3 +74,5 @@ void NSUtilDisposeWindow(void* pWindow)
}

#endif

#endif
4 changes: 4 additions & 0 deletions source/MaterialXRenderHw/WindowWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ WindowWrapper::WindowWrapper(ExternalWindowHandle externalHandle,
DisplayHandle display)
{
_externalHandle = externalHandle;
#ifndef TARGET_OS_IOS
// Cache a pointer to the window.
_internalHandle = NSUtilGetView(externalHandle);
#else
_internalHandle = nullptr;
#endif
}

WindowWrapper::~WindowWrapper()
Expand Down
9 changes: 8 additions & 1 deletion source/MaterialXRenderMsl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ if(POLICY CMP0072)
endif()

if(APPLE)
if(NOT MATERIALX_BUILD_IOS)
find_library(COCOA_FRAMEWORK Cocoa)
find_package(OpenGL REQUIRED)
endif()
file(GLOB_RECURSE materialx_source_oc "${CMAKE_CURRENT_SOURCE_DIR}/*.m")
message("Objective C files: " ${materialx_source_oc})
set_source_files_properties(${materialx_source_oc} PROPERTIES
Expand Down Expand Up @@ -44,6 +46,12 @@ set(COMMON_LIBRARIES
MaterialXRenderHw
MaterialXGenMsl
${CMAKE_DL_LIBS})

if(APPLE AND NOT MATERIALX_BUILD_IOS)
set(COMMON_LIBRARIES
${COMMON_LIBRARIES}
"-framework Cocoa")
endif()

if(MSVC)
target_link_libraries(
Expand All @@ -56,7 +64,6 @@ elseif(APPLE)
${COMMON_LIBRARIES}
${OPENGL_LIBRARIES}
"-framework Foundation"
"-framework Cocoa"
"-framework Metal")
elseif(UNIX)
target_link_libraries(
Expand Down