Debian Codegraph @

podofo/CMakeLists.txt

raw
1 cmake_minimum_required(VERSION 3.16)
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" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
10 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
11 message(FATAL_ERROR "Clang version must be at least 7.0")
12 endif()
13 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
14 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "15.9")
15 message(FATAL_ERROR "MSVC version must be at least 15.9")
16 endif()
17 else()
18 message(WARNING "You are using an unsupported compiler!")
19 endif()
20
21 set(PODOFO_VERSION_MAJOR "0" CACHE STRING "Major part of podofo version number")
22 set(PODOFO_VERSION_MINOR "10" CACHE STRING "Minor part of podofo version number")
23 set(PODOFO_VERSION_PATCH "6" CACHE STRING "Patchlevel part of podofo version number")
24 set(PODOFO_VERSION "${PODOFO_VERSION_MAJOR}.${PODOFO_VERSION_MINOR}.${PODOFO_VERSION_PATCH}")
25 set(PODOFO_SOVERSION "2")
26
27 #
28 # Main includes
29 #
30 include(CheckIncludeFile)
31 include(CheckLibraryExists)
32 include(TestBigEndian)
33 include(CheckTypeSize)
34 include(GNUInstallDirs)
35
36 # Load modules from our source tree too
37 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" "${CMAKE_CURRENT_BINARY_DIR}")
38
39 # Builds must use this CMakeLists.txt, not the one in src/ or somewhere else.
40 # If users try to use something else the results can be confusing. We set a
41 # variable here that we require to be set elsewhere, otherwise we'll complain.
42 set(PODOFO_MAIN_CMAKELISTS_READ TRUE)
43
44 if(PODOFO_BUILD_LIB_ONLY)
45 set(PODOFO_BUILD_TEST FALSE)
46 set(PODOFO_BUILD_EXAMPLES FALSE)
47 set(PODOFO_BUILD_TOOLS FALSE)
48 else()
49 if (NOT DEFINED PODOFO_BUILD_TEST)
50 set(PODOFO_BUILD_TEST TRUE)
51 endif()
52
53 if (NOT DEFINED PODOFO_BUILD_EXAMPLES)
54 set(PODOFO_BUILD_EXAMPLES TRUE)
55 endif()
56
57 if (NOT DEFINED PODOFO_BUILD_TOOLS)
58 set(PODOFO_BUILD_TOOLS FALSE)
59 endif()
60
61 # We assume a standalone build so we set output
62 # path to a fixed location
63 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/target)
64 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/target)
65 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/target)
66 message(STATUS "Binary output directory is \"${CMAKE_BINARY_DIR}/target\"")
67 endif()
68
69 if (DEFINED PODOFO_BUILD_SHARED)
70 message(FATAL_ERROR "PODOFO_BUILD_SHARED shouldn't be defined externally. Set PODOFO_BUILD_STATIC to TRUE if you need a static build")
71 endif()
72
73 option(PODOFO_BUILD_STATIC "Build static libraries (.a/.lib)" FALSE)
74 if(PODOFO_BUILD_STATIC)
75 set(PODOFO_BUILD_SHARED FALSE)
76 add_compile_definitions(PODOFO_STATIC)
77 else()
78 set(PODOFO_BUILD_SHARED TRUE)
79 add_compile_definitions(PODOFO_SHARED)
80 endif()
81
82 message("Will install libraries to ${CMAKE_INSTALL_FULL_LIBDIR}")
83
84 # Linux packagers want an uninstall target.
85 configure_file(
86 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
87 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
88 IMMEDIATE @ONLY)
89 add_custom_target(uninstall "${CMAKE_COMMAND}"
90 -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
91
92 if(NOT DEFINED PLATFORM_SYSTEM_LIBRARIES)
93 set(PLATFORM_SYSTEM_LIBRARIES)
94 endif()
95
96 if(WIN32)
97 # We must explicitly link to the core win32 libraries
98 list(APPEND PLATFORM_SYSTEM_LIBRARIES kernel32 user32 gdi32 winspool comdlg32 advapi32 shell32 ole32 oleaut32 uuid ws2_32 Crypt32)
99 endif()
100
101 # Set minimum required standard C++17, but also enforce it
102 # with compiler options as CMAKE_CXX_STANDARD (or any other
103 # CMake construct) won't really do it.
104 # See https://discourse.cmake.org/t/how-to-limit-maximum-cxx-standard-to-prevent-accidental-c-17-or-above-code/9862/2
105 set(CMAKE_CXX_STANDARD 17)
106 set(CMAKE_CXX_STANDARD_REQUIRED ON)
107 set(CMAKE_CXX_EXTENSIONS ON)
108 if (MSVC)
109 # Set the compiler less permissive and add some warnings
110 # /we4287: unsigned/negative constant mismatch
111 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/std:c++17> $<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus> /permissive- /utf-8 /we4287 /W4)
112
113 # Microsoft deprecate certain POSIX functions that we use.
114 # for now, turn off these warnings.
115 add_compile_definitions(_CRT_SECURE_NO_DEPRECATE)
116 else()
117 # By default hide symbols on gcc/clang
118 # TODO: Remove -Wno-format-truncation after porting the
119 # code to std::fmt as it will be unuseful
120 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)
121
122 # Note that we do not need debug definitions here. Set
123 # -DCMAKE_BUILD_TYPE=debug or (if you want an optimised
124 # release build with debug info) -DCMAKE_CXX_FLAGS="-g3"
125 #
126 # We add -W unless we're using gcc on win32, where it produces
127 # spurious warnings about dllimport of inlines because of a dllimport
128 # declaration on the whole class.
129 if(NOT WIN32)
130 add_definitions(-W)
131 endif()
132 endif()
133
134 find_package(ZLIB REQUIRED)
135 message("Found zlib headers in ${ZLIB_INCLUDE_DIR}, library at ${ZLIB_LIBRARIES}")
136
137 find_package(OpenSSL REQUIRED)
138 message("OPENSSL_LIBRARIES: ${OPENSSL_LIBRARIES}")
139
140 find_package(Libidn)
141
142 if(LIBIDN_FOUND)
143 message("Found Libidn headers in ${LIBIDN_INCLUDE_DIR}, library at ${LIBIDN_LIBRARIES}")
144 set(PODOFO_HAVE_LIBIDN TRUE)
145 message("Libidn found. AES-256 Encryption support will be enabled")
146 else()
147 message("Libidn not found. AES-256 Encryption support will be disabled")
148 endif()
149
150 find_package(JPEG)
151
152 if(JPEG_FOUND)
153 message("Found libjpeg headers in ${JPEG_INCLUDE_DIR}, library at ${JPEG_LIBRARIES}")
154 set(PODOFO_HAVE_JPEG_LIB TRUE)
155 else()
156 message("Libjpeg not found. JPEG support will be disabled")
157 endif()
158
159 find_package(TIFF)
160
161 if(TIFF_FOUND)
162 message("Found libtiff headers in ${TIFF_INCLUDE_DIR}, library at ${TIFF_LIBRARIES}")
163 set(PODOFO_HAVE_TIFF_LIB TRUE)
164 else()
165 message("Libtiff not found. TIFF support will be disabled")
166 endif()
167
168 find_package(PNG)
169
170 if(PNG_FOUND)
171 message("Found LibPng headers in ${PNG_INCLUDE_DIR}, library at ${PNG_LIBRARIES}")
172 set(PODOFO_HAVE_PNG_LIB TRUE)
173 else()
174 message("LibPng not found. PNG support will be disabled")
175 set(PNG_LIBRARIES "")
176 endif()
177
178 find_package(Freetype REQUIRED)
179 message("Found freetype library at ${FREETYPE_LIBRARIES}, headers ${FREETYPE_INCLUDE_DIRS}")
180
181 find_package(Fontconfig)
182 if(Fontconfig_FOUND)
183 set(PODOFO_HAVE_FONTCONFIG TRUE)
184 message("Found fontconfig headers in ${Fontconfig_INCLUDE_DIRS}, library at ${Fontconfig_LIBRARIES}")
185 endif()
186
187 if(WIN32 AND NOT PODOFO_HAVE_FONTCONFIG OR PODOFO_WANT_WIN32GDI)
188 # Fallback to GDI if FontConfig is missing in Windows
189 set(PODOFO_HAVE_WIN32GDI TRUE)
190 message("Enabled Windows GDI API")
191 endif()
192
193 find_package(LibXml2 REQUIRED)
194 message("Found libxml2 library at ${LIBXML2_LIBRARIES}, headers ${LIBXML2_INCLUDE_DIRS}")
195
196 # The podofo library needs to be linked to these libraries
197 # NOTE: Be careful when adding/removing: the order may be
198 # platform sensible, so don't modify the current order
199
200 set(PODOFO_HEADERS_DEPENDS)
201 set(PODOFO_LIB_DEPENDS OpenSSL::SSL)
202 if(Fontconfig_FOUND)
203 list(APPEND PODOFO_LIB_DEPENDS Fontconfig::Fontconfig)
204 endif()
205 list(APPEND PODOFO_LIB_DEPENDS Freetype::Freetype)
206 list(APPEND PODOFO_LIB_DEPENDS LibXml2::LibXml2)
207 if(PNG_FOUND)
208 list(APPEND PODOFO_LIB_DEPENDS PNG::PNG)
209 endif()
210 if(TIFF_FOUND)
211 list(APPEND PODOFO_LIB_DEPENDS TIFF::TIFF)
212 endif()
213 if(JPEG_FOUND)
214 list(APPEND PODOFO_LIB_DEPENDS JPEG::JPEG)
215 endif()
216 list(APPEND PODOFO_LIB_DEPENDS ZLIB::ZLIB)
217 list(APPEND PODOFO_LIB_DEPENDS ${PLATFORM_SYSTEM_LIBRARIES})
218
219 if(LIBIDN_FOUND)
220 # libidn doesn't provide targets.
221 list(APPEND PODOFO_LIB_DEPENDS ${LIBIDN_LIBRARIES})
222 list(APPEND PODOFO_HEADERS_DEPENDS ${LIBIDN_INCLUDE_DIR})
223 endif()
224
225 # Create the config file. It'll be appended to as the subdirs run though
226 # then dependency information will be written to it at the end of the
227 # build.
228 file(WRITE
229 "${PROJECT_BINARY_DIR}/podofoConfig.cmake"
230 "# CMake module for podofo\n"
231 )
232 file(APPEND
233 "${PROJECT_BINARY_DIR}/podofoConfig.cmake"
234 "set(PODOFO_INCLUDES ${PROJECT_SOURCE_DIR}/src)\n"
235 )
236
237 add_subdirectory(src/podofo)
238 include_directories(${PODOFO_INCLUDE_DIRS})
239
240 if(PODOFO_BUILD_TEST)
241 enable_testing()
242 add_subdirectory(test)
243 endif()
244
245 if(PODOFO_BUILD_EXAMPLES)
246 add_subdirectory(examples)
247 endif()
248
249 if(PODOFO_BUILD_TOOLS)
250 add_subdirectory(tools)
251 endif()
252
253 # Enable packaging
254 set(CPACK_PACKAGE_DESCRIPTION "A C++ PDF manipulation library")
255 set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/podofo/podofo")
256 set(CPACK_PACKAGE_VENDOR "Francesco Pretto")
257 set(CPACK_PACKAGE_CONTACT "[email protected]")
258 set(CPACK_PACKAGE_VERSION ${PODOFO_VERSION})
259 if (WIN32)
260 # Set MSI generation
261 set(CPACK_GENERATOR "WIX")
262 endif()
263 include(CPack)