1 | #========================================================================
|
---|
2 | #
|
---|
3 | # xpdf/cmake-xpdf.txt
|
---|
4 | #
|
---|
5 | # CMake script for the Xpdf tools.
|
---|
6 | #
|
---|
7 | # Copyright 2015 Glyph & Cog, LLC
|
---|
8 | #
|
---|
9 | #========================================================================
|
---|
10 |
|
---|
11 | #========================================================================
|
---|
12 | # This is a customised version of Xpdf Tools' CMake file.
|
---|
13 | # Customised for Greenstone.
|
---|
14 | #========================================================================
|
---|
15 |
|
---|
16 | include_directories("${PROJECT_SOURCE_DIR}")
|
---|
17 | include_directories("${PROJECT_BINARY_DIR}")
|
---|
18 | include_directories("${PROJECT_SOURCE_DIR}/goo")
|
---|
19 | include_directories("${PROJECT_SOURCE_DIR}/fofi")
|
---|
20 | include_directories("${PROJECT_SOURCE_DIR}/splash")
|
---|
21 |
|
---|
22 |
|
---|
23 | # For Mac OSX, when -static is passed in for linking, we end up with the error "ld: library not found for -lcrt0.o"
|
---|
24 | # See https://stackoverflow.com/questions/3801011/ld-library-not-found-for-lcrt0-o-on-osx-10-6-with-gcc-clang-static-flag
|
---|
25 | # On Mac OSX, compile it with -Bstatic, as per https://stackoverflow.com/questions/844819/how-to-static-link-on-os-x
|
---|
26 | # XPDFTOOLS.sh will have set the GSDLFLAG_STATIC to either "-static" (for linux) or "-Bstatic" for darwin
|
---|
27 |
|
---|
28 | if(GSDLFLAG_STATIC)
|
---|
29 | message(STATUS "@@@@ GSDLFLAG_STATIC SET. Building xpdf-tools statically.")
|
---|
30 | else ()
|
---|
31 | message(STATUS "@@@@ GSDLFLAG_STATIC not SET. Building dynamically using xpdf-tools' (mostly) original, unmodified linker flags.")
|
---|
32 | endif ()
|
---|
33 | if (PNG_FOUND)
|
---|
34 | include_directories("${PNG_INCLUDE_DIRS}")
|
---|
35 | add_definitions("${PNG_DEFINITIONS}")
|
---|
36 | else ()
|
---|
37 | message(STATUS "@@@@@@@@@@@@@@@ NO PNG_FOUND")
|
---|
38 | endif ()
|
---|
39 | # https://stackoverflow.com/questions/36126333/mingw-cmake-undefined-reference-to-zlib
|
---|
40 | if (ZLIB_FOUND)
|
---|
41 | include_directories("${ZLIB_INCLUDE_DIRS}")
|
---|
42 | add_definitions("${ZLIB_DEFINITIONS}")
|
---|
43 | else ()
|
---|
44 | message(STATUS "@@@@@@@@@@@@@@@ NO ZLIB_FOUND")
|
---|
45 | endif ()
|
---|
46 | if (HAVE_LCMS)
|
---|
47 | include_directories("${LCMS_INCLUDE_DIR}")
|
---|
48 | set(COLOR_MANAGER_SOURCE "ColorManager.cc")
|
---|
49 | if(GSDLFLAG_STATIC)
|
---|
50 | # Untested combination, warn https://cmake.org/cmake/help/v3.0/command/message.html
|
---|
51 | message(AUTHOR_WARNING "@@@@@@@@@@@@@@@ GSDL Warning: static building with HAVE_LCMS on. If running ldd/file on generated binaries shows any binary to be partially a dynamic executable, then Export VERBOSE=1 and re-run the CMake build. Then check the verbose build output's linker flags (for static building) for that binary: they should not be -Wl,-Bstatic LIBS -Wl,-Bdynamic -lpthread but -static LIBS. Fix it by removing all references to LCMS_LIBRARY in the static linking flags of target_link_libraries statements (i.e. when GSDLFLAG_STATIC is set) in file gs-CMakeLists.txt and replacing them with the -l equivalent for the color manager library, (l)cms. @@@@@@@@@@@@@@@")
|
---|
52 | endif ()
|
---|
53 | else ()
|
---|
54 | set(COLOR_MANAGER_SOURCE "")
|
---|
55 | endif ()
|
---|
56 | if (DTYPE_LIBRARY)
|
---|
57 | if(GSDLFLAG_STATIC)
|
---|
58 | # Untested combination, warn
|
---|
59 | message(AUTHOR_WARNING "@@@@@@@@@@@@@@@ GSDL Warning: static building with TYPE_LIBRARY. If running ldd/file on generated binaries shows any binary to be partially a dynamic executable, then export VERBOSE=1 and re-run the CMake build. Then check the verbose build output's linker flags (for static building) for that binary: they should not be -Wl,-Bstatic LIBS -Wl,-Bdynamic -lpthread but -static LIBS. Fix it by removing all references to DTYPE_LIBRARY in the static linking flags of target_link_libraries statements (i.e. when GSDLFLAG_STATIC is set) in file gs-CMakeLists.txt and replacing them with the -l equivalent for typelib. @@@@@@@@@@@@@@@")
|
---|
60 | endif ()
|
---|
61 | endif ()
|
---|
62 | add_library(xpdf_objs OBJECT
|
---|
63 | AcroForm.cc
|
---|
64 | Annot.cc
|
---|
65 | Array.cc
|
---|
66 | BuiltinFont.cc
|
---|
67 | BuiltinFontTables.cc
|
---|
68 | Catalog.cc
|
---|
69 | CharCodeToUnicode.cc
|
---|
70 | CMap.cc
|
---|
71 | ${COLOR_MANAGER_SOURCE}
|
---|
72 | Decrypt.cc
|
---|
73 | Dict.cc
|
---|
74 | Error.cc
|
---|
75 | FontEncodingTables.cc
|
---|
76 | Form.cc
|
---|
77 | Function.cc
|
---|
78 | Gfx.cc
|
---|
79 | GfxFont.cc
|
---|
80 | GfxState.cc
|
---|
81 | GlobalParams.cc
|
---|
82 | JArithmeticDecoder.cc
|
---|
83 | JBIG2Stream.cc
|
---|
84 | JPXStream.cc
|
---|
85 | Lexer.cc
|
---|
86 | Link.cc
|
---|
87 | NameToCharCode.cc
|
---|
88 | Object.cc
|
---|
89 | OptionalContent.cc
|
---|
90 | Outline.cc
|
---|
91 | OutputDev.cc
|
---|
92 | Page.cc
|
---|
93 | Parser.cc
|
---|
94 | PDFDoc.cc
|
---|
95 | PDFDocEncoding.cc
|
---|
96 | PSTokenizer.cc
|
---|
97 | SecurityHandler.cc
|
---|
98 | Stream.cc
|
---|
99 | TextString.cc
|
---|
100 | UnicodeMap.cc
|
---|
101 | UnicodeTypeTable.cc
|
---|
102 | UTF8.cc
|
---|
103 | XFAForm.cc
|
---|
104 | XRef.cc
|
---|
105 | Zoox.cc
|
---|
106 | )
|
---|
107 |
|
---|
108 | #--- object files needed by XpdfWidget
|
---|
109 |
|
---|
110 | if ((QT4_FOUND OR Qt5Widgets_FOUND)
|
---|
111 | AND HAVE_SPLASH AND MULTITHREADED AND USE_EXCEPTIONS)
|
---|
112 |
|
---|
113 | if (HIGHLIGHTED_REGIONS)
|
---|
114 | set(HIGHLIGHT_SRC "HighlightFile.cc")
|
---|
115 | else ()
|
---|
116 | set(HIGHLIGHT_SRC "")
|
---|
117 | endif ()
|
---|
118 |
|
---|
119 | add_library(xpdf_widget_objs OBJECT
|
---|
120 | DisplayState.cc
|
---|
121 | PDFCore.cc
|
---|
122 | PreScanOutputDev.cc
|
---|
123 | PSOutputDev.cc
|
---|
124 | SplashOutputDev.cc
|
---|
125 | TextOutputDev.cc
|
---|
126 | TileCache.cc
|
---|
127 | TileCompositor.cc
|
---|
128 | TileMap.cc
|
---|
129 | ${HIGHLIGHT_SRC}
|
---|
130 | )
|
---|
131 | endif ()
|
---|
132 |
|
---|
133 | # We want to build static xpdf-tools binaries. See
|
---|
134 | # https://stackoverflow.com/questions/24648357/compiling-a-static-executable-with-cmake
|
---|
135 | # Want to make the min number of changes for building statically, so using the way
|
---|
136 | # below. Beware, must *append* "-static" to existing CMAKE_EXE_LINKER_FLAGS=LD_FLAGS
|
---|
137 | ##SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
---|
138 | ##SET(BUILD_SHARED_LIBS OFF)
|
---|
139 | ##SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
|
---|
140 |
|
---|
141 | # The original, unmodified CMakeLists.txt was not set up sufficiently
|
---|
142 | # for static compilation of xpdf-tools. As a result, compile would first fail
|
---|
143 | # with errors about undefined refs to mutex / lpthread.
|
---|
144 | # When building xpdf-tools statically, need to add the following 2 lines as well
|
---|
145 | # as append "Threads::Threads" to the end of each "target_link_libraries(<list>)"
|
---|
146 | # See https://stackoverflow.com/questions/1620918/cmake-and-libpthread
|
---|
147 | # found googling cmake and "-lpthread" (pthread) after ERRORS to do with this, like:
|
---|
148 | # undefined reference to `pthread_mutex_unlock'
|
---|
149 | ##set(THREADS_PREFER_PTHREAD_FLAG ON)
|
---|
150 | ##find_package(Threads REQUIRED)
|
---|
151 |
|
---|
152 | #--- pdftops
|
---|
153 |
|
---|
154 | if (HAVE_SPLASH)
|
---|
155 | add_executable(pdftops
|
---|
156 | $<TARGET_OBJECTS:xpdf_objs>
|
---|
157 | PreScanOutputDev.cc
|
---|
158 | PSOutputDev.cc
|
---|
159 | SplashOutputDev.cc
|
---|
160 | pdftops.cc
|
---|
161 | )
|
---|
162 | if(GSDLFLAG_STATIC)
|
---|
163 | target_link_libraries(pdftops goo fofi splash
|
---|
164 | ${GSDLFLAG_STATIC} -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lz -lm -lc -lpthread)
|
---|
165 | # Threads::Threads instead of -lpthread results in a partially dynamic executable
|
---|
166 | else ()
|
---|
167 | target_link_libraries(pdftops goo fofi splash
|
---|
168 | ${FREETYPE_LIBRARY} ${FREETYPE_OTHER_LIBS}
|
---|
169 | ${DTYPE_LIBRARY}
|
---|
170 | ${LCMS_LIBRARY}
|
---|
171 | ${ZLIB_LIBRARIES})
|
---|
172 | endif ()
|
---|
173 | else ()
|
---|
174 | add_executable(pdftops
|
---|
175 | $<TARGET_OBJECTS:xpdf_objs>
|
---|
176 | PreScanOutputDev.cc
|
---|
177 | PSOutputDev.cc
|
---|
178 | pdftops.cc
|
---|
179 | )
|
---|
180 | if(GSDLFLAG_STATIC)
|
---|
181 | target_link_libraries(pdftops goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lm -lc -lpthread)
|
---|
182 | else ()
|
---|
183 | target_link_libraries(pdftops goo fofi ${LCMS_LIBRARY})
|
---|
184 | endif ()
|
---|
185 | endif ()
|
---|
186 | install(TARGETS pdftops RUNTIME DESTINATION bin)
|
---|
187 | install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftops.1 DESTINATION man/man1)
|
---|
188 |
|
---|
189 | #--- pdftotext
|
---|
190 |
|
---|
191 | add_executable(pdftotext
|
---|
192 | $<TARGET_OBJECTS:xpdf_objs>
|
---|
193 | TextOutputDev.cc
|
---|
194 | pdftotext.cc
|
---|
195 | )
|
---|
196 | if(GSDLFLAG_STATIC)
|
---|
197 | target_link_libraries(pdftotext goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
|
---|
198 | # Threads::Threads instead of -lpthread results in a partially dynamic executable
|
---|
199 | else ()
|
---|
200 | target_link_libraries(pdftotext goo fofi ${LCMS_LIBRARY})
|
---|
201 | endif ()
|
---|
202 | install(TARGETS pdftotext RUNTIME DESTINATION bin)
|
---|
203 | install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftotext.1 DESTINATION man/man1)
|
---|
204 |
|
---|
205 | #--- pdftohtml
|
---|
206 |
|
---|
207 | if (HAVE_SPLASH AND PNG_FOUND)
|
---|
208 | add_executable(pdftohtml
|
---|
209 | $<TARGET_OBJECTS:xpdf_objs>
|
---|
210 | HTMLGen.cc
|
---|
211 | SplashOutputDev.cc
|
---|
212 | TextOutputDev.cc
|
---|
213 | pdftohtml.cc
|
---|
214 | )
|
---|
215 | if(GSDLFLAG_STATIC)
|
---|
216 | target_link_libraries(pdftohtml goo fofi splash
|
---|
217 | ${GSDLFLAG_STATIC} -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lpng -lz -lm -lc -lpthread)
|
---|
218 | else ()
|
---|
219 | target_link_libraries(pdftohtml goo fofi splash
|
---|
220 | ${FREETYPE_LIBRARY} ${FREETYPE_OTHER_LIBS}
|
---|
221 | ${DTYPE_LIBRARY}
|
---|
222 | ${LCMS_LIBRARY} ${PNG_LIBRARIES})
|
---|
223 | endif ()
|
---|
224 | # Doing the regular target_link_libraries() in static mode results in building with
|
---|
225 | # "-Wl,-Bstatic -lfreetype -lpng15 -lz -Wl,-Bdynamic -lpthread" at end of link line
|
---|
226 | # and produces broken binaries for pdftohtml/pdftoppm/pdftops/pdftopng.
|
---|
227 | # Note that PNG_LIBRARIES includes zlib/lz: "-lpng -lz", and along with freetype,
|
---|
228 | # these are linked statically. However, Threads/lpthread is included as a dynamically
|
---|
229 | # linked library instead of including a .a (regardless of whether it's appended
|
---|
230 | # as -lpthread or Threads::Threads in else above), contributing to the pdfhtml binary
|
---|
231 | # produced being a partially static, partially dynamic one,
|
---|
232 | # so a dynamic executable overall.
|
---|
233 | # The order of dynamic .so files listed by ldd in the broken binary differs from
|
---|
234 | # a manually linked working version of pdftohtml, and seems to be the only difference
|
---|
235 | # between the two in ldd output. Not using "-Wl,-Bstatic" and using -static (-Bstatic on Mac)
|
---|
236 | # in its place creates a partially static dynamic executable that isn't broken, whereas
|
---|
237 | # additionally removing "-Wl,-Bdynamic -lpthread" and replacing it with -lpthread
|
---|
238 | # moreover produces a working pdftohtml that is a fully static linked executable.
|
---|
239 | # The inclusion of the math lib and c lib (lm and lc) in the final link command
|
---|
240 | # are to completely bypass the remaining .so dependencies that were present in
|
---|
241 | # the executable and produce the fully static executable.
|
---|
242 | # Not sure what colormanager (lcms) and typelibrary, or how they're written in -l
|
---|
243 | # form as they were not present when the original unmodified static linking command
|
---|
244 | # was run, so they've not been included in the replacement static linking command.
|
---|
245 | install(TARGETS pdftohtml RUNTIME DESTINATION bin)
|
---|
246 | install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftohtml.1 DESTINATION man/man1)
|
---|
247 | endif ()
|
---|
248 |
|
---|
249 | #--- pdfinfo
|
---|
250 |
|
---|
251 | add_executable(pdfinfo
|
---|
252 | $<TARGET_OBJECTS:xpdf_objs>
|
---|
253 | pdfinfo.cc
|
---|
254 | )
|
---|
255 | if(GSDLFLAG_STATIC)
|
---|
256 | target_link_libraries(pdfinfo goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
|
---|
257 | else ()
|
---|
258 | target_link_libraries(pdfinfo goo fofi ${LCMS_LIBRARY})
|
---|
259 | endif()
|
---|
260 | install(TARGETS pdfinfo RUNTIME DESTINATION bin)
|
---|
261 | install(FILES ${PROJECT_SOURCE_DIR}/doc/pdfinfo.1 DESTINATION man/man1)
|
---|
262 |
|
---|
263 | #--- pdffonts
|
---|
264 |
|
---|
265 | add_executable(pdffonts
|
---|
266 | $<TARGET_OBJECTS:xpdf_objs>
|
---|
267 | pdffonts.cc
|
---|
268 | )
|
---|
269 | if(GSDLFLAG_STATIC)
|
---|
270 | target_link_libraries(pdffonts goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
|
---|
271 | else ()
|
---|
272 | target_link_libraries(pdffonts goo fofi ${LCMS_LIBRARY})
|
---|
273 | endif ()
|
---|
274 | install(TARGETS pdffonts RUNTIME DESTINATION bin)
|
---|
275 | install(FILES ${PROJECT_SOURCE_DIR}/doc/pdffonts.1 DESTINATION man/man1)
|
---|
276 |
|
---|
277 | #--- pdfdetach
|
---|
278 |
|
---|
279 | add_executable(pdfdetach
|
---|
280 | $<TARGET_OBJECTS:xpdf_objs>
|
---|
281 | pdfdetach.cc
|
---|
282 | )
|
---|
283 | if(GSDLFLAG_STATIC)
|
---|
284 | target_link_libraries(pdfdetach goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
|
---|
285 | else ()
|
---|
286 | target_link_libraries(pdfdetach goo fofi ${LCMS_LIBRARY})
|
---|
287 | endif ()
|
---|
288 | install(TARGETS pdfdetach RUNTIME DESTINATION bin)
|
---|
289 | install(FILES ${PROJECT_SOURCE_DIR}/doc/pdfdetach.1 DESTINATION man/man1)
|
---|
290 |
|
---|
291 | #--- pdftoppm
|
---|
292 |
|
---|
293 | if (HAVE_SPLASH)
|
---|
294 | add_executable(pdftoppm
|
---|
295 | $<TARGET_OBJECTS:xpdf_objs>
|
---|
296 | SplashOutputDev.cc
|
---|
297 | pdftoppm.cc
|
---|
298 | )
|
---|
299 | if(GSDLFLAG_STATIC)
|
---|
300 | target_link_libraries(pdftoppm goo fofi splash
|
---|
301 | ${GSDLFLAG_STATIC} -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lz -lm -lc -lpthread)
|
---|
302 | else ()
|
---|
303 | target_link_libraries(pdftoppm goo fofi splash
|
---|
304 | ${FREETYPE_LIBRARY} ${FREETYPE_OTHER_LIBS}
|
---|
305 | ${DTYPE_LIBRARY}
|
---|
306 | ${LCMS_LIBRARY}
|
---|
307 | ${ZLIB_LIBRARIES})
|
---|
308 | endif ()
|
---|
309 | install(TARGETS pdftoppm RUNTIME DESTINATION bin)
|
---|
310 | install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftoppm.1 DESTINATION man/man1)
|
---|
311 | endif ()
|
---|
312 |
|
---|
313 | #--- pdftopng
|
---|
314 |
|
---|
315 | if (HAVE_SPLASH AND PNG_FOUND)
|
---|
316 | add_executable(pdftopng
|
---|
317 | $<TARGET_OBJECTS:xpdf_objs>
|
---|
318 | SplashOutputDev.cc
|
---|
319 | pdftopng.cc
|
---|
320 | )
|
---|
321 | if(GSDLFLAG_STATIC)
|
---|
322 | target_link_libraries(pdftopng goo fofi splash
|
---|
323 | ${GSDLFLAG_STATIC} -lfreetype ${DTYPE_LIBRARY} ${LCMS_LIBRARY} -lpng -lz -lm -lc -lpthread)
|
---|
324 | else ()
|
---|
325 | target_link_libraries(pdftopng goo fofi splash
|
---|
326 | ${FREETYPE_LIBRARY} ${FREETYPE_OTHER_LIBS}
|
---|
327 | ${DTYPE_LIBRARY}
|
---|
328 | ${LCMS_LIBRARY} ${PNG_LIBRARIES})
|
---|
329 | endif ()
|
---|
330 | install(TARGETS pdftopng RUNTIME DESTINATION bin)
|
---|
331 | install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftopng.1 DESTINATION man/man1)
|
---|
332 | endif ()
|
---|
333 |
|
---|
334 | #--- pdfimages
|
---|
335 |
|
---|
336 | add_executable(pdfimages
|
---|
337 | $<TARGET_OBJECTS:xpdf_objs>
|
---|
338 | ImageOutputDev.cc
|
---|
339 | pdfimages.cc
|
---|
340 | )
|
---|
341 | if(GSDLFLAG_STATIC)
|
---|
342 | target_link_libraries(pdfimages goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
|
---|
343 | else ()
|
---|
344 | target_link_libraries(pdfimages goo fofi ${LCMS_LIBRARY})
|
---|
345 | endif ()
|
---|
346 | install(TARGETS pdfimages RUNTIME DESTINATION bin)
|
---|
347 | install(FILES ${PROJECT_SOURCE_DIR}/doc/pdfimages.1 DESTINATION man/man1)
|
---|
348 |
|
---|
349 | #--- xpdfrc man page
|
---|
350 |
|
---|
351 | install(FILES ${PROJECT_SOURCE_DIR}/doc/xpdfrc.5 DESTINATION man/man5)
|
---|