Skip to content

Add support for Apple framework builds #2026

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ Contrib/DtexToExr/DtexToExr
*.trs
*.project
*.cproject
*.framework
*.xcframework
.DS_Store
abi_check
build/
build-win/
build-nuget/
build*/
build-win*/
build-nuget*/
*~
.vscode
docs/_test_images/
Expand Down
35 changes: 27 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ project(OpenEXR VERSION ${OPENEXR_VERSION_MAJOR}.${OPENEXR_VERSION_MINOR}.${OPEN
set(OPENEXR_VERSION_RELEASE_TYPE "-dev" CACHE STRING "Extra version tag string for OpenEXR build, such as -dev, -beta1, etc.")

set(OPENEXR_VERSION ${OpenEXR_VERSION})
set(OPENEXR_VERSION_API "${OpenEXR_VERSION_MAJOR}_${OpenEXR_VERSION_MINOR}")
set(OPENEXR_VERSION_FULL "${OPENEXR_VERSION_MAJOR}_${OPENEXR_VERSION_MINOR}_${OPENEXR_VERSION_PATCH}")
set(OPENEXR_VERSION_API "${OPENEXR_VERSION_MAJOR}_${OPENEXR_VERSION_MINOR}")

project(OpenEXR VERSION ${OPENEXR_VERSION_MAJOR}.${OPENEXR_VERSION_MINOR}.${OPENEXR_VERSION_PATCH} LANGUAGES C CXX)

# The SOVERSION (i.e. numerical component of SONAME) tracks the ABI
# version. Increment this number whenever, and only when, the ABI changes in
Expand All @@ -49,6 +52,22 @@ set(OPENEXR_LIB_VERSION "${OPENEXR_LIB_SOVERSION}.${OPENEXR_VERSION}") # e.g. "3
option(OPENEXR_INSTALL "Install OpenEXR libraries" ON)
option(OPENEXR_INSTALL_TOOLS "Install OpenEXR tools" ON)
option(OPENEXR_INSTALL_DEVELOPER_TOOLS "Install OpenEXR developer tools" OFF)
if (APPLE)
option(OPENEXR_FRAMEWORK "Build as Apple Frameworks" OFF)
endif ()

if(OPENEXR_FRAMEWORK)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to name this OPENEXR_BUILD_APPLE_FRAMEWORKS

# Define resource files for Apple Framework early to ensure scope
set(OPENEXR_RESOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/README.md"
"${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/OpenEXRConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/OpenEXRConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/OpenEXRTargets.cmake"
CACHE INTERNAL "Resource files for frameworks"
)
message(STATUS "Resource files: ${OPENEXR_RESOURCES}")
endif()

if(OPENEXR_INSTALL OR OPENEXR_INSTALL_TOOLS OR OPENEXR_INSTALL_DEVELOPER_TOOLS)
# uninstall target
Expand Down Expand Up @@ -102,6 +121,11 @@ if(OPENEXR_BUILD_EXAMPLES AND OPENEXR_BUILD_LIBS)
add_subdirectory( src/examples )
endif()

if (OPENEXR_BUILD_LIBS AND NOT OPENEXR_IS_SUBPROJECT)
Copy link
Member

@cary-ilm cary-ilm Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this moved? Better to minimize changes unless there's a specific reason.

# Even if not building the website, still make sure the website example code compiles.
add_subdirectory(website/src)
endif()

# If you want to use ctest to configure, build and
# upload the results, cmake has builtin support for
# submitting to CDash, or any server who speaks the
Expand All @@ -127,7 +151,7 @@ endif()
include(CTest)

if(BUILD_TESTING AND OPENEXR_BUILD_LIBS AND NOT OPENEXR_IS_SUBPROJECT)
add_subdirectory(src/test)
add_subplot(src/test)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is add_subplot()?

endif()

# Including this module will add a `clang-format` target to the build if
Expand All @@ -146,11 +170,6 @@ if (BUILD_WEBSITE AND NOT OPENEXR_IS_SUBPROJECT)
add_subdirectory(website)
endif()

if (OPENEXR_BUILD_LIBS AND NOT OPENEXR_IS_SUBPROJECT)
# Even if not building the website, still make sure the website example code compiles.
add_subdirectory(website/src)
endif()

if (OPENEXR_BUILD_PYTHON AND OPENEXR_BUILD_LIBS AND NOT OPENEXR_IS_SUBPROJECT)
add_subdirectory(src/wrappers/python)
endif()
endif()
50 changes: 46 additions & 4 deletions cmake/LibraryDefine.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ function(OPENEXR_DEFINE_LIBRARY libname)
C_VISIBILITY_PRESET hidden
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
)
)
else()
target_compile_definitions(${objlib} PUBLIC OPENEXR_USE_DEFAULT_VISIBILITY)
target_compile_definitions(${objlib} PUBLIC OPENEXR_USE_DEFAULT_VISIBILITY)
endif()
if (_openexr_extra_flags)
target_compile_options(${objlib} PRIVATE ${_openexr_extra_flags})
Expand All @@ -69,10 +69,31 @@ function(OPENEXR_DEFINE_LIBRARY libname)
VERSION ${OPENEXR_LIB_VERSION}
)
endif()
# Set OUTPUT_NAME to avoid suffix for frameworks
set_target_properties(${libname} PROPERTIES
OUTPUT_NAME "${libname}${OPENEXR_LIB_SUFFIX}"
OUTPUT_NAME "${libname}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output name needs the OPENEXR_LIB_SUFFIX.

RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
if(OPENEXR_FRAMEWORK)
# Mark resource files for inclusion in the framework bundle
set_source_files_properties(${OPENEXR_RESOURCES} PROPERTIES
MACOSX_PACKAGE_LOCATION Resources
)
set_target_properties(${libname} PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION "${OPENEXR_VERSION_FULL}"
PRODUCT_BUNDLE_IDENTIFIER "github.com/AcademySoftwareFoundation/openexr/${libname}"
XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
MACOSX_FRAMEWORK_IDENTIFIER "github.com/AcademySoftwareFoundation/openexr/${libname}"
MACOSX_FRAMEWORK_BUNDLE_VERSION "${OPENEXR_VERSION_FULL}"
MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${OPENEXR_VERSION_API}"
MACOSX_RPATH TRUE
)
configure_framework(${libname} "${OPENEXR_RESOURCES}")
endif()
add_library(${PROJECT_NAME}::${libname} ALIAS ${libname})

if(OPENEXR_INSTALL)
Expand All @@ -81,12 +102,18 @@ function(OPENEXR_DEFINE_LIBRARY libname)
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${OPENEXR_OUTPUT_SUBDIR}
)
if(OPENEXR_FRAMEWORK)
install(FILES ${OPENEXR_RESOURCES}
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${libname}.framework/Resources"
)
endif()
endif()
if(BUILD_SHARED_LIBS AND (NOT "${OPENEXR_LIB_SUFFIX}" STREQUAL "") AND NOT WIN32)
if(BUILD_SHARED_LIBS AND (NOT "${OPENEXR_LIB_SUFFIX}" STREQUAL "") AND NOT WIN32 AND NOT OPENEXR_FRAMEWORK)
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
set(verlibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${OPENEXR_LIB_SUFFIX}${CMAKE_${uppercase_CMAKE_BUILD_TYPE}_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX})
set(baselibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${CMAKE_${uppercase_CMAKE_BUILD_TYPE}_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX})
Expand All @@ -97,3 +124,18 @@ function(OPENEXR_DEFINE_LIBRARY libname)
set(baselibname)
endif()
endfunction()

function(configure_framework libname resources)
if(OPENEXR_FRAMEWORK)
set(RES_DEST_DIR "$<TARGET_BUNDLE_CONTENT_DIR:${libname}>/Resources")
message(STATUS "Configuring framework for ${libname}, copying resources to ${RES_DEST_DIR}")
message(STATUS "Resources to copy: ${resources}")
add_custom_command(TARGET ${libname} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${RES_DEST_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${resources} "${RES_DEST_DIR}/"
COMMAND ${CMAKE_COMMAND} -E echo "Copied resources: ${resources} to ${RES_DEST_DIR}"
COMMENT "Copying resource files to ${libname}.framework/Resources in build directory"
VERBATIM
)
endif()
endfunction()
2 changes: 1 addition & 1 deletion cmake/OpenEXRSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,4 @@ int main() {
if(NOT HAS_VLD1)
set(OPENEXR_MISSING_ARM_VLD1 TRUE)
endif()
endif()
endif()
Copy link
Member

@cary-ilm cary-ilm Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the newline?

In fact, it looks like all your edited files now lack a newline as the final character, which is odd, an artifact of your text editor, perhaps? Please add them back in.