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