forked from pdfmm/pdfmm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
294 lines (246 loc) · 9.43 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
cmake_minimum_required(VERSION 3.16)
project(pdfmm)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.1)
message(FATAL_ERROR "GCC version must be at least 8.1")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
message(FATAL_ERROR "Clang version must be at least 7.0")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "15.9")
message(FATAL_ERROR "MSVC version bust be at least 15.9")
endif()
else()
message(WARNING "You are using an unsupported compiler!")
endif()
set(PDFMM_VERSION_MAJOR "0" CACHE STRING "Major part of pdfmm version number")
set(PDFMM_VERSION_MINOR "9" CACHE STRING "Minor part of pdfmm version number")
set(PDFMM_VERSION_PATCH "23" CACHE STRING "Patchlevel part of pdfmm version number")
set(PDFMM_SOVERSION "${PDFMM_VERSION_MAJOR}.${PDFMM_VERSION_MINOR}.${PDFMM_VERSION_PATCH}")
set(PDFMM_LIBVERSION "${PDFMM_SOVERSION}")
#
# Main includes
#
include(CheckIncludeFile)
include(CheckLibraryExists)
include(TestBigEndian)
include(CheckTypeSize)
set(CMAKE_CXX_STANDARD 17)
# Load modules from our source tree too
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
# 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(PDFMM_MAIN_CMAKELISTS_READ TRUE)
if(NOT PDFMM_BUILD_LIB_ONLY)
# 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)
endif()
# If the user hasn't told use specifically what they want, build only
# a static library or only a shared library on Windows.
if(NOT DEFINED PDFMM_BUILD_SHARED AND NOT DEFINED PDFMM_BUILD_STATIC)
if(WIN32)
set(PDFMM_BUILD_STATIC FALSE)
set(PDFMM_BUILD_SHARED TRUE)
else()
set(PDFMM_BUILD_STATIC TRUE)
set(PDFMM_BUILD_SHARED FALSE)
endif()
endif()
if(DEFINED PDFMM_BUILD_SHARED AND NOT DEFINED PDFMM_BUILD_STATIC)
if(PDFMM_BUILD_SHARED)
set(PDFMM_BUILD_STATIC FALSE)
else()
set(PDFMM_BUILD_STATIC TRUE)
endif()
endif()
if(NOT DEFINED PDFMM_BUILD_SHARED AND DEFINED PDFMM_BUILD_STATIC)
if(PDFMM_BUILD_STATIC)
set(PDFMM_BUILD_SHARED FALSE)
else()
set(PDFMM_BUILD_SHARED TRUE)
endif()
endif()
if(DEFINED LIB_SUFFIX)
set(LIBDIRNAME "lib${LIB_SUFFIX}")
else()
# Some 64 bit linux distros use /usr/lib64 for 64 bit libraries.
# on these platforms we must
if(NOT DEFINED WANT_LIB64)
# TODO: detect 64-bit build and existance of /usr/lib64 and set to TRUE.
message("WANT_LIB64 unset; assuming normal library directory names")
set(WANT_LIB64 FALSE)
endif()
if(WANT_LIB64)
set(LIBDIRNAME "lib64")
else()
set(LIBDIRNAME "lib")
endif()
endif() # DEFINED LIB_SUFFIX
message("Will install libraries to ${CMAKE_INSTALL_PREFIX}/${LIBDIRNAME}")
# 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(WIN32)
# We must explicitly link to the core win32 libraries
set(PLATFORM_SYSTEM_LIBRARIES kernel32 user32 gdi32 winspool comdlg32 advapi32 shell32 ole32 oleaut32 uuid ws2_32)
else()
set(PLATFORM_SYSTEM_LIBRARIES)
endif()
if (MSVC)
# Set the compiler less permissive and add some warnings
# /w34388: 'expression': signed/unsigned mismatch
# /w34389: 'operator': signed/unsigned mismatch
# /we4287: unsigned/negative constant mismatch
# /w34100: unreferenced formal parameter
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive- /w34388 /w34389 /we4287 /w34100 /Zc:__cplusplus")
# Microsoft deprecate certain POSIX functions that we use.
# for now, turn off these warnings.
add_compile_definitions(_CRT_SECURE_NO_DEPRECATE)
else()
message("Using gcc specific compiler options")
# If the user hasn't specifically said whether they want
# -fvisibility=hidden or not, turn it on if it's said to
# be supported, off for other gcc versions.
if(NOT DEFINED PDFMM_USE_VISIBILITY)
set(PDFMM_USE_VISIBILITY ${PDFMM_HAVE_GCC_SYMBOL_VISIBILITY})
endif()
# TODO: Remove -Wno-format-truncation after porting the
# code to std::fmt as it will be unuseful
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Woverloaded-virtual -Wswitch -Wcast-qual -Wwrite-strings -Wredundant-decls -Wreorder -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 they've enabled the use of symbol visibility, use it.
if(PDFMM_USE_VISIBILITY)
add_definitions(
-DPDFMM_HAVE_GCC_SYMBOL_VISIBILITY
-fvisibility=hidden
)
endif()
endif()
find_package(ZLIB REQUIRED)
message("Found zlib headers in ${ZLIB_INCLUDE_DIR}, library at ${ZLIB_LIBRARIES}")
find_package(OpenSSL REQUIRED)
message("OPENSSL_VERSION: ${OPENSSL_LIBRARIES}")
find_package(Libidn)
if(Libidn_FOUND)
message("Found Libidn headers in ${Libidn_INCLUDE_DIR}, library at ${Libidn_LIBRARIES}")
set(PDFMM_HAVE_LIBIDN TRUE)
message("Libidn found. AES-256 Encryption support will be enabled")
else()
message("Libidn not found. AES-256 Encryption support will be disabled")
endif()
find_package(JPEG)
if(JPEG_FOUND)
message("Found libjpeg headers in ${JPEG_INCLUDE_DIR}, library at ${JPEG_LIBRARIES}")
set(PDFMM_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(PDFMM_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(PDFMM_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}")
find_package(Fontconfig)
if(Fontconfig_FOUND)
set(PDFMM_HAVE_FONTCONFIG TRUE)
message("Found fontconfig headers in ${Fontconfig_INCLUDE_DIRS}, library at ${Fontconfig_LIBRARIES}")
elseif(WIN32)
# Fallback to GDI if FontConfig is missing in Windows
set(PDFMM_HAVE_WIN32GDI TRUE)
endif()
find_package(LibXml2 REQUIRED)
message("Found libxml2 library at ${LIBXML2_LIBRARIES}, headers ${LIBXML2_INCLUDE_DIRS}")
# The pdfmm 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(PDFMM_LIB_DEPENDS
${OPENSSL_LIBRARIES}
${Fontconfig_LIBRARIES}
${FREETYPE_LIBRARIES}
${LIBXML2_LIBRARIES}
${PNG_LIBRARIES}
${TIFF_LIBRARIES}
${JPEG_LIBRARIES}
${ZLIB_LIBRARIES}
${PLATFORM_SYSTEM_LIBRARIES}
)
set(PDFMM_HEADERS_DEPENDS
${OPENSSL_INCLUDE_DIR}
${Fontconfig_INCLUDE_DIRS}
${FREETYPE_INCLUDE_DIRS}
${LIBXML2_INCLUDE_DIRS}
${PNG_INCLUDE_DIR}
${TIFF_INCLUDE_DIR}
${JPEG_INCLUDE_DIR}
${ZLIB_INCLUDE_DIR}
${PLATFORM_SYSTEM_HEADERS}
)
if(Libidn_FOUND)
list(APPEND PDFMM_LIB_DEPENDS ${Libidn_LIBRARIES})
list(APPEND PDFMM_HEADERS_DEPENDS ${Libidn_INCLUDE_DIR})
endif()
# Create the config file. It'll be appended to as the subdirs run though
# then dependency information will be written to it at the end of the
# build.
file(WRITE
"${PROJECT_BINARY_DIR}/pdfmmConfig.cmake"
"# CMake module for pdfmm\n"
)
file(APPEND
"${PROJECT_BINARY_DIR}/pdfmmConfig.cmake"
"set(PDFMM_INCLUDES ${PROJECT_SOURCE_DIR}/src)\n"
)
add_subdirectory(src/pdfmm)
include_directories(${PDFMM_INCLUDE_DIRS})
if(NOT PDFMM_BUILD_LIB_ONLY)
enable_testing()
add_subdirectory(test)
add_subdirectory(examples)
endif()
# Export some variables into the config file so it's easier for others
# to build and link against pdfmm
# To use these dependencies set PDFMM_DIR to the pdfmm BUILD directory in
# your build (eg -DPDFMM_DIR=/path/to/pdfmm when running cmake to configure
# the app that'll use pdfmm). See: find_package(...) in the cmake docs.
if(PDFMM_BUILD_SHARED)
export(TARGETS pdfmm_shared FILE "${PROJECT_BINARY_DIR}/pdfmmConfig.cmake")
endif()
if(PDFMM_BUILD_STATIC)
export(TARGETS pdfmm_static pdfmm_private FILE "${PROJECT_BINARY_DIR}/pdfmmConfig.cmake")
endif()
set(CPACK_PACKAGE_VENDOR "Francesco Pretto")
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_PACKAGE_VERSION ${PDFMM_LIBVERSION})
set(CPACK_GENERATOR "DEB")
include(CPack)