cmake_minimum_required(VERSION 3.23) project(PoDoFo) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) message(FATAL_ERROR "GCC version must be at least 9.0") endif() elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) message(FATAL_ERROR "Clang version must be at least 9.0") endif() elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.0) message(FATAL_ERROR "Apple clang version must be at least 11.0") endif() elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "15.9") message(FATAL_ERROR "MSVC version must be at least 15.9") endif() else() message(WARNING "You are using an unsupported compiler!") endif() include(PoDoFoVersion.cmake) set(DOXYGEN_PROJECT_NUMBER "${PODOFO_VERSION}") configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY ) message("PoDoFo version: ${PODOFO_VERSION}") message("PoDoFo SO version: ${PODOFO_SOVERSION}") message("Host system: ${CMAKE_HOST_SYSTEM}") message("C++ compiler ID: ${CMAKE_CXX_COMPILER_ID}") message("C++ compiler version: ${CMAKE_CXX_COMPILER_VERSION}") message("CMake version: ${CMAKE_VERSION}") find_package(Doxygen) if (DOXYGEN_FOUND) # TODO: Add doxygen target endif() if(PODOFO_BUILD_DOC_ONLY) return() endif() # # Main includes # include(CheckIncludeFile) include(CheckLibraryExists) include(TestBigEndian) include(CheckTypeSize) include(GNUInstallDirs) # Load modules from our source tree too list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" "${CMAKE_CURRENT_BINARY_DIR}") # Builds must use this CMakeLists.txt, not the one in src/ or somewhere else. # If users try to use something else the results can be confusing. We set a # variable here that we require to be set elsewhere, otherwise we'll complain. set(PODOFO_MAIN_CMAKELISTS_READ TRUE) if(PODOFO_BUILD_LIB_ONLY) set(PODOFO_BUILD_TEST FALSE) set(PODOFO_BUILD_EXAMPLES FALSE) set(PODOFO_BUILD_UNSUPPORTED_TOOLS FALSE) else() if (NOT DEFINED PODOFO_BUILD_TEST) set(PODOFO_BUILD_TEST TRUE) endif() if (NOT DEFINED PODOFO_BUILD_EXAMPLES) set(PODOFO_BUILD_EXAMPLES TRUE) endif() if (NOT DEFINED PODOFO_BUILD_UNSUPPORTED_TOOLS) set(PODOFO_BUILD_UNSUPPORTED_TOOLS FALSE) endif() # We assume a standalone build so we set output # path to a fixed location set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/target) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/target) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/target) message(STATUS "Binary output directory is \"${CMAKE_BINARY_DIR}/target\"") endif() if (DEFINED PODOFO_BUILD_SHARED) message(FATAL_ERROR "PODOFO_BUILD_SHARED shouldn't be defined externally. Set PODOFO_BUILD_STATIC to TRUE if you need a static build") endif() option(PODOFO_BUILD_STATIC "Build static libraries (.a/.lib)" FALSE) option(PODOFO_WITH_AFDKO "Enable AFDKO support" ON) if(PODOFO_WITH_AFDKO) set(PODOFO_ENABLE_AFDKO TRUE) endif() if(PODOFO_BUILD_STATIC) set(PODOFO_BUILD_SHARED FALSE) add_compile_definitions(PODOFO_STATIC) else() set(PODOFO_BUILD_SHARED TRUE) add_compile_definitions(PODOFO_SHARED) endif() message("Will install libraries to ${CMAKE_INSTALL_FULL_LIBDIR}") # Linux packagers want an uninstall target. configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") if(NOT DEFINED PLATFORM_SYSTEM_LIBRARIES) set(PLATFORM_SYSTEM_LIBRARIES) endif() if(WIN32) # Core win32 libraries come with CMAKE_C(XX)_IMPLICIT_LINK_LIBRARIES set(PODOFO_HAVE_WIN32GDI TRUE) list(APPEND PLATFORM_SYSTEM_LIBRARIES ws2_32 crypt32 Bcrypt) endif() # Set minimum required standard C++17, but also enforce it # with compiler options as CMAKE_CXX_STANDARD (or any other # CMake construct) won't really do it. # See https://discourse.cmake.org/t/how-to-limit-maximum-cxx-standard-to-prevent-accidental-c-17-or-above-code/9862/2 set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS ON) if (MSVC) # Set the compiler less permissive and add some warnings # /we4287: unsigned/negative constant mismatch add_compile_options($<$:/std:c++17> $<$:/Zc:__cplusplus> /permissive- /utf-8 /we4287 /we4552 /W4) # Microsoft deprecate certain POSIX functions that we use. # for now, turn off these warnings. add_compile_definitions(_CRT_SECURE_NO_DEPRECATE) else() # By default hide symbols on gcc/clang # TODO: Remove -Wno-format-truncation after porting the # code to std::fmt as it will be unuseful add_compile_options($<$:-std=gnu++17> $<$:-Woverloaded-virtual> $<$:-Wreorder> -fvisibility=hidden -Wall -Wswitch -Wcast-qual -Wwrite-strings -Wredundant-decls -Wno-format-truncation -Wno-unknown-pragmas -Wno-unknown-warning-option) # Note that we do not need debug definitions here. Set # -DCMAKE_BUILD_TYPE=debug or (if you want an optimised # release build with debug info) -DCMAKE_CXX_FLAGS="-g3" # # We add -W unless we're using gcc on win32, where it produces # spurious warnings about dllimport of inlines because of a dllimport # declaration on the whole class. if(NOT WIN32) add_definitions(-W) endif() if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # Silence warnings on use of typeid(*ptr) # See https://stackoverflow.com/questions/46494928/clang-warning-on-expression-side-effects add_compile_options(-Wno-potentially-evaluated-expression) endif() endif() set(PODOFO_3RDPARTY_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/adobe" "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/chromium" ) find_package(ZLIB REQUIRED) message("Found zlib headers in ${ZLIB_INCLUDE_DIR}, library at ${ZLIB_LIBRARIES}") find_package(OpenSSL REQUIRED) message("Found OpenSSL headers in ${OPENSSL_INCLUDE_DIR}, libraries at ${OPENSSL_LIBRARIES}") if (PODOFO_WITH_LCMS2) find_package(LCMS2) if(LCMS2_FOUND) message("Found little-cms2 headers in ${LCMS2_INCLUDE_DIR}, library at ${LCMS2_LIBRARIES}") set(PODOFO_HAVE_LCMS2 TRUE) message("little-cms2 found. ICC profile reading support will be enabled") else() message("little-cms2 not found. ICC profile reading support will be disabled") endif() endif() find_package(JPEG) if(JPEG_FOUND) message("Found libjpeg headers in ${JPEG_INCLUDE_DIR}, library at ${JPEG_LIBRARIES}") set(PODOFO_HAVE_JPEG_LIB TRUE) else() message("Libjpeg not found. JPEG support will be disabled") endif() find_package(TIFF) if(TIFF_FOUND) message("Found libtiff headers in ${TIFF_INCLUDE_DIR}, library at ${TIFF_LIBRARIES}") set(PODOFO_HAVE_TIFF_LIB TRUE) else() message("Libtiff not found. TIFF support will be disabled") endif() find_package(PNG) if(PNG_FOUND) message("Found LibPng headers in ${PNG_INCLUDE_DIR}, library at ${PNG_LIBRARIES}") set(PODOFO_HAVE_PNG_LIB TRUE) else() message("LibPng not found. PNG support will be disabled") set(PNG_LIBRARIES "") endif() find_package(Freetype REQUIRED) message("Found freetype library at ${FREETYPE_LIBRARIES}, headers ${FREETYPE_INCLUDE_DIRS}") option(PODOFO_WITH_FONTMANAGER "Enable font search mechanism" ON) if(PODOFO_WITH_FONTMANAGER) if(WIN32) option(PODOFO_WITH_WIN32GDI_FONT_SEARCH "Enable Win32 GDI font search as alternative to FontConfig" OFF) endif() if(WIN32 AND PODOFO_WITH_WIN32GDI_FONT_SEARCH) # Win32 font search enabled: FontConfig is optional find_package(Fontconfig) if(Fontconfig_FOUND) set(PODOFO_HAVE_FONTCONFIG TRUE) message("Found fontconfig headers in ${Fontconfig_INCLUDE_DIRS}, library at ${Fontconfig_LIBRARIES}") else() message("Fontconfig not found, using Win32 GDI font search only") endif() set(PODOFO_ENABLE_WIN32GDI_FONT_SEARCH TRUE) message("Enabled Windows GDI font search") else() # FontConfig is required on all platforms find_package(Fontconfig REQUIRED) set(PODOFO_HAVE_FONTCONFIG TRUE) message("Found fontconfig headers in ${Fontconfig_INCLUDE_DIRS}, library at ${Fontconfig_LIBRARIES}") endif() endif() find_package(LibXml2 REQUIRED) message("Found libxml2 library at ${LIBXML2_LIBRARIES}, headers ${LIBXML2_INCLUDE_DIRS}") if (PODOFO_DEVENDOR_FMT_HEADER_ONLY) # Implies PODOFO_DEVENDOR_FMT set(PODOFO_DEVENDOR_FMT TRUE) endif() if (PODOFO_DEVENDOR_TCBSPAN) find_package(TcbSpan REQUIRED) else() list(APPEND PODOFO_3RDPARTY_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/tcbspan") endif() if (PODOFO_DEVENDOR_DATE) find_package(date CONFIG REQUIRED) else() list(APPEND PODOFO_3RDPARTY_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/date") endif() if (PODOFO_DEVENDOR_FASTFLOAT) find_package(FastFloat CONFIG REQUIRED) else() list(APPEND PODOFO_3RDPARTY_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/fastfloat") endif() if (PODOFO_DEVENDOR_FMT) find_package(fmt CONFIG REQUIRED) else() list(APPEND PODOFO_3RDPARTY_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/fmtlib") endif() if (PODOFO_DEVENDOR_UTF8CPP) find_package(utf8cpp CONFIG REQUIRED) else() list(APPEND PODOFO_3RDPARTY_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/utf8cpp") endif() if (PODOFO_DEVENDOR_UTF8PROC) find_package(utf8proc CONFIG REQUIRED) else() list(APPEND PODOFO_3RDPARTY_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/utf8proc") endif() # The podofo library needs to be linked to these libraries # NOTE: Be careful when adding/removing: the order may be # platform sensible, so don't modify the current order set(PODOFO_PKGCONFIG_REQUIRES_PRIVATE "") set(PODOFO_HEADERS_DEPENDS) set(PODOFO_LIB_DEPENDS) if (PODOFO_DEVENDOR_TCBSPAN) list(APPEND PODOFO_LIB_DEPENDS PUBLIC $) endif() list(APPEND PODOFO_LIB_DEPENDS PRIVATE OpenSSL::SSL) string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " libssl") if(Fontconfig_FOUND) list(APPEND PODOFO_LIB_DEPENDS PRIVATE Fontconfig::Fontconfig) string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " fontconfig") endif() list(APPEND PODOFO_LIB_DEPENDS PRIVATE Freetype::Freetype) string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " freetype2") list(APPEND PODOFO_LIB_DEPENDS PRIVATE LibXml2::LibXml2) string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " libxml-2.0") if(PNG_FOUND) list(APPEND PODOFO_LIB_DEPENDS PRIVATE PNG::PNG) string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " libpng") endif() if(TIFF_FOUND) list(APPEND PODOFO_LIB_DEPENDS PRIVATE TIFF::TIFF) string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " libtiff-4") endif() if(JPEG_FOUND) list(APPEND PODOFO_LIB_DEPENDS PRIVATE JPEG::JPEG) string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " libjpeg") endif() list(APPEND PODOFO_LIB_DEPENDS PRIVATE ZLIB::ZLIB) string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " zlib") if (PODOFO_DEVENDOR_DATE) list(APPEND PODOFO_LIB_DEPENDS PRIVATE $) endif() if (PODOFO_DEVENDOR_FASTFLOAT) list(APPEND PODOFO_LIB_DEPENDS PRIVATE $) endif() if (PODOFO_DEVENDOR_FMT) if (PODOFO_DEVENDOR_FMT_HEADER_ONLY) list(APPEND PODOFO_LIB_DEPENDS PRIVATE $) else() list(APPEND PODOFO_LIB_DEPENDS PRIVATE fmt::fmt) endif() endif() if (PODOFO_DEVENDOR_UTF8CPP) list(APPEND PODOFO_LIB_DEPENDS PRIVATE $) endif() if (PODOFO_DEVENDOR_UTF8PROC) list(APPEND PODOFO_LIB_DEPENDS PRIVATE utf8proc::utf8proc) string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " libutf8proc") endif() list(APPEND PODOFO_LIB_DEPENDS PRIVATE ${PLATFORM_SYSTEM_LIBRARIES}) if(LCMS2_FOUND) # little-cms2 doesn't provide targets. list(APPEND PODOFO_LIB_DEPENDS PRIVATE ${LCMS2_LIBRARIES}) list(APPEND PODOFO_HEADERS_DEPENDS ${LCMS2_INCLUDE_DIR}) string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " lcms2") endif() function(add_source subdir subdir_path dstsources dstheaders) file(GLOB_RECURSE source_files "${subdir_path}/[^.]*") # Set visual studio source group source_group(${subdir} FILES ${source_files}) # Add subdir to source files list(APPEND ${dstsources} ${source_files}) set(${dstsources} ${${dstsources}} PARENT_SCOPE) # Identity the headers and do some cleanup set(headers_files ${source_files}) list(FILTER headers_files EXCLUDE REGEX "\.cpp$") list(FILTER headers_files EXCLUDE REGEX "\.in$") list(APPEND ${dstheaders} ${headers_files}) set(${dstheaders} ${${dstheaders}} PARENT_SCOPE) endfunction() add_subdirectory(3rdparty) add_subdirectory(src/podofo) include_directories(${PODOFO_INCLUDE_DIRS}) if(PODOFO_BUILD_TEST) enable_testing() add_subdirectory(test) endif() if(PODOFO_BUILD_EXAMPLES) add_subdirectory(examples) endif() if(PODOFO_BUILD_UNSUPPORTED_TOOLS) add_subdirectory(tools) endif() # Enable packaging set(CPACK_PACKAGE_DESCRIPTION "A C++ PDF manipulation library") set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/podofo/podofo") set(CPACK_PACKAGE_VENDOR "Francesco Pretto") set(CPACK_PACKAGE_CONTACT "ceztko@gmail.com") set(CPACK_PACKAGE_VERSION ${PODOFO_VERSION}) if (WIN32) # Set MSI generation set(CPACK_GENERATOR "WIX") endif() include(CPack)