From f3fa6fc02f0ccade05ba860897c8682b11c14d1d Mon Sep 17 00:00:00 2001 From: gal kahana Date: Fri, 17 Feb 2023 16:07:40 +0200 Subject: [PATCH] Find package targets (#193) * improving the install with proper internal target definitions, allowing fallback if not using bundled * documentation --- CMakeLists.txt | 155 +++++++++++++++++++++++++++++++-------- Config.cmake.in | 11 ++- FreeType/CMakeLists.txt | 24 +++--- LibAesgm/CMakeLists.txt | 8 +- LibJpeg/CMakeLists.txt | 8 +- LibPng/CMakeLists.txt | 16 ++-- LibTiff/CMakeLists.txt | 47 ++++++------ PDFWriter/CMakeLists.txt | 135 +++++++++++++--------------------- ZLib/CMakeLists.txt | 11 ++- cmake/FindAesgm.cmake | 92 +++++++++++++++++++++++ readme.md | 19 +++-- 11 files changed, 360 insertions(+), 166 deletions(-) create mode 100644 cmake/FindAesgm.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 637f6449..5cd4d788 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/Config.cmake.in b/Config.cmake.in index 72e92197..bcfec357 100644 --- a/Config.cmake.in +++ b/Config.cmake.in @@ -2,4 +2,13 @@ include ( "${CMAKE_CURRENT_LIST_DIR}/PDFHummusTargets.cmake" ) -check_required_components(PDFHummus) \ No newline at end of file +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@ diff --git a/FreeType/CMakeLists.txt b/FreeType/CMakeLists.txt index 7cfa91fb..99b59aee 100644 --- a/FreeType/CMakeLists.txt +++ b/FreeType/CMakeLists.txt @@ -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 + $ + $ +) +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 diff --git a/LibAesgm/CMakeLists.txt b/LibAesgm/CMakeLists.txt index 7f0ccc2c..6ff89204 100644 --- a/LibAesgm/CMakeLists.txt +++ b/LibAesgm/CMakeLists.txt @@ -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 + $ + $ +) install(TARGETS LibAesgm EXPORT PDFHummusTargets diff --git a/LibJpeg/CMakeLists.txt b/LibJpeg/CMakeLists.txt index d452f50a..fc763fd6 100644 --- a/LibJpeg/CMakeLists.txt +++ b/LibJpeg/CMakeLists.txt @@ -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 + $ + $ +) install(TARGETS LibJpeg EXPORT PDFHummusTargets diff --git a/LibPng/CMakeLists.txt b/LibPng/CMakeLists.txt index f87ecd86..02e31d75 100644 --- a/LibPng/CMakeLists.txt +++ b/LibPng/CMakeLists.txt @@ -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 + $ + $ +) + # 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 diff --git a/LibTiff/CMakeLists.txt b/LibTiff/CMakeLists.txt index 89527f22..c9316d1c 100644 --- a/LibTiff/CMakeLists.txt +++ b/LibTiff/CMakeLists.txt @@ -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 + $ + $ +) + +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 diff --git a/PDFWriter/CMakeLists.txt b/PDFWriter/CMakeLists.txt index aa738e5b..6f6e5cd1 100644 --- a/PDFWriter/CMakeLists.txt +++ b/PDFWriter/CMakeLists.txt @@ -349,92 +349,60 @@ XObjectContentContext.h add_library(PDFHummus::PDFWriter ALIAS PDFWriter) -if(USE_BUNDLED) - target_include_directories(PDFWriter - PUBLIC - $ - $ - ) - target_include_directories(PDFWriter - PUBLIC - $ - $ - ) - target_include_directories(PDFWriter - PUBLIC - $ - $ - ) -else(USE_BUNDLED) - target_include_directories(PDFWriter - PUBLIC - ${LIBAESGM_INCLUDE_DIRS} - ) - target_include_directories(PDFWriter - PUBLIC - ${ZLIB_INCLUDE_DIRS} - ) - target_include_directories(PDFWriter - PUBLIC - ${FREETYPE_INCLUDE_DIRS} - ) -endif(USE_BUNDLED) - -if(NOT PDFHUMMUS_NO_DCT) - if(USE_BUNDLED) - target_include_directories(PDFWriter - PUBLIC - $ - $ - ) - else(USE_BUNDLED) - target_include_directories(PDFWriter - PUBLIC - ${JPEG_INCLUDE_DIRS} - ) - endif(USE_BUNDLED) -else(NOT PDFHUMMUS_NO_DCT) +# zlib +if(USING_UNBUNDLED_ZLIB) + target_link_libraries(PDFWriter ZLIB::ZLIB) +else(USING_UNBUNDLED_ZLIB) + target_link_libraries(PDFWriter PDFHummus::Zlib) +endif(USING_UNBUNDLED_ZLIB) + +# freetype +if(USING_UNBUNDLED_Freetype) + target_link_libraries(PDFWriter Freetype::Freetype) +else(USING_UNBUNDLED_Freetype) + target_link_libraries(PDFWriter PDFHummus::FreeType) +endif(USING_UNBUNDLED_Freetype) + +# libaesgm +if(USING_UNBUNDLED_aesgm) + target_link_libraries(PDFWriter Aesgm::Aesgm) +else(USING_UNBUNDLED_aesgm) + target_link_libraries(PDFWriter PDFHummus::LibAesgm) +endif(USING_UNBUNDLED_aesgm) + +# libjpeg +if(PDFHUMMUS_NO_DCT) target_compile_definitions(PDFWriter PUBLIC PDFHUMMUS_NO_DCT=1) -endif(NOT PDFHUMMUS_NO_DCT) - -if(NOT PDFHUMMUS_NO_TIFF) - if(USE_BUNDLED) - target_include_directories(PDFWriter - PUBLIC - $ - $ - ) - else(USE_BUNDLED) - target_include_directories(PDFWriter - PUBLIC - ${LIBTIFF_INCLUDE_DIRS} - ) - endif(USE_BUNDLED) - if(INCLUDE_TIFF_HEADER) - target_compile_definitions(PDFWriter PUBLIC _INCLUDE_TIFF_HEADER) - endif(INCLUDE_TIFF_HEADER) -else(NOT PDFHUMMUS_NO_TIFF) +else(PDFHUMMUS_NO_DCT) + if(USING_UNBUNDLED_JPEG) + target_link_libraries(PDFWriter JPEG::JPEG) + else(USING_UNBUNDLED_JPEG) + target_link_libraries(PDFWriter PDFHummus::LibJpeg) + endif(USING_UNBUNDLED_JPEG) +endif(PDFHUMMUS_NO_DCT) + +# libtiff +if(PDFHUMMUS_NO_TIFF) target_compile_definitions(PDFWriter PUBLIC PDFHUMMUS_NO_TIFF=1) -endif(NOT PDFHUMMUS_NO_TIFF) - -if(NOT PDFHUMMUS_NO_PNG) - if(USE_BUNDLED) - target_include_directories(PDFWriter - PUBLIC - $ - $ - ) - else(USE_BUNDLED) - target_include_directories(PDFWriter - PUBLIC - ${LIBPNG_INCLUDE_DIRS} - ) - endif(USE_BUNDLED) -else(NOT PDFHUMMUS_NO_PNG) - target_compile_definitions(PDFWriter PUBLIC PDFHUMMUS_NO_PNG=1) -endif(NOT PDFHUMMUS_NO_PNG) +else(PDFHUMMUS_NO_TIFF) + if(USING_UNBUNDLED_TIFF) + target_link_libraries(PDFWriter TIFF::TIFF) + target_compile_definitions(PDFWriter PUBLIC _INCLUDE_TIFF_HEADER) + else(USING_UNBUNDLED_TIFF) + target_link_libraries(PDFWriter PDFHummus::LibTiff) + endif(USING_UNBUNDLED_TIFF) +endif(PDFHUMMUS_NO_TIFF) -set(PDFWriter_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE) +# libpng +if(PDFHUMMUS_NO_PNG) + target_compile_definitions(PDFWriter PUBLIC PDFHUMMUS_NO_PNG=1) +else(PDFHUMMUS_NO_PNG) + if(USING_UNBUNDLED_PNG) + target_link_libraries(PDFWriter PNG::PNG) + else(USING_UNBUNDLED_PNG) + target_link_libraries(PDFWriter PDFHummus::LibPng) + endif(USING_UNBUNDLED_PNG) +endif(PDFHUMMUS_NO_PNG) target_include_directories(PDFWriter INTERFACE @@ -442,7 +410,6 @@ target_include_directories(PDFWriter $ ) -target_link_libraries(PDFWriter ${LIBAESGM_LDFLAGS} ${JPEG_LIBRARIES} ${ZLIB_LDFLAGS} ${LIBTIFF_LDFLAGS} ${FREETYPE_LDFLAGS} ${LIBPNG_LDFLAGS}) set_target_properties(PDFWriter PROPERTIES VERSION ${PDFWRITER_LIB_VERSION} SOVERSION ${PDFWRITER_SO_VERSION}) install(TARGETS PDFWriter diff --git a/ZLib/CMakeLists.txt b/ZLib/CMakeLists.txt index aea14e4d..ee11eb26 100644 --- a/ZLib/CMakeLists.txt +++ b/ZLib/CMakeLists.txt @@ -32,16 +32,19 @@ zutil.h add_library(PDFHummus::Zlib ALIAS Zlib) -set(ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE) -set(ZLIB_LDFLAGS Zlib PARENT_SCOPE) -include(CheckIncludeFile) +target_include_directories(Zlib + INTERFACE + $ + $ +) # # Check for unistd.h # +include(CheckIncludeFile) check_include_file(unistd.h Z_HAVE_UNISTD_H) if(Z_HAVE_UNISTD_H) -ADD_DEFINITIONS(-DHAVE_UNISTD_H=1) + target_compile_definitions(Zlib PUBLIC HAVE_UNISTD_H=1) endif(Z_HAVE_UNISTD_H) diff --git a/cmake/FindAesgm.cmake b/cmake/FindAesgm.cmake new file mode 100644 index 00000000..726c07f3 --- /dev/null +++ b/cmake/FindAesgm.cmake @@ -0,0 +1,92 @@ +# Distributed under Apache 2 License. See accompanying +# file LICENSE or https://github.com/galkahana/PDF-Writer/blob/master/LICENSE +# for details. + +#[=======================================================================[.rst: +FindAesgm +------- + +Finds the Aesgm library. +(I guess originally I took the pdfhummus bundled copy from https://github.com/BrianGladman/aes) + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``Aesgm::Aesgm`` + The Aesgm library + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``Aesgm_FOUND`` + True if the system has the Aesgm library. +``Aesgm_INCLUDE_DIRS`` + Include directories needed to use Aesgm. +``Aesgm_LIBRARIES`` + Libraries needed to link to Aesgm. +``Aesgm_VERSION`` + The version of the Aesgm library which was found. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``Aesgm_INCLUDE_DIR`` + The directory containing ``aescpp.h``. +``Aesgm_LIBRARY`` + The path to the Aesgm library. + +#]=======================================================================] + + +find_package(PkgConfig) +pkg_check_modules(PC_Aesgm QUIET Aesgm) + + +find_path(Aesgm_INCLUDE_DIR + NAMES aescpp.h + PATHS ${PC_Aesgm_INCLUDE_DIRS} /usr/local/include/aes /usr/include/aes + PATH_SUFFIXES aes +) +find_library(Aesgm_LIBRARY + NAMES aesgm + PATHS ${PC_Aesgm_LIBRARY_DIRS} /usr/local/lib${LIB_SUFFIX} /usr/lib${LIB_SUFFIX} +) + +set(Aesgm_VERSION ${PC_Aesgm_VERSION}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Aesgm + FOUND_VAR Aesgm_FOUND + REQUIRED_VARS + Aesgm_LIBRARY + Aesgm_INCLUDE_DIR + VERSION_VAR Aesgm_VERSION +) + +if(Aesgm_FOUND) + set(Aesgm_LIBRARIES ${Aesgm_LIBRARY}) + set(Aesgm_INCLUDE_DIRS ${Aesgm_INCLUDE_DIR}) + set(Aesgm_DEFINITIONS ${PC_Aesgm_CFLAGS_OTHER}) +endif() + + +if(Aesgm_FOUND AND NOT TARGET Aesgm::Aesgm) + add_library(Aesgm::Aesgm UNKNOWN IMPORTED) + set_target_properties(Aesgm::Aesgm PROPERTIES + IMPORTED_LOCATION "${Aesgm_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${PC_Aesgm_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${Aesgm_INCLUDE_DIR}" + ) +endif() + + +mark_as_advanced( + Aesgm_INCLUDE_DIR + Aesgm_LIBRARY +) \ No newline at end of file diff --git a/readme.md b/readme.md index 539f1cc2..1268c560 100644 --- a/readme.md +++ b/readme.md @@ -6,10 +6,6 @@ Project site is [here](http://www.pdfhummus.com). There is also a NodeJS module named [MuhammaraJS](https://github.com/julianhille/MuhammaraJS) wrapping PDFHummus PDF library and making it available for that language. It is the current and still supported version of a now deprecated [HummusJS](https://github.com/galkahana/HummusJS) project of mine, which [julianhille](https://github.com/julianhille) maintains. -**Note and clarification on earlier notes:** Since 9/11/2019 I ended support for this project. You may still use the code as is, with the provided license, however I will not be providing answers, solutions, responses etc. I may still develop the library further, making sure not to break API or change it in any other way to harm your existing implementations, however those developments are based solely on my own personal projects needs. - -And now that we got that out of the way, let's move on for some basic instructions. - # First time around This is a C++ Project using CMake as project builder. @@ -50,7 +46,8 @@ The project defines some optional flags to allow you to control some aspects of - `PDFHUMMUS_NO_DCT` - defines whether to exclude DCT functionality (essentially - not include LibJpeg) from the library. defaults to `FALSE`. when setting `TRUE` the library will not require the existance of LibJpeg however will not be able to decode DCT streams from PDF files. (note that this has no baring on the ability to include JPEG images. That ability does not require LibJpeg given the innate ability of PDF files to include DCT encoded streams). - `PDFHUMMUS_NO_TIFF` - defines whether to exclude TIFF functionality (essentially - not include LibTiff) from the library. defaults to `FALSE`. when setting `TRUE` the library will not require the existance of LibTiff however will not be able to embed TIFF images. - `PDFHuMMUS_NO_PNG` - defines whether to exclude PNG functionality (essentially - not include LibPng) from the library. defaults to `FALSE`. when setting `TRUE` the library will not require the existance of LibPng however will not be able to embed PNG images. -- `USE_BUNDLED` - defines whether to use bundled dependencies when building the project or use system libraries. defaults to `TRUE`. when defined as `FALSE`, the project configuration will look for installed versions of LibJpeg, ZLib, LibTiff, FreeType, LibAesgm, LibPng and use them instead of the bundled ones (i.e. those contained in the project). Note that for optional dependencies - LibJpeg, LibTiff, LibPng - if not installed the coniguration will succeed but will automatically set the optional building flags (the 3 just described) according to the libraries avialability. As for required dependencies - FreeType, LibAesgm, Zlib - the configuration will fail if those dependencies are not found. +- `USE_BUNDLED` - defines whether to use bundled dependencies when building the project or use system libraries. defaults to `TRUE`. when defined as `FALSE`, the project configuration will look for installed versions of LibJpeg, ZLib, LibTiff, FreeType, LibAesgm, LibPng and use them instead of the bundled ones (i.e. those contained in the project). Note that for optional dependencies - LibJpeg, LibTiff, LibPng - if not installed the coniguration will succeed but will automatically set the optional building flags (the 3 just described) according to the libraries avialability. As for required dependencies - FreeType, LibAesgm, Zlib - the configuration will fail if those dependencies are not found. see `USE_UNBUNDLED_FALLBACK_BUNDLED` for an alternative method to deal with dependencies not being found. +- `USE_UNBUNDLED_FALLBACK_BUNDLED` - Defines an alternative behavior when using `USE_BUNDLED=OFF` and a certain dependency is not installed on the system. If set to `TRUE` then for a dependency that's not found it will fallback on the bundled version of this dependency. This is essentially attempting to find installed library and if not avialable use a bundled one to ensure that the build will succeed. You can set any of those options when calling the `cmake` command. For example to use system libraries replaced the earlier sequence with: @@ -123,7 +120,7 @@ include(FetchContent) FetchContent_Declare( PDFHummus GIT_REPOSITORY https://github.com/galkahana/PDF-Writer.git - GIT_TAG 4.4 + GIT_TAG 4.5 FIND_PACKAGE_ARGS ) FetchContent_MakeAvailable(PDFHummus) @@ -135,6 +132,16 @@ This will either download the project and build it or use an installed version ( Change the `GIT_TAG` value to what version you'd like to install. You can use tags, branches, commit hashs. anything goes. Includes are included haha. +Note that when installing PDFHummus with the bundled libraries built (this is the default behvaior which can be changed by setting `USE_BUNDLED` variable to `FALSE`) there are additional targets that PDFHummus includes: +- PDFHummus::FreeType - bundled freetype library +- PDFHummus::LibAesgm - bundled aesgm library +- PDFHummus::LibJpeg - bundled libjpeg library +- PDFHummus::LibPng - bundled libpng library +- PDFHummus::LibTiff - bundled libtiff library +- PDFHummus:::Zlib - bundled zlib library + +You can use those targets in additon or instead of using PDFWriter if this makes sense to your project (like if you are extracting images, having LibJpeg or LibPng around can be useful). + # Packaging PDFHummus for installing someplace else The project contains definitions for `cpack`, cmake packaging mechanism. It might be useful for when you want to build PDFHummus and then install it someplace else.