Skip to content
Merged
Changes from 6 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
60 changes: 44 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<TARGET_FILE_DIR:${libtype}>/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
Expand Down Expand Up @@ -221,6 +246,15 @@ set(LIB_INCLUDE_DIRS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_FULL_INCLUDEDIR}>)

# 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}")
Comment thread
Treata11 marked this conversation as resolved.
Outdated

# Build the static library.
if(LIBDEFLATE_BUILD_STATIC_LIB)
add_library(libdeflate_static STATIC ${LIB_SOURCES})
Expand All @@ -237,21 +271,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})
Expand All @@ -271,6 +291,7 @@ if(LIBDEFLATE_BUILD_SHARED_LIB)
PUBLIC_HEADER libdeflate.h
C_VISIBILITY_PRESET hidden
SOVERSION 0)
configure_framework(libdeflate_shared)
Comment thread
Treata11 marked this conversation as resolved.
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})
Expand All @@ -289,6 +310,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}
Expand Down Expand Up @@ -336,4 +364,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()