From e4fe355a20da38ec192d3b24b0d71419d2dc934a Mon Sep 17 00:00:00 2001 From: Thrita Date: Sat, 18 Jan 2025 04:41:21 +0330 Subject: [PATCH] Add iOS Cross-Compilation Support (#461) * Enable Cross-Compilation for iOS. Signed-off-by: Treata11 * Fix typo Replaced `TBB_USE_APPLE_FRAMEWORKS` with `IMATH_BUILD_APPLE_FRAMEWORKS`. Signed-off-by: Treata * Ignore macOS finder files Signed-off-by: Treata11 * Build: set FRAMEWORK property TRUE for iOS-derived builds before install Signed-off-by: Treata11 * Update Framework properties Signed-off-by: Treata11 --------- Signed-off-by: Treata11 Signed-off-by: Treata --- .gitignore | 2 ++ CMakeLists.txt | 4 ++++ config/LibraryDefine.cmake | 26 +++++++++++++++++++++---- src/Imath/CMakeLists.txt | 11 +++++++++++ src/ImathTest/CMakeLists.txt | 4 ++++ src/pybind11/PyBindImath/CMakeLists.txt | 12 ++++++++++++ 6 files changed, 55 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index a36992cf..5df1720e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ build/ _build/ _install/ + +.DS_Store \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cb90feb..9aab5f95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,10 @@ if (BUILD_WEBSITE AND NOT IMATH_IS_SUBPROJECT) add_subdirectory(website) endif() +if (APPLE) + option(IMATH_BUILD_APPLE_FRAMEWORKS "Build as Apple Frameworks" OFF) +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 diff --git a/config/LibraryDefine.cmake b/config/LibraryDefine.cmake index 576aa2e4..a507d0e2 100644 --- a/config/LibraryDefine.cmake +++ b/config/LibraryDefine.cmake @@ -84,13 +84,31 @@ function(IMATH_DEFINE_LIBRARY libname) ) add_library(${PROJECT_NAME}::${libname} ALIAS ${libname}) + if (IMATH_BUILD_APPLE_FRAMEWORKS) + set_target_properties(${libname} PROPERTIES + FRAMEWORK TRUE + FRAMEWORK_VERSION IMATH_LIB_VERSION + XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER com.AcademySoftwareFoundation.${libname} + MACOSX_FRAMEWORK_IDENTIFIER com.AcademySoftwareFoundation.${libname} + MACOSX_FRAMEWORK_BUNDLE_VERSION IMATH_LIB_VERSION + MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${Imath_VERSION}) + endif() + if (IMATH_INSTALL) install(TARGETS ${libname} EXPORT ${PROJECT_NAME} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + RUNTIME + DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY + DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE + DESTINATION ${CMAKE_INSTALL_LIBDIR} + FRAMEWORK + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT runtime + OPTIONAL + INCLUDES + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${IMATH_OUTPUT_SUBDIR} ) diff --git a/src/Imath/CMakeLists.txt b/src/Imath/CMakeLists.txt index 7990bde0..ef500115 100644 --- a/src/Imath/CMakeLists.txt +++ b/src/Imath/CMakeLists.txt @@ -47,3 +47,14 @@ imath_define_library(Imath ImathVec.h ImathVecAlgo.h ) + +if(IMATH_BUILD_APPLE_FRAMEWORKS) + set_target_properties(Imath PROPERTIES + FRAMEWORK TRUE + FRAMEWORK_VERSION IMATH_LIB_VERSION + XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER github.com/AcademySoftwareFoundation/Imath + OUTPUT_NAME "imath" + MACOSX_FRAMEWORK_IDENTIFIER github.com/AcademySoftwareFoundation/Imath + MACOSX_FRAMEWORK_BUNDLE_VERSION IMATH_LIB_VERSION + MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${Imath_VERSION}) +endif() diff --git a/src/ImathTest/CMakeLists.txt b/src/ImathTest/CMakeLists.txt index 58820316..5ffaf0a3 100644 --- a/src/ImathTest/CMakeLists.txt +++ b/src/ImathTest/CMakeLists.txt @@ -84,6 +84,10 @@ function(DEFINE_IMATH_TESTS) endforeach() endfunction() +if (IMATH_BUILD_APPLE_FRAMEWORKS) + add_compile_definitions(IMATH_BUILD_APPLE_FRAMEWORKS) +endif() + define_imath_tests( testToFloat testSize diff --git a/src/pybind11/PyBindImath/CMakeLists.txt b/src/pybind11/PyBindImath/CMakeLists.txt index 15473c69..511abb86 100644 --- a/src/pybind11/PyBindImath/CMakeLists.txt +++ b/src/pybind11/PyBindImath/CMakeLists.txt @@ -78,6 +78,7 @@ if (IMATH_INSTALL) 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}) if(BUILD_SHARED_LIBS AND (NOT "${IMATH_LIB_SUFFIX}" STREQUAL "") AND IMATH_INSTALL_SYM_LINK) @@ -109,3 +110,14 @@ if (IMATH_INSTALL) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${pcout} DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endif() + +if(IMATH_BUILD_APPLE_FRAMEWORKS) + set_target_properties(${PYBINDIMATH_LIBRARY} PROPERTIES + FRAMEWORK TRUE + FRAMEWORK_VERSION PYBINDIMATH_LIB_SUFFIX + XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER github.com/AcademySoftwareFoundation/Imath.PyBind + # OUTPUT_NAME "pybind" + MACOSX_FRAMEWORK_IDENTIFIER github.com/AcademySoftwareFoundation/Imath.PyBind + MACOSX_FRAMEWORK_BUNDLE_VERSION PYBINDIMATH_LIB_SUFFIX + MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${Imath_VERSION}) +endif() \ No newline at end of file