source: gs2-extensions/xpdf-tools/trunk/src/packages/gs-CMakeLists.txt@ 32246

Last change on this file since 32246 was 32246, checked in by ak19, 6 years ago

I'm unable so far to get xpdf-tools to build statically on the mac. These are the changes to get it to build on the Mac in an attempt to make static xpdf-tools binaries. Running otool minus L on the binaries however shows that they're linking to dylib dlls, albeit our ones for freetype, libpng and zlib.

File size: 12.6 KB
Line 
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
16include_directories("${PROJECT_SOURCE_DIR}")
17include_directories("${PROJECT_BINARY_DIR}")
18include_directories("${PROJECT_SOURCE_DIR}/goo")
19include_directories("${PROJECT_SOURCE_DIR}/fofi")
20include_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
28if(GSDLFLAG_STATIC)
29 message(STATUS "@@@@ GSDLFLAG_STATIC SET. Building xpdf-tools statically.")
30else ()
31 message(STATUS "@@@@ GSDLFLAG_STATIC not SET. Building dynamically using xpdf-tools' (mostly) original, unmodified linker flags.")
32endif ()
33if (PNG_FOUND)
34 include_directories("${PNG_INCLUDE_DIRS}")
35 add_definitions("${PNG_DEFINITIONS}")
36else ()
37 message(STATUS "@@@@@@@@@@@@@@@ NO PNG_FOUND")
38endif ()
39# https://stackoverflow.com/questions/36126333/mingw-cmake-undefined-reference-to-zlib
40if (ZLIB_FOUND)
41 include_directories("${ZLIB_INCLUDE_DIRS}")
42 add_definitions("${ZLIB_DEFINITIONS}")
43else ()
44 message(STATUS "@@@@@@@@@@@@@@@ NO ZLIB_FOUND")
45endif ()
46if (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 ()
53else ()
54 set(COLOR_MANAGER_SOURCE "")
55endif ()
56if (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 ()
61endif ()
62add_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
110if ((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 )
131endif ()
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
154if (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 ()
173else ()
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 ()
185endif ()
186install(TARGETS pdftops RUNTIME DESTINATION bin)
187install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftops.1 DESTINATION man/man1)
188
189#--- pdftotext
190
191add_executable(pdftotext
192 $<TARGET_OBJECTS:xpdf_objs>
193 TextOutputDev.cc
194 pdftotext.cc
195)
196if(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
199else ()
200 target_link_libraries(pdftotext goo fofi ${LCMS_LIBRARY})
201endif ()
202install(TARGETS pdftotext RUNTIME DESTINATION bin)
203install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftotext.1 DESTINATION man/man1)
204
205#--- pdftohtml
206
207if (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)
247endif ()
248
249#--- pdfinfo
250
251add_executable(pdfinfo
252 $<TARGET_OBJECTS:xpdf_objs>
253 pdfinfo.cc
254)
255if(GSDLFLAG_STATIC)
256 target_link_libraries(pdfinfo goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
257else ()
258 target_link_libraries(pdfinfo goo fofi ${LCMS_LIBRARY})
259endif()
260install(TARGETS pdfinfo RUNTIME DESTINATION bin)
261install(FILES ${PROJECT_SOURCE_DIR}/doc/pdfinfo.1 DESTINATION man/man1)
262
263#--- pdffonts
264
265add_executable(pdffonts
266 $<TARGET_OBJECTS:xpdf_objs>
267 pdffonts.cc
268)
269if(GSDLFLAG_STATIC)
270 target_link_libraries(pdffonts goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
271else ()
272 target_link_libraries(pdffonts goo fofi ${LCMS_LIBRARY})
273endif ()
274install(TARGETS pdffonts RUNTIME DESTINATION bin)
275install(FILES ${PROJECT_SOURCE_DIR}/doc/pdffonts.1 DESTINATION man/man1)
276
277#--- pdfdetach
278
279add_executable(pdfdetach
280 $<TARGET_OBJECTS:xpdf_objs>
281 pdfdetach.cc
282)
283if(GSDLFLAG_STATIC)
284 target_link_libraries(pdfdetach goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
285else ()
286 target_link_libraries(pdfdetach goo fofi ${LCMS_LIBRARY})
287endif ()
288install(TARGETS pdfdetach RUNTIME DESTINATION bin)
289install(FILES ${PROJECT_SOURCE_DIR}/doc/pdfdetach.1 DESTINATION man/man1)
290
291#--- pdftoppm
292
293if (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)
311endif ()
312
313#--- pdftopng
314
315if (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)
332endif ()
333
334#--- pdfimages
335
336add_executable(pdfimages
337 $<TARGET_OBJECTS:xpdf_objs>
338 ImageOutputDev.cc
339 pdfimages.cc
340)
341if(GSDLFLAG_STATIC)
342 target_link_libraries(pdfimages goo fofi ${GSDLFLAG_STATIC} ${LCMS_LIBRARY} -lpthread)
343else ()
344 target_link_libraries(pdfimages goo fofi ${LCMS_LIBRARY})
345endif ()
346install(TARGETS pdfimages RUNTIME DESTINATION bin)
347install(FILES ${PROJECT_SOURCE_DIR}/doc/pdfimages.1 DESTINATION man/man1)
348
349#--- xpdfrc man page
350
351install(FILES ${PROJECT_SOURCE_DIR}/doc/xpdfrc.5 DESTINATION man/man5)
Note: See TracBrowser for help on using the repository browser.