Skip to content

Commit

Permalink
Find package targets (#193)
Browse files Browse the repository at this point in the history
* improving the install with proper internal target definitions, allowing fallback if not using bundled

* documentation
  • Loading branch information
galkahana authored Feb 17, 2023
1 parent 5ff0956 commit f3fa6fc
Show file tree
Hide file tree
Showing 11 changed files with 360 additions and 166 deletions.
155 changes: 124 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,154 @@ cmake_minimum_required(VERSION 3.15)
# Soname
# MAJOR is incremented when symbols are removed or changed in an incompatible way
# MINOR is incremented when new symbols are added
project(PDFHummus VERSION 1.0)
project(PDFHummus VERSION 4.5)


option(USE_BUNDLED "Whether to use bundled libraries" TRUE)
option(USE_UNBUNDLED_FALLBACK_BUNDLED "When USE_BUNDLED is false and a certain system library is not available should fallback on bundled lib")
option(PDFHUMMUS_NO_DCT "Whether to drop support for DCT streams parsing (will not use LibJpeg)")
option(PDFHUMMUS_NO_TIFF "Whether to drop TIFF Images support (will not use LibTiff)" )
option(PDFHUMMUS_NO_PNG "Whether to drop PNG Images support (will not use LibPng)" )

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

if(NOT USE_BUNDLED)
FIND_PACKAGE(PkgConfig)

find_package (JPEG)
if (NOT JPEG_FOUND)
set (PDFHUMMUS_NO_DCT TRUE)
endif (NOT JPEG_FOUND)
# zlib
if(USE_UNBUNDLED_FALLBACK_BUNDLED)
find_package (ZLIB)
if(ZLIB_FOUND)
set (USING_UNBUNDLED_ZLIB TRUE)
else(ZLIB_FOUND)
ADD_SUBDIRECTORY(ZLib)
endif(ZLIB_FOUND)
else(USE_UNBUNDLED_FALLBACK_BUNDLED)
find_package (ZLIB REQUIRED)
set (USING_UNBUNDLED_ZLIB TRUE)
endif(USE_UNBUNDLED_FALLBACK_BUNDLED)
if(USING_UNBUNDLED_ZLIB)
set(PDFHUMMUS_DEPENDS_ZLIB "find_dependency(ZLIB)")
endif()

# freetype
if(USE_UNBUNDLED_FALLBACK_BUNDLED)
find_package (Freetype)
if(Freetype_FOUND)
set (USING_UNBUNDLED_Freetype TRUE)
else(Freetype_FOUND)
ADD_SUBDIRECTORY(FreeType)
endif(Freetype_FOUND)
else(USE_UNBUNDLED_FALLBACK_BUNDLED)
find_package (Freetype REQUIRED)
set (USING_UNBUNDLED_Freetype TRUE)
endif(USE_UNBUNDLED_FALLBACK_BUNDLED)
if(USING_UNBUNDLED_Freetype)
set(PDFHUMMUS_DEPENDS_FREETYPE "find_dependency(Freetype)")
endif()


# libaesgm
if(USE_UNBUNDLED_FALLBACK_BUNDLED)
find_package (Aesgm)
if(aesgm_FOUND)
set (USING_UNBUNDLED_aesgm TRUE)
else(aesgm_FOUND)
ADD_SUBDIRECTORY(LibAesgm)
endif(aesgm_FOUND)
else(USE_UNBUNDLED_FALLBACK_BUNDLED)
find_package (Aesgm REQUIRED)
set (USING_UNBUNDLED_aesgm TRUE)
endif(USE_UNBUNDLED_FALLBACK_BUNDLED)
if(USING_UNBUNDLED_aesgm)
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindAesgm.cmake
DESTINATION lib/cmake/PDFHummus/cmake
)
set(PDFHUMMUS_APPEND_MODULE "list(APPEND CMAKE_MODULE_PATH \"${CMAKE_CURRENT_LIST_DIR}/cmake\")")
set(PDFHUMMUS_DEPENDS_AESGM "find_dependency(Aesgm)")
endif()


# libjpeg
if(NOT PDFHUMMUS_NO_DCT)
find_package (JPEG)
if (JPEG_FOUND)
set (USING_UNBUNDLED_JPEG TRUE)
else(JPEG_FOUND)
if(USE_UNBUNDLED_FALLBACK_BUNDLED)
ADD_SUBDIRECTORY(LibJpeg)
else(USE_UNBUNDLED_FALLBACK_BUNDLED)
set (PDFHUMMUS_NO_DCT TRUE)
endif(USE_UNBUNDLED_FALLBACK_BUNDLED)
endif(JPEG_FOUND)
endif(NOT PDFHUMMUS_NO_DCT)
if(USING_UNBUNDLED_JPEG)
set(PDFHUMMUS_DEPENDS_JPEG "find_dependency(JPEG)")
endif()

PKG_CHECK_MODULES(ZLIB zlib REQUIRED)

PKG_CHECK_MODULES(LIBTIFF libtiff-4)
if(NOT LIBTIFF_FOUND)
SET(PDFHUMMUS_NO_TIFF TRUE)
else(NOT LIBTIFF_FOUND)
SET(INCLUDE_TIFF_HEADER TRUE)
endif(NOT LIBTIFF_FOUND)
# libtiff
if(NOT PDFHUMMUS_NO_TIFF)
find_package (TIFF)
if (TIFF_FOUND)
set (USING_UNBUNDLED_TIFF TRUE)
else(TIFF_FOUND)
if(USE_UNBUNDLED_FALLBACK_BUNDLED)
ADD_SUBDIRECTORY(LibTiff)
else(USE_UNBUNDLED_FALLBACK_BUNDLED)
set (PDFHUMMUS_NO_TIFF TRUE)
endif(USE_UNBUNDLED_FALLBACK_BUNDLED)
endif(TIFF_FOUND)
endif(NOT PDFHUMMUS_NO_TIFF)
if(USING_UNBUNDLED_TIFF)
set(PDFHUMMUS_DEPENDS_TIFF "find_dependency(TIFF)")
endif()

PKG_CHECK_MODULES(FREETYPE REQUIRED freetype2)
# libpng
if(NOT PDFHUMMUS_NO_PNG)
find_package (PNG)
if (PNG_FOUND)
set (USING_UNBUNDLED_PNG TRUE)
else(PNG_FOUND)
if(USE_UNBUNDLED_FALLBACK_BUNDLED)
ADD_SUBDIRECTORY(LibPng)
else(USE_UNBUNDLED_FALLBACK_BUNDLED)
set (PDFHUMMUS_NO_PNG TRUE)
endif(USE_UNBUNDLED_FALLBACK_BUNDLED)
endif(PNG_FOUND)
endif(NOT PDFHUMMUS_NO_PNG)
if(USING_UNBUNDLED_PNG)
set(PDFHUMMUS_DEPENDS_PNG "find_dependency(PNG)")
endif()

if (MINGW OR FLATPAK)
# FIXME: Fedora's MinGW environment doesn't provide LibAesgm
# FIXME: Flatpak's Gnome runtime doesn't provide LibAesgm
ADD_SUBDIRECTORY (LibAesgm)
else (MINGW OR FLATPAK)
FIND_PATH(LIBAESGM_INCLUDE_DIRS aescpp.h /usr/local/include/aes /usr/include/aes)
FIND_LIBRARY(LIBAESGM_LDFLAGS NAMES aesgm PATHS /usr/local/lib${LIB_SUFFIX} /usr/lib${LIB_SUFFIX})
endif (MINGW OR FLATPAK)
else(NOT USE_BUNDLED)
# zlib
ADD_SUBDIRECTORY(ZLib)

PKG_CHECK_MODULES(LIBPNG libpng)
if(NOT LIBPNG_FOUND)
SET(PDFHUMMUS_NO_PNG TRUE)
endif(NOT LIBPNG_FOUND)
# freetype
ADD_SUBDIRECTORY(FreeType)

else(NOT USE_BUNDLED)
# libaesgm
ADD_SUBDIRECTORY(LibAesgm)

# libjpeg
if(NOT PDFHUMMUS_NO_DCT)
ADD_SUBDIRECTORY(LibJpeg)
ADD_SUBDIRECTORY(LibJpeg)
endif(NOT PDFHUMMUS_NO_DCT)
ADD_SUBDIRECTORY(ZLib)

# libtiff
if(NOT PDFHUMMUS_NO_TIFF)
ADD_SUBDIRECTORY(LibTiff)
ADD_SUBDIRECTORY(LibTiff)
endif(NOT PDFHUMMUS_NO_TIFF)
ADD_SUBDIRECTORY(FreeType)

# libpng
if(NOT PDFHUMMUS_NO_PNG)
ADD_SUBDIRECTORY(LibPng)
ADD_SUBDIRECTORY(LibPng)
endif(NOT PDFHUMMUS_NO_PNG)

endif(NOT USE_BUNDLED)

ADD_SUBDIRECTORY(PDFWriter)

enable_testing()
Expand Down
11 changes: 10 additions & 1 deletion Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@

include ( "${CMAKE_CURRENT_LIST_DIR}/PDFHummusTargets.cmake" )

check_required_components(PDFHummus)
check_required_components(PDFHummus)

include(CMakeFindDependencyMacro)
@PDFHUMMUS_APPEND_MODULE@
@PDFHUMMUS_DEPENDS_ZLIB@
@PDFHUMMUS_DEPENDS_FREETYPE@
@PDFHUMMUS_DEPENDS_AESGM@
@PDFHUMMUS_DEPENDS_JPEG@
@PDFHUMMUS_DEPENDS_TIFF@
@PDFHUMMUS_DEPENDS_PNG@
24 changes: 15 additions & 9 deletions FreeType/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,21 @@ include/ft2build.h
)
add_library(PDFHummus::FreeType ALIAS FreeType)

set(FREETYPE_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
set(FREETYPE_LDFLAGS FreeType PARENT_SCOPE)
add_definitions(-DFT2_BUILD_LIBRARY=1)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include/freetype)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include/freetype/config)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include/src)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include/freetype/internal)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include/freetype/internal/services)
target_include_directories(FreeType
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/FreeType/include>
)
target_compile_definitions(FreeType PUBLIC FT2_BUILD_LIBRARY=1)

target_include_directories(FreeType
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include/freetype
${CMAKE_CURRENT_SOURCE_DIR}/include/freetype/config
${CMAKE_CURRENT_SOURCE_DIR}/include/src
${CMAKE_CURRENT_SOURCE_DIR}/include/freetype/internal
${CMAKE_CURRENT_SOURCE_DIR}/include/freetype/internal/services
)

install(TARGETS FreeType
EXPORT PDFHummusTargets
Expand Down
8 changes: 6 additions & 2 deletions LibAesgm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ brg_types.h
)

add_library(PDFHummus::LibAesgm ALIAS LibAesgm)
set(LIBAESGM_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
set(LIBAESGM_LDFLAGS LibAesgm PARENT_SCOPE)

target_include_directories(LibAesgm
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/LibAesgm>
)

install(TARGETS LibAesgm
EXPORT PDFHummusTargets
Expand Down
8 changes: 6 additions & 2 deletions LibJpeg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ jversion.h
)

add_library(PDFHummus::LibJpeg ALIAS LibJpeg)
set(JPEG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
set(JPEG_LIBRARIES LibJpeg PARENT_SCOPE)

target_include_directories(LibJpeg
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/LibJpeg>
)

install(TARGETS LibJpeg
EXPORT PDFHummusTargets
Expand Down
16 changes: 10 additions & 6 deletions LibPng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ pngstruct.h

add_library(PDFHummus::LibPng ALIAS LibPng)

set(LIBPNG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
set(LIBPNG_LDFLAGS LibPng PARENT_SCOPE)
target_include_directories(LibPng
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/LibPng>
)

# https://github.com/julienr/libpng-android/issues/6
if (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "aarch64" OR ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "arm64")
set(CMAKE_C_FLAGS -DPNG_ARM_NEON_OPT=0 ${CMAKE_C_FLAGS})
message (STATUS "libPng Arm64 - disable fpu Neon optimization")
target_compile_definitions(LibPng PRIVATE
PNG_ARM_NEON_OPT=0
)
endif()

include_directories (${ZLIB_INCLUDE_DIRS})
target_link_libraries(LibPng PDFHummus::Zlib)

target_link_libraries(LibPng ${ZLIB_LDFLAGS})

install(TARGETS LibPng
EXPORT PDFHummusTargets
Expand Down
47 changes: 26 additions & 21 deletions LibTiff/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,33 @@ uvcode.h
)

add_library(PDFHummus::LibTiff ALIAS LibTiff)
set(LIBTIFF_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
set(LIBTIFF_LDFLAGS LibTiff PARENT_SCOPE)
include_directories (${ZLIB_INCLUDE_DIRS})
add_definitions(
-D_CRT_SECURE_NO_DEPRECATE=1
-DAVOID_WIN32_FILEIO=1
-DCHECK_JPEG_YCBCR_SUBSAMPLING=1
-DDEFAULT_EXTRASAMPLE_AS_ALPHA=1
-DSTRIPCHOP_DEFAULT=TIFF_STRIPCHOP
-DSTRIP_SIZE_DEFAULT=8192
-DPIXARLOG_SUPPORT=1
-DZIP_SUPPORT=1
-DLOGLUV_SUPPORT=1
-DNEXT_SUPPORT=1
-DTHUNDER_SUPPORT=1
-DLZW_SUPPORT=1
-DPACKBITS_SUPPORT=1
-DCCITT_SUPPORT=1
-DTIF_PLATFORM_CONSOLE=1
-DFILLODER_LSB2MSB=1)

target_link_libraries(LibTiff ${ZLIB_LDFLAGS})
target_include_directories(LibTiff
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/LibTiff>
)

target_compile_definitions(LibTiff PUBLIC
_CRT_SECURE_NO_DEPRECATE=1
AVOID_WIN32_FILEIO=1
CHECK_JPEG_YCBCR_SUBSAMPLING=1
DEFAULT_EXTRASAMPLE_AS_ALPHA=1
STRIPCHOP_DEFAULT=TIFF_STRIPCHOP
STRIP_SIZE_DEFAULT=8192
PIXARLOG_SUPPORT=1
ZIP_SUPPORT=1
LOGLUV_SUPPORT=1
NEXT_SUPPORT=1
THUNDER_SUPPORT=1
LZW_SUPPORT=1
PACKBITS_SUPPORT=1
CCITT_SUPPORT=1
TIF_PLATFORM_CONSOLE=1
FILLODER_LSB2MSB=1
)

target_link_libraries(LibTiff PDFHummus::Zlib)

install(TARGETS LibTiff
EXPORT PDFHummusTargets
Expand Down
Loading

0 comments on commit f3fa6fc

Please sign in to comment.