Debian Codegraph @

podofo/CMakeLists.txt

raw
1 cmake_minimum_required(VERSION 3.23)
2
3 project(PoDoFo)
4
5 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
6 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
7 message(FATAL_ERROR "GCC version must be at least 9.0")
8 endif()
9 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
10 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
11 message(FATAL_ERROR "Clang version must be at least 9.0")
12 endif()
13 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
14 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.0)
15 message(FATAL_ERROR "Apple clang version must be at least 11.0")
16 endif()
17 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
18 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "15.9")
19 message(FATAL_ERROR "MSVC version must be at least 15.9")
20 endif()
21 else()
22 message(WARNING "You are using an unsupported compiler!")
23 endif()
24
25 include(PoDoFoVersion.cmake)
26 set(DOXYGEN_PROJECT_NUMBER "${PODOFO_VERSION}")
27
28 configure_file(
29 ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
30 ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
31 @ONLY
32 )
33
34 message("PoDoFo version: ${PODOFO_VERSION}")
35 message("PoDoFo SO version: ${PODOFO_SOVERSION}")
36 message("Host system: ${CMAKE_HOST_SYSTEM}")
37 message("C++ compiler ID: ${CMAKE_CXX_COMPILER_ID}")
38 message("C++ compiler version: ${CMAKE_CXX_COMPILER_VERSION}")
39 message("CMake version: ${CMAKE_VERSION}")
40
41 find_package(Doxygen)
42 if (DOXYGEN_FOUND)
43 # TODO: Add doxygen target
44 endif()
45
46 if(PODOFO_BUILD_DOC_ONLY)
47 return()
48 endif()
49
50 #
51 # Main includes
52 #
53 include(CheckIncludeFile)
54 include(CheckLibraryExists)
55 include(TestBigEndian)
56 include(CheckTypeSize)
57 include(GNUInstallDirs)
58
59 # Load modules from our source tree too
60 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" "${CMAKE_CURRENT_BINARY_DIR}")
61
62 # Builds must use this CMakeLists.txt, not the one in src/ or somewhere else.
63 # If users try to use something else the results can be confusing. We set a
64 # variable here that we require to be set elsewhere, otherwise we'll complain.
65 set(PODOFO_MAIN_CMAKELISTS_READ TRUE)
66
67 if(PODOFO_BUILD_LIB_ONLY)
68 set(PODOFO_BUILD_TEST FALSE)
69 set(PODOFO_BUILD_EXAMPLES FALSE)
70 set(PODOFO_BUILD_UNSUPPORTED_TOOLS FALSE)
71 else()
72 if (NOT DEFINED PODOFO_BUILD_TEST)
73 set(PODOFO_BUILD_TEST TRUE)
74 endif()
75
76 if (NOT DEFINED PODOFO_BUILD_EXAMPLES)
77 set(PODOFO_BUILD_EXAMPLES TRUE)
78 endif()
79
80 if (NOT DEFINED PODOFO_BUILD_UNSUPPORTED_TOOLS)
81 set(PODOFO_BUILD_UNSUPPORTED_TOOLS FALSE)
82 endif()
83
84 # We assume a standalone build so we set output
85 # path to a fixed location
86 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/target)
87 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/target)
88 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/target)
89 message(STATUS "Binary output directory is \"${CMAKE_BINARY_DIR}/target\"")
90 endif()
91
92 if (DEFINED PODOFO_BUILD_SHARED)
93 message(FATAL_ERROR "PODOFO_BUILD_SHARED shouldn't be defined externally. Set PODOFO_BUILD_STATIC to TRUE if you need a static build")
94 endif()
95
96 option(PODOFO_BUILD_STATIC "Build static libraries (.a/.lib)" FALSE)
97 option(PODOFO_WITH_AFDKO "Enable AFDKO support" ON)
98
99 if(PODOFO_WITH_AFDKO)
100 set(PODOFO_ENABLE_AFDKO TRUE)
101 endif()
102
103 if(PODOFO_BUILD_STATIC)
104 set(PODOFO_BUILD_SHARED FALSE)
105 add_compile_definitions(PODOFO_STATIC)
106 else()
107 set(PODOFO_BUILD_SHARED TRUE)
108 add_compile_definitions(PODOFO_SHARED)
109 endif()
110
111 message("Will install libraries to ${CMAKE_INSTALL_FULL_LIBDIR}")
112
113 # Linux packagers want an uninstall target.
114 configure_file(
115 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
116 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
117 IMMEDIATE @ONLY)
118 add_custom_target(uninstall "${CMAKE_COMMAND}"
119 -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
120
121 if(NOT DEFINED PLATFORM_SYSTEM_LIBRARIES)
122 set(PLATFORM_SYSTEM_LIBRARIES)
123 endif()
124
125 if(WIN32)
126 # Core win32 libraries come with CMAKE_C(XX)_IMPLICIT_LINK_LIBRARIES
127 set(PODOFO_HAVE_WIN32GDI TRUE)
128 list(APPEND PLATFORM_SYSTEM_LIBRARIES ws2_32 crypt32 Bcrypt)
129 endif()
130
131 # Set minimum required standard C++17, but also enforce it
132 # with compiler options as CMAKE_CXX_STANDARD (or any other
133 # CMake construct) won't really do it.
134 # See https://discourse.cmake.org/t/how-to-limit-maximum-cxx-standard-to-prevent-accidental-c-17-or-above-code/9862/2
135 set(CMAKE_CXX_STANDARD 17)
136 set(CMAKE_CXX_STANDARD_REQUIRED ON)
137 set(CMAKE_CXX_EXTENSIONS ON)
138 if (MSVC)
139 # Set the compiler less permissive and add some warnings
140 # /we4287: unsigned/negative constant mismatch
141 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/std:c++17> $<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus> /permissive- /utf-8 /we4287 /we4552 /W4)
142
143 # Microsoft deprecate certain POSIX functions that we use.
144 # for now, turn off these warnings.
145 add_compile_definitions(_CRT_SECURE_NO_DEPRECATE)
146 else()
147 # By default hide symbols on gcc/clang
148 # TODO: Remove -Wno-format-truncation after porting the
149 # code to std::fmt as it will be unuseful
150 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=gnu++17> $<$<COMPILE_LANGUAGE:CXX>:-Woverloaded-virtual> $<$<COMPILE_LANGUAGE:CXX>:-Wreorder> -fvisibility=hidden -Wall -Wswitch -Wcast-qual -Wwrite-strings -Wredundant-decls -Wno-format-truncation -Wno-unknown-pragmas -Wno-unknown-warning-option)
151
152 # Note that we do not need debug definitions here. Set
153 # -DCMAKE_BUILD_TYPE=debug or (if you want an optimised
154 # release build with debug info) -DCMAKE_CXX_FLAGS="-g3"
155 #
156 # We add -W unless we're using gcc on win32, where it produces
157 # spurious warnings about dllimport of inlines because of a dllimport
158 # declaration on the whole class.
159 if(NOT WIN32)
160 add_definitions(-W)
161 endif()
162
163 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
164 # Silence warnings on use of typeid(*ptr)
165 # See https://stackoverflow.com/questions/46494928/clang-warning-on-expression-side-effects
166 add_compile_options(-Wno-potentially-evaluated-expression)
167 endif()
168 endif()
169
170 set(PODOFO_3RDPARTY_INCLUDES
171 "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/adobe"
172 "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/chromium"
173 )
174
175 find_package(ZLIB REQUIRED)
176 message("Found zlib headers in ${ZLIB_INCLUDE_DIR}, library at ${ZLIB_LIBRARIES}")
177
178 find_package(OpenSSL REQUIRED)
179 message("Found OpenSSL headers in ${OPENSSL_INCLUDE_DIR}, libraries at ${OPENSSL_LIBRARIES}")
180
181 if (PODOFO_WITH_LCMS2)
182 find_package(LCMS2)
183 if(LCMS2_FOUND)
184 message("Found little-cms2 headers in ${LCMS2_INCLUDE_DIR}, library at ${LCMS2_LIBRARIES}")
185 set(PODOFO_HAVE_LCMS2 TRUE)
186 message("little-cms2 found. ICC profile reading support will be enabled")
187 else()
188 message("little-cms2 not found. ICC profile reading support will be disabled")
189 endif()
190 endif()
191
192 find_package(JPEG)
193
194 if(JPEG_FOUND)
195 message("Found libjpeg headers in ${JPEG_INCLUDE_DIR}, library at ${JPEG_LIBRARIES}")
196 set(PODOFO_HAVE_JPEG_LIB TRUE)
197 else()
198 message("Libjpeg not found. JPEG support will be disabled")
199 endif()
200
201 find_package(TIFF)
202
203 if(TIFF_FOUND)
204 message("Found libtiff headers in ${TIFF_INCLUDE_DIR}, library at ${TIFF_LIBRARIES}")
205 set(PODOFO_HAVE_TIFF_LIB TRUE)
206 else()
207 message("Libtiff not found. TIFF support will be disabled")
208 endif()
209
210 find_package(PNG)
211
212 if(PNG_FOUND)
213 message("Found LibPng headers in ${PNG_INCLUDE_DIR}, library at ${PNG_LIBRARIES}")
214 set(PODOFO_HAVE_PNG_LIB TRUE)
215 else()
216 message("LibPng not found. PNG support will be disabled")
217 set(PNG_LIBRARIES "")
218 endif()
219
220 find_package(Freetype REQUIRED)
221 message("Found freetype library at ${FREETYPE_LIBRARIES}, headers ${FREETYPE_INCLUDE_DIRS}")
222
223 option(PODOFO_WITH_FONTMANAGER "Enable font search mechanism" ON)
224
225 if(PODOFO_WITH_FONTMANAGER)
226 if(WIN32)
227 option(PODOFO_WITH_WIN32GDI_FONT_SEARCH "Enable Win32 GDI font search as alternative to FontConfig" OFF)
228 endif()
229
230 if(WIN32 AND PODOFO_WITH_WIN32GDI_FONT_SEARCH)
231 # Win32 font search enabled: FontConfig is optional
232 find_package(Fontconfig)
233 if(Fontconfig_FOUND)
234 set(PODOFO_HAVE_FONTCONFIG TRUE)
235 message("Found fontconfig headers in ${Fontconfig_INCLUDE_DIRS}, library at ${Fontconfig_LIBRARIES}")
236 else()
237 message("Fontconfig not found, using Win32 GDI font search only")
238 endif()
239 set(PODOFO_ENABLE_WIN32GDI_FONT_SEARCH TRUE)
240 message("Enabled Windows GDI font search")
241 else()
242 # FontConfig is required on all platforms
243 find_package(Fontconfig REQUIRED)
244 set(PODOFO_HAVE_FONTCONFIG TRUE)
245 message("Found fontconfig headers in ${Fontconfig_INCLUDE_DIRS}, library at ${Fontconfig_LIBRARIES}")
246 endif()
247 endif()
248
249 find_package(LibXml2 REQUIRED)
250 message("Found libxml2 library at ${LIBXML2_LIBRARIES}, headers ${LIBXML2_INCLUDE_DIRS}")
251
252 if (PODOFO_DEVENDOR_FMT_HEADER_ONLY)
253 # Implies PODOFO_DEVENDOR_FMT
254 set(PODOFO_DEVENDOR_FMT TRUE)
255 endif()
256
257 if (PODOFO_DEVENDOR_TCBSPAN)
258 find_package(TcbSpan REQUIRED)
259 else()
260 list(APPEND PODOFO_3RDPARTY_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/tcbspan")
261 endif()
262 if (PODOFO_DEVENDOR_DATE)
263 find_package(date CONFIG REQUIRED)
264 else()
265 list(APPEND PODOFO_3RDPARTY_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/date")
266 endif()
267 if (PODOFO_DEVENDOR_FASTFLOAT)
268 find_package(FastFloat CONFIG REQUIRED)
269 else()
270 list(APPEND PODOFO_3RDPARTY_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/fastfloat")
271 endif()
272 if (PODOFO_DEVENDOR_FMT)
273 find_package(fmt CONFIG REQUIRED)
274 else()
275 list(APPEND PODOFO_3RDPARTY_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/fmtlib")
276 endif()
277 if (PODOFO_DEVENDOR_UTF8CPP)
278 find_package(utf8cpp CONFIG REQUIRED)
279 else()
280 list(APPEND PODOFO_3RDPARTY_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/utf8cpp")
281 endif()
282 if (PODOFO_DEVENDOR_UTF8PROC)
283 find_package(utf8proc CONFIG REQUIRED)
284 else()
285 list(APPEND PODOFO_3RDPARTY_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/utf8proc")
286 endif()
287
288 # The podofo library needs to be linked to these libraries
289 # NOTE: Be careful when adding/removing: the order may be
290 # platform sensible, so don't modify the current order
291
292 set(PODOFO_PKGCONFIG_REQUIRES_PRIVATE "")
293 set(PODOFO_HEADERS_DEPENDS)
294 set(PODOFO_LIB_DEPENDS)
295
296 if (PODOFO_DEVENDOR_TCBSPAN)
297 list(APPEND PODOFO_LIB_DEPENDS PUBLIC $<COMPILE_ONLY:tcbspan::tcbspan>)
298 endif()
299 list(APPEND PODOFO_LIB_DEPENDS PRIVATE OpenSSL::SSL)
300 string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " libssl")
301 if(Fontconfig_FOUND)
302 list(APPEND PODOFO_LIB_DEPENDS PRIVATE Fontconfig::Fontconfig)
303 string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " fontconfig")
304 endif()
305 list(APPEND PODOFO_LIB_DEPENDS PRIVATE Freetype::Freetype)
306 string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " freetype2")
307 list(APPEND PODOFO_LIB_DEPENDS PRIVATE LibXml2::LibXml2)
308 string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " libxml-2.0")
309 if(PNG_FOUND)
310 list(APPEND PODOFO_LIB_DEPENDS PRIVATE PNG::PNG)
311 string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " libpng")
312 endif()
313 if(TIFF_FOUND)
314 list(APPEND PODOFO_LIB_DEPENDS PRIVATE TIFF::TIFF)
315 string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " libtiff-4")
316 endif()
317 if(JPEG_FOUND)
318 list(APPEND PODOFO_LIB_DEPENDS PRIVATE JPEG::JPEG)
319 string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " libjpeg")
320 endif()
321 list(APPEND PODOFO_LIB_DEPENDS PRIVATE ZLIB::ZLIB)
322 string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " zlib")
323 if (PODOFO_DEVENDOR_DATE)
324 list(APPEND PODOFO_LIB_DEPENDS PRIVATE $<COMPILE_ONLY:date::date>)
325 endif()
326 if (PODOFO_DEVENDOR_FASTFLOAT)
327 list(APPEND PODOFO_LIB_DEPENDS PRIVATE $<COMPILE_ONLY:FastFloat::fast_float>)
328 endif()
329 if (PODOFO_DEVENDOR_FMT)
330 if (PODOFO_DEVENDOR_FMT_HEADER_ONLY)
331 list(APPEND PODOFO_LIB_DEPENDS PRIVATE $<COMPILE_ONLY:fmt::fmt-header-only>)
332 else()
333 list(APPEND PODOFO_LIB_DEPENDS PRIVATE fmt::fmt)
334 endif()
335 endif()
336 if (PODOFO_DEVENDOR_UTF8CPP)
337 list(APPEND PODOFO_LIB_DEPENDS PRIVATE $<COMPILE_ONLY:utf8cpp::utf8cpp>)
338 endif()
339 if (PODOFO_DEVENDOR_UTF8PROC)
340 list(APPEND PODOFO_LIB_DEPENDS PRIVATE utf8proc::utf8proc)
341 string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " libutf8proc")
342 endif()
343 list(APPEND PODOFO_LIB_DEPENDS PRIVATE ${PLATFORM_SYSTEM_LIBRARIES})
344
345 if(LCMS2_FOUND)
346 # little-cms2 doesn't provide targets.
347 list(APPEND PODOFO_LIB_DEPENDS PRIVATE ${LCMS2_LIBRARIES})
348 list(APPEND PODOFO_HEADERS_DEPENDS ${LCMS2_INCLUDE_DIR})
349 string(APPEND PODOFO_PKGCONFIG_REQUIRES_PRIVATE " lcms2")
350 endif()
351
352 function(add_source subdir subdir_path dstsources dstheaders)
353 file(GLOB_RECURSE source_files "${subdir_path}/[^.]*")
354 # Set visual studio source group
355 source_group(${subdir} FILES ${source_files})
356 # Add subdir to source files
357 list(APPEND ${dstsources} ${source_files})
358 set(${dstsources} ${${dstsources}} PARENT_SCOPE)
359
360 # Identity the headers and do some cleanup
361 set(headers_files ${source_files})
362 list(FILTER headers_files EXCLUDE REGEX "\.cpp$")
363 list(FILTER headers_files EXCLUDE REGEX "\.in$")
364 list(APPEND ${dstheaders} ${headers_files})
365 set(${dstheaders} ${${dstheaders}} PARENT_SCOPE)
366 endfunction()
367
368 add_subdirectory(3rdparty)
369 add_subdirectory(src/podofo)
370 include_directories(${PODOFO_INCLUDE_DIRS})
371
372 if(PODOFO_BUILD_TEST)
373 enable_testing()
374 add_subdirectory(test)
375 endif()
376
377 if(PODOFO_BUILD_EXAMPLES)
378 add_subdirectory(examples)
379 endif()
380
381 if(PODOFO_BUILD_UNSUPPORTED_TOOLS)
382 add_subdirectory(tools)
383 endif()
384
385 # Enable packaging
386 set(CPACK_PACKAGE_DESCRIPTION "A C++ PDF manipulation library")
387 set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/podofo/podofo")
388 set(CPACK_PACKAGE_VENDOR "Francesco Pretto")
389 set(CPACK_PACKAGE_CONTACT "[email protected]")
390 set(CPACK_PACKAGE_VERSION ${PODOFO_VERSION})
391 if (WIN32)
392 # Set MSI generation
393 set(CPACK_GENERATOR "WIX")
394 endif()
395 include(CPack)