kermitt2 / xpdf-4.00

GNU General Public License v2.0
14 stars 12 forks source link

Building with libpaper present requires a few cmake changes #1

Closed wehlutyk closed 6 years ago

wehlutyk commented 6 years ago

Hi!

I was trying to build this on Arch Linux (where I have libpaper installed), and the build fails with:

[ 40%] Linking CXX executable pdfinfo
CMakeFiles/xpdf_objs.dir/GlobalParams.cc.o: In function `GlobalParams::GlobalParams(char const*)':
GlobalParams.cc:(.text+0xde1): undefined reference to `paperinit'
GlobalParams.cc:(.text+0xde6): undefined reference to `systempapername'
GlobalParams.cc:(.text+0xe02): undefined reference to `paperinfo'
GlobalParams.cc:(.text+0xe12): undefined reference to `paperpswidth'
GlobalParams.cc:(.text+0xe29): undefined reference to `paperpsheight'
GlobalParams.cc:(.text+0xe6e): undefined reference to `paperdone'
collect2: error: ld returned 1 exit status
make[2]: *** [xpdf/CMakeFiles/pdfinfo.dir/build.make:170: xpdf/pdfinfo] Error 1
make[1]: *** [CMakeFiles/Makefile2:392: xpdf/CMakeFiles/pdfinfo.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

Indeed, the Arch xpdf package has a patch (among others) to properly build with libpaper.

Adapting it to work with the fix of xpdf-qt target name made in 61eb5e40fb75be0628123b50d9b6f6344ebd2db4 makes this:

diff -up xpdf-4.00/xpdf/CMakeLists.txt.paperfix xpdf-4.00/xpdf/CMakeLists.txt
--- xpdf-4.00/xpdf/CMakeLists.txt.paperfix  2017-08-08 19:22:50.000000000 -0400
+++ xpdf-4.00/xpdf/CMakeLists.txt   2017-08-16 19:40:19.103263736 -0400
@@ -108,7 +108,7 @@ if (HAVE_SPLASH)
   target_link_libraries(pdftops goo fofi splash
                         ${FREETYPE_LIBRARY} ${FREETYPE_OTHER_LIBS}
                         ${DTYPE_LIBRARY}
-                        ${LCMS_LIBRARY})
+                        ${LCMS_LIBRARY} ${HAVE_PAPER_H})
 else ()
   add_executable(pdftops
     $<TARGET_OBJECTS:xpdf_objs>
@@ -116,7 +116,7 @@ else ()
     PSOutputDev.cc
     pdftops.cc
   )
-  target_link_libraries(pdftops goo fofi ${LCMS_LIBRARY})
+  target_link_libraries(pdftops goo fofi ${LCMS_LIBRARY} ${HAVE_PAPER_H})
 endif ()
 install(TARGETS pdftops RUNTIME DESTINATION bin)
 install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftops.1 DESTINATION man/man1)
@@ -128,7 +128,7 @@ add_executable(pdftotext
   TextOutputDev.cc
   pdftotext.cc
 )
-target_link_libraries(pdftotext goo fofi ${LCMS_LIBRARY})
+target_link_libraries(pdftotext goo fofi ${LCMS_LIBRARY} ${HAVE_PAPER_H})
 install(TARGETS pdftotext RUNTIME DESTINATION bin)
 install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftotext.1 DESTINATION man/man1)

@@ -145,7 +145,7 @@ if (HAVE_SPLASH AND PNG_FOUND)
   target_link_libraries(pdftohtml goo fofi splash
                         ${FREETYPE_LIBRARY} ${FREETYPE_OTHER_LIBS}
                         ${DTYPE_LIBRARY}
-                        ${LCMS_LIBRARY} ${PNG_LIBRARIES})
+                        ${LCMS_LIBRARY} ${PNG_LIBRARIES} ${HAVE_PAPER_H})
   install(TARGETS pdftohtml RUNTIME DESTINATION bin)
   install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftohtml.1 DESTINATION man/man1)
 endif ()
@@ -156,7 +156,7 @@ add_executable(pdfinfo
   $<TARGET_OBJECTS:xpdf_objs>
   pdfinfo.cc
 )
-target_link_libraries(pdfinfo goo fofi ${LCMS_LIBRARY})
+target_link_libraries(pdfinfo goo fofi ${LCMS_LIBRARY} ${HAVE_PAPER_H})
 install(TARGETS pdfinfo RUNTIME DESTINATION bin)
 install(FILES ${PROJECT_SOURCE_DIR}/doc/pdfinfo.1 DESTINATION man/man1)

@@ -166,7 +166,7 @@ add_executable(pdffonts
   $<TARGET_OBJECTS:xpdf_objs>
   pdffonts.cc
 )
-target_link_libraries(pdffonts goo fofi ${LCMS_LIBRARY})
+target_link_libraries(pdffonts goo fofi ${LCMS_LIBRARY} ${HAVE_PAPER_H})
 install(TARGETS pdffonts RUNTIME DESTINATION bin)
 install(FILES ${PROJECT_SOURCE_DIR}/doc/pdffonts.1 DESTINATION man/man1)

@@ -176,7 +176,7 @@ add_executable(pdfdetach
   $<TARGET_OBJECTS:xpdf_objs>
   pdfdetach.cc
 )
-target_link_libraries(pdfdetach goo fofi ${LCMS_LIBRARY})
+target_link_libraries(pdfdetach goo fofi ${LCMS_LIBRARY} ${HAVE_PAPER_H})
 install(TARGETS pdfdetach RUNTIME DESTINATION bin)
 install(FILES ${PROJECT_SOURCE_DIR}/doc/pdfdetach.1 DESTINATION man/man1)

@@ -191,7 +191,7 @@ if (HAVE_SPLASH)
   target_link_libraries(pdftoppm goo fofi splash
                         ${FREETYPE_LIBRARY} ${FREETYPE_OTHER_LIBS}
                         ${DTYPE_LIBRARY}
-                        ${LCMS_LIBRARY})
+                        ${LCMS_LIBRARY} ${HAVE_PAPER_H})
   install(TARGETS pdftoppm RUNTIME DESTINATION bin)
   install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftoppm.1 DESTINATION man/man1)
 endif ()
@@ -207,7 +207,7 @@ if (HAVE_SPLASH AND PNG_FOUND)
   target_link_libraries(pdftopng goo fofi splash
                         ${FREETYPE_LIBRARY} ${FREETYPE_OTHER_LIBS}
                         ${DTYPE_LIBRARY}
-                        ${LCMS_LIBRARY} ${PNG_LIBRARIES})
+                        ${LCMS_LIBRARY} ${PNG_LIBRARIES} ${HAVE_PAPER_H})
   install(TARGETS pdftopng RUNTIME DESTINATION bin)
   install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftopng.1 DESTINATION man/man1)
 endif ()
@@ -219,7 +219,7 @@ add_executable(pdfimages
   ImageOutputDev.cc
   pdfimages.cc
 )
-target_link_libraries(pdfimages goo fofi ${LCMS_LIBRARY})
+target_link_libraries(pdfimages goo fofi ${LCMS_LIBRARY} ${HAVE_PAPER_H})
 install(TARGETS pdfimages RUNTIME DESTINATION bin)
 install(FILES ${PROJECT_SOURCE_DIR}/doc/pdfimages.1 DESTINATION man/man1)

diff -up xpdf-4.00/xpdf-qt/CMakeLists.txt.paperfix xpdf-4.00/xpdf-qt/CMakeLists.txt
--- xpdf-4.00/xpdf-qt/CMakeLists.txt.paperfix   2017-08-16 19:39:23.275757290 -0400
+++ xpdf-4.00/xpdf-qt/CMakeLists.txt    2017-08-16 19:39:47.810100923 -0400
@@ -83,7 +83,7 @@ if ((QT4_FOUND OR Qt5Widgets_FOUND)
   target_link_libraries(xpdf-qt ${QT_LIBRARIES} ${EXTRA_QT_LIBRARIES}
                         ${FREETYPE_LIBRARY} ${FREETYPE_OTHER_LIBS}
                         ${DTYPE_LIBRARY} ${LCMS_LIBRARY}
-                        ${CMAKE_THREAD_LIBS_INIT})
+                        ${CMAKE_THREAD_LIBS_INIT} ${HAVE_PAPER_H})
   set_property(TARGET xpdf-qt PROPERTY WIN32_EXECUTABLE 1)

   install(TARGETS xpdf-qt RUNTIME DESTINATION bin)

I can PR this if you want, but I haven't tested it when libpaper is not present (that would break my system). Is this an issue you've encountered?

Aazhar commented 6 years ago

Hello, XPDF uses libpaper to pre-fill some missing parameters about the page dimensions, so if it's not installed it will give errors and this library is no mandatory.

wehlutyk commented 6 years ago

In that case you still need to declare it in the CMake link libraries, don't you?

wehlutyk commented 6 years ago

Ok I see now with your answer in kermitt2/pdfalto#2 "libpaper is not mandatory". Indeed! My point is that when libpaper is present on the system, some part of the build system finds it and tries to build xpdf with it, which fails because the target_link_libraries are not set well. My changes don't make libpaper mandatory, they make so that it builds properly whether libpaper is present or not.

Aazhar commented 6 years ago

actually the problem is that the cmake function 'find_library', looks for libpaper and saves the path if it finds it in HAVE_PAPER_H otherwise it is set to NOTFOUND which lead to build fail, so a verification should be done with an if-else statement in cmake configuration, would you PR it please ?

wehlutyk commented 6 years ago

I see, I can reproduce the build error when libpaper is not found. I just made the PR which for me works with and without libpaper present on the system.