diff --git a/.gitignore b/.gitignore index 9fbfa4fc0..a4e1096d3 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 582243484..666f7aea8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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) + # 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 @@ -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) + # 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 @@ -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) endif() # Including this module will add a `clang-format` target to the build if @@ -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() \ No newline at end of file diff --git a/cmake/LibraryDefine.cmake b/cmake/LibraryDefine.cmake index 39e737d75..2803e17d5 100644 --- a/cmake/LibraryDefine.cmake +++ b/cmake/LibraryDefine.cmake @@ -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}) @@ -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}" 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) @@ -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}) @@ -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 "$/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() \ No newline at end of file diff --git a/cmake/OpenEXRSetup.cmake b/cmake/OpenEXRSetup.cmake index 26b1d87be..dec17c762 100644 --- a/cmake/OpenEXRSetup.cmake +++ b/cmake/OpenEXRSetup.cmake @@ -384,4 +384,4 @@ int main() { if(NOT HAS_VLD1) set(OPENEXR_MISSING_ARM_VLD1 TRUE) endif() -endif() +endif() \ No newline at end of file