diff --git a/CMakeLists.txt b/CMakeLists.txt index e9641759..f7c615af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,31 @@ if(LIBDEFLATE_FREESTANDING) add_definitions(-DFREESTANDING) endif() +function(configure_framework libtype) + if(LIBDEFLATE_APPLE_FRAMEWORK) + set_target_properties(${libtype} PROPERTIES + FRAMEWORK TRUE + FRAMEWORK_VERSION "${VERSION_STRING}" + PRODUCT_BUNDLE_IDENTIFIER "github.com/ebiggers/libdeflate/${libtype}" + 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/ebiggers/libdeflate/${libtype}" + MACOSX_FRAMEWORK_BUNDLE_VERSION "${VERSION_STRING}" + MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${PROJECT_VERSION}" + MACOSX_RPATH TRUE + ) + + set(RES_DEST_DIR "$/Resources") + add_custom_command(TARGET ${libtype} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory "${RES_DEST_DIR}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LIBDEFLATE_RESOURCES} "${RES_DEST_DIR}/" + COMMENT "Copying resource files to ${libtype}.framework/Resources" + ) + endif() +endfunction() + # Check for cases where the compiler supports an instruction set extension but # the assembler does not, and in those cases print a warning and add an # appropriate -DLIBDEFLATE_ASSEMBLER_DOES_NOT_SUPPORT_* flag. libdeflate's C @@ -221,6 +246,17 @@ set(LIB_INCLUDE_DIRS $ $) +if(LIBDEFLATE_APPLE_FRAMEWORK) +# Define resource files for Apple Framework + set(LIBDEFLATE_RESOURCES + "${CMAKE_CURRENT_SOURCE_DIR}/README.md" + "${CMAKE_CURRENT_SOURCE_DIR}/COPYING" + "${CMAKE_CURRENT_BINARY_DIR}/libdeflate-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/libdeflate-targets.cmake" + ) + message(STATUS "Resource files: ${LIBDEFLATE_RESOURCES}") +endif() + # Build the static library. if(LIBDEFLATE_BUILD_STATIC_LIB) add_library(libdeflate_static STATIC ${LIB_SOURCES}) @@ -237,21 +273,7 @@ if(LIBDEFLATE_BUILD_STATIC_LIB) set_target_properties(libdeflate_static PROPERTIES OUTPUT_NAME ${STATIC_LIB_NAME} PUBLIC_HEADER libdeflate.h) - if(LIBDEFLATE_APPLE_FRAMEWORK) - set_target_properties(libdeflate_static PROPERTIES - FRAMEWORK TRUE - FRAMEWORK_VERSION "${VERSION_STRING}" - PRODUCT_BUNDLE_IDENTIFIER "github.com/ebiggers/libdeflate" - 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/ebiggers/libdeflate" - MACOSX_FRAMEWORK_BUNDLE_VERSION "${VERSION_STRING}" - MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${PROJECT_VERSION}" - MACOSX_RPATH TRUE) - endif() - + configure_framework(libdeflate_static) target_include_directories(libdeflate_static PUBLIC ${LIB_INCLUDE_DIRS}) target_compile_definitions(libdeflate_static PRIVATE ${LIB_COMPILE_DEFINITIONS}) target_compile_options(libdeflate_static PRIVATE ${LIB_COMPILE_OPTIONS}) @@ -271,6 +293,7 @@ if(LIBDEFLATE_BUILD_SHARED_LIB) PUBLIC_HEADER libdeflate.h C_VISIBILITY_PRESET hidden SOVERSION 0) + configure_framework(libdeflate_shared) target_include_directories(libdeflate_shared PUBLIC ${LIB_INCLUDE_DIRS}) target_compile_definitions(libdeflate_shared PUBLIC LIBDEFLATE_DLL) target_compile_definitions(libdeflate_shared PRIVATE ${LIB_COMPILE_DEFINITIONS}) @@ -289,6 +312,13 @@ install(TARGETS ${LIB_TARGETS} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +# Install resource files to Resources/ directory in the framework +if(LIBDEFLATE_APPLE_FRAMEWORK) + install(FILES ${LIBDEFLATE_RESOURCES} + DESTINATION "${CMAKE_INSTALL_LIBDIR}/libdeflate_static.framework/Resources" + ) +endif() + # Generate and install the pkg-config file. (Don't confuse this with the CMake # package config file, which is CMake-specific.) Take care to define the # include and lib directories in terms of the ${prefix} and ${exec_prefix} @@ -336,4 +366,4 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libdeflate-config.cmake # Build the programs subdirectory if needed. if(LIBDEFLATE_BUILD_GZIP OR LIBDEFLATE_BUILD_TESTS) add_subdirectory(programs) -endif() +endif() \ No newline at end of file