Skip to content
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

Add support for Apple-Framework builds #1246

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ __pycache__/
*.txt.uncompressed
*.br
*.unbr

# Build
/build
/_build
/out

# OSX
*.DS_Store
48 changes: 43 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ project(brotli C)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
set(BROTLI_BUILD_TOOLS ON CACHE BOOL "Build/install CLI tools")

if(APPLE)
option(BUILD_FRAMEWORK "Build as Apple Frameworks" OFF)
endif()

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to Release as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build" FORCE)
Expand Down Expand Up @@ -92,6 +96,12 @@ set(BROTLI_LIBRARIES_CORE brotlienc brotlidec brotlicommon)
set(BROTLI_LIBRARIES ${BROTLI_LIBRARIES_CORE} ${LIBM_LIBRARY})
mark_as_advanced(BROTLI_LIBRARIES)

set(BROTLI_PUBLIC_HDRS
docs/constants.h.3
docs/decode.h.3
docs/encode.h.3
docs/types.h.3)

if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
add_definitions(-DOS_LINUX)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
Expand All @@ -107,17 +117,19 @@ if(BROTLI_EMSCRIPTEN)
endif()

file(GLOB_RECURSE BROTLI_COMMON_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} c/common/*.c)
add_library(brotlicommon ${BROTLI_COMMON_SOURCES})
add_library(brotlicommon ${BROTLI_COMMON_SOURCES} ${BROTLI_PUBLIC_HDRS})

file(GLOB_RECURSE BROTLI_DEC_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} c/dec/*.c)
add_library(brotlidec ${BROTLI_DEC_SOURCES})
add_library(brotlidec ${BROTLI_DEC_SOURCES} ${BROTLI_PUBLIC_HDRS})

file(GLOB_RECURSE BROTLI_ENC_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} c/enc/*.c)
add_library(brotlienc ${BROTLI_ENC_SOURCES})
add_library(brotlienc ${BROTLI_ENC_SOURCES} ${BROTLI_PUBLIC_HDRS})

# Older CMake versions does not understand INCLUDE_DIRECTORIES property.
include_directories(${BROTLI_INCLUDE_DIRS})

set(BROTLI_FULL_VERSION "${BROTLI_ABI_COMPATIBILITY}.${BROTLI_ABI_AGE}.${BROTLI_ABI_REVISION}")

if(BUILD_SHARED_LIBS)
foreach(lib ${BROTLI_LIBRARIES_CORE})
target_compile_definitions(${lib} PUBLIC "BROTLI_SHARED_COMPILATION" )
Expand All @@ -126,11 +138,30 @@ if(BUILD_SHARED_LIBS)
endforeach()
endif()

if(BUILD_FRAMEWORK)
foreach(lib ${BROTLI_LIBRARIES_CORE})
set_target_properties(${lib} PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION "${BROTLI_FULL_VERSION}"
PRODUCT_BUNDLE_IDENTIFIER "github.com/google/brotli/${lib}"
XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
OUTPUT_NAME "${lib}"
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
PUBLIC_HEADER "${BROTLI_PUBLIC_HDRS}"
MACOSX_FRAMEWORK_IDENTIFIER "github.com/google/brotli/${lib}"
MACOSX_FRAMEWORK_BUNDLE_VERSION "${BROTLI_FULL_VERSION}"
MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${BROTLI_ABI_COMPATIBILITY}"
MACOSX_RPATH TRUE)
endforeach()
endif()

foreach(lib ${BROTLI_LIBRARIES_CORE})
target_link_libraries(${lib} ${LIBM_LIBRARY})
set_property(TARGET ${lib} APPEND PROPERTY INCLUDE_DIRECTORIES ${BROTLI_INCLUDE_DIRS})
set_target_properties(${lib} PROPERTIES
VERSION "${BROTLI_ABI_COMPATIBILITY}.${BROTLI_ABI_AGE}.${BROTLI_ABI_REVISION}"
VERSION "${BROTLI_FULL_VERSION}"
SOVERSION "${BROTLI_ABI_COMPATIBILITY}")
if(NOT BROTLI_EMSCRIPTEN)
set_target_properties(${lib} PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
Expand Down Expand Up @@ -166,6 +197,10 @@ if(NOT BROTLI_BUNDLED_MODE)
install(
TARGETS brotli
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
FRAMEWORK DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT runtime OPTIONAL
BUNDLE DESTINATION "${CMAKE_SOURCE_DIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
endif()

Expand All @@ -174,6 +209,9 @@ if(NOT BROTLI_BUNDLED_MODE)
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
FRAMEWORK DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT runtime OPTIONAL
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

install(
Expand Down Expand Up @@ -350,7 +388,7 @@ if (BROTLI_BUILD_TOOLS)
DESTINATION "${CMAKE_INSTALL_FULL_MANDIR}/man1")
endif()

install(FILES docs/constants.h.3 docs/decode.h.3 docs/encode.h.3 docs/types.h.3
install(FILES ${BROTLI_PUBLIC_HDRS}
DESTINATION "${CMAKE_INSTALL_FULL_MANDIR}/man3")

if (ENABLE_COVERAGE STREQUAL "yes")
Expand Down