Changeset 32237

Show
Ignore:
Timestamp:
05.07.2018 19:38:36 (2 weeks ago)
Author:
ak19
Message:

Rewrote gs-CMakeLists.txt in a tidier way to successfully build working static xpdftools binaries, replacing the previously committed temporary gs-CMakeLists.txt.staticworks file wit its sloppier contents . The changes to gs-CMakeLists.txt now take into account a new variable introduced and set in XPDFTOOLS.sh: GSDLFLAG_STATIC_BUILD. When building statically, set PNG_LIBRARY, ZLIB_LIBRARY, FREETYPE_LIBRARY to their generated .a files and now also set GSDLFLAG_STATIC_BUILD to dummy value true. When wanting to go back to dynamic building for any reason, either don't set any of the LIBRARY packages or set them to their specific real (not symbolical link) generated .so files. In case of dynamic building, additionally do NOT set GSDLFLAG_STATIC_BUILD at all, whether to true or false. Then the gs-CMakeLists.txt follows the internal code branches to use the original code to generate dynamically linked xpdftools binaries.

Location:
gs2-extensions/xpdf-tools/trunk/src/packages
Files:
1 removed
2 modified

Legend:

Unmodified
Added
Removed
  • gs2-extensions/xpdf-tools/trunk/src/packages/CASCADE-MAKE/XPDFTOOLS.sh

    r32235 r32237  
    7272        -DCMAKE_CXX_FLAGS="$CXXFLAGS" \ 
    7373        -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS" \ 
     74        -DGSDLFLAG_STATIC_BUILD="true" \ 
    7475        $GEXT_XPDFTOOLS/packages/$package$version 
    7576    fi ; \ 
     
    9495#       -DPNG_LIBRARY=$prefix/lib/libpng15.a \ 
    9596#       -DFREETYPE_LIBRARY=$prefix/lib/libfreetype.a \ 
    96 # else, in place of FREETYPE_LIBRARY: 
     97# And throw in -DGSDLFLAG_STATIC_BUILD="true" 
     98# In place of FREETYPE_LIBRARY, could also try the following (then check built bins 
     99# by running ldd and file over them): 
    97100##      -DFREETYPE_DIR=$prefix \ 
     101 
    98102 
    99103## When -DFREETYPE_DIR is used in place of -DFREETYPE_LIBRARY above, it makes 
     
    113117#       -DPNG_LIBRARY=$prefix/lib/libpng15.so.15.30.0 \ 
    114118#       -DFREETYPE_LIBRARY=$prefix/lib/libfreetype.so.6.3.20 \ 
    115  
     119# The above is for building dynamic xpdf-tools executables. For which, also don't 
     120# pass in -DGSDLFLAG_STATIC_BUILD="true" (remove the line, don't comment it out, nor 
     121# set the value to false) 
    116122 
    117123# If compilation was successful, then we don't need cmake binaries anymore when 
  • gs2-extensions/xpdf-tools/trunk/src/packages/gs-CMakeLists.txt

    r32234 r32237  
    1919include_directories("${PROJECT_SOURCE_DIR}/fofi") 
    2020include_directories("${PROJECT_SOURCE_DIR}/splash") 
     21 
     22if(GSDLFLAG_STATIC_BUILD) 
     23  message(STATUS "@@@@ GSDLFLAG_STATIC_BUILD SET. Building xpdf-tools statically.") 
     24else () 
     25  message(STATUS "@@@@ GSDLFLAG_STATIC_BUILD not SET. Building dynamically using xpdf-tools' (mostly) original, unmodified linker flags.") 
     26endif () 
    2127if (PNG_FOUND) 
    2228  include_directories("${PNG_INCLUDE_DIRS}") 
     
    3541  include_directories("${LCMS_INCLUDE_DIR}") 
    3642  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 () 
    3747else () 
    3848  set(COLOR_MANAGER_SOURCE "") 
    3949endif () 
    40  
     50if (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 () 
     55endif () 
    4156add_library(xpdf_objs OBJECT 
    4257  AcroForm.cc 
     
    114129# Want to make the min number of changes for building statically, so using the way 
    115130# below. Beware, must *append* "-static" to existing CMAKE_EXE_LINKER_FLAGS=LD_FLAGS 
    116 SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") 
    117 SET(BUILD_SHARED_LIBS OFF) 
    118 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") 
     131##SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") 
     132##SET(BUILD_SHARED_LIBS OFF) 
     133##SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") 
    119134 
    120135# The original, unmodified CMakeLists.txt was not set up sufficiently 
     
    126141# found googling cmake and "-lpthread" (pthread) after ERRORS to do with this, like: 
    127142#   undefined reference to `pthread_mutex_unlock' 
    128 set(THREADS_PREFER_PTHREAD_FLAG ON) 
    129 find_package(Threads REQUIRED) 
     143##set(THREADS_PREFER_PTHREAD_FLAG ON) 
     144##find_package(Threads REQUIRED) 
    130145 
    131146#--- pdftops 
     
    138153    SplashOutputDev.cc 
    139154    pdftops.cc 
    140   ) 
    141   target_link_libraries(pdftops goo fofi splash 
     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 
    142162                        ${FREETYPE_LIBRARY} ${FREETYPE_OTHER_LIBS} 
    143             ${ZLIB_LIBRARIES} 
    144163                        ${DTYPE_LIBRARY} 
    145164                        ${LCMS_LIBRARY} 
    146             Threads::Threads) 
     165            ${ZLIB_LIBRARIES}) 
     166  endif () 
    147167else () 
    148168  add_executable(pdftops 
     
    152172    pdftops.cc 
    153173  ) 
    154   target_link_libraries(pdftops goo fofi ${LCMS_LIBRARY} Threads::Threads) 
     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 () 
    155179endif () 
    156180install(TARGETS pdftops RUNTIME DESTINATION bin) 
     
    164188  pdftotext.cc 
    165189) 
    166 target_link_libraries(pdftotext goo fofi ${LCMS_LIBRARY} Threads::Threads) 
     190if(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 
     193else () 
     194  target_link_libraries(pdftotext goo fofi ${LCMS_LIBRARY}) 
     195endif () 
    167196install(TARGETS pdftotext RUNTIME DESTINATION bin) 
    168197install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftotext.1 DESTINATION man/man1) 
     
    178207    pdftohtml.cc 
    179208  ) 
    180   target_link_libraries(pdftohtml goo fofi splash 
     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) 
     241endif () 
     242 
     243#--- pdfinfo 
     244 
     245add_executable(pdfinfo 
     246  $<TARGET_OBJECTS:xpdf_objs> 
     247  pdfinfo.cc 
     248) 
     249if(GSDLFLAG_STATIC_BUILD) 
     250  target_link_libraries(pdfinfo goo fofi -static ${LCMS_LIBRARY} -lpthread) 
     251else () 
     252  target_link_libraries(pdfinfo goo fofi ${LCMS_LIBRARY}) 
     253endif() 
     254install(TARGETS pdfinfo RUNTIME DESTINATION bin) 
     255install(FILES ${PROJECT_SOURCE_DIR}/doc/pdfinfo.1 DESTINATION man/man1) 
     256 
     257#--- pdffonts 
     258 
     259add_executable(pdffonts 
     260  $<TARGET_OBJECTS:xpdf_objs> 
     261  pdffonts.cc 
     262) 
     263if(GSDLFLAG_STATIC_BUILD) 
     264  target_link_libraries(pdffonts goo fofi -static ${LCMS_LIBRARY} -lpthread) 
     265else () 
     266  target_link_libraries(pdffonts goo fofi ${LCMS_LIBRARY}) 
     267endif () 
     268install(TARGETS pdffonts RUNTIME DESTINATION bin) 
     269install(FILES ${PROJECT_SOURCE_DIR}/doc/pdffonts.1 DESTINATION man/man1) 
     270 
     271#--- pdfdetach 
     272 
     273add_executable(pdfdetach 
     274  $<TARGET_OBJECTS:xpdf_objs> 
     275  pdfdetach.cc 
     276) 
     277if(GSDLFLAG_STATIC_BUILD) 
     278  target_link_libraries(pdfdetach goo fofi -static ${LCMS_LIBRARY} -lpthread) 
     279else () 
     280  target_link_libraries(pdfdetach goo fofi ${LCMS_LIBRARY}) 
     281endif () 
     282install(TARGETS pdfdetach RUNTIME DESTINATION bin) 
     283install(FILES ${PROJECT_SOURCE_DIR}/doc/pdfdetach.1 DESTINATION man/man1) 
     284 
     285#--- pdftoppm 
     286 
     287if (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 
    181298                        ${FREETYPE_LIBRARY} ${FREETYPE_OTHER_LIBS} 
    182299                        ${DTYPE_LIBRARY} 
    183                         ${LCMS_LIBRARY} ${PNG_LIBRARIES} 
    184             Threads::Threads) 
    185   install(TARGETS pdftohtml RUNTIME DESTINATION bin) 
    186   install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftohtml.1 DESTINATION man/man1) 
    187 endif () 
    188  
    189 #--- pdfinfo 
    190  
    191 add_executable(pdfinfo 
    192   $<TARGET_OBJECTS:xpdf_objs> 
    193   pdfinfo.cc 
    194 ) 
    195 target_link_libraries(pdfinfo goo fofi ${LCMS_LIBRARY} Threads::Threads) 
    196 install(TARGETS pdfinfo RUNTIME DESTINATION bin) 
    197 install(FILES ${PROJECT_SOURCE_DIR}/doc/pdfinfo.1 DESTINATION man/man1) 
    198  
    199 #--- pdffonts 
    200  
    201 add_executable(pdffonts 
    202   $<TARGET_OBJECTS:xpdf_objs> 
    203   pdffonts.cc 
    204 ) 
    205 target_link_libraries(pdffonts goo fofi ${LCMS_LIBRARY} Threads::Threads) 
    206 install(TARGETS pdffonts RUNTIME DESTINATION bin) 
    207 install(FILES ${PROJECT_SOURCE_DIR}/doc/pdffonts.1 DESTINATION man/man1) 
    208  
    209 #--- pdfdetach 
    210  
    211 add_executable(pdfdetach 
    212   $<TARGET_OBJECTS:xpdf_objs> 
    213   pdfdetach.cc 
    214 ) 
    215 target_link_libraries(pdfdetach goo fofi ${LCMS_LIBRARY} Threads::Threads) 
    216 install(TARGETS pdfdetach RUNTIME DESTINATION bin) 
    217 install(FILES ${PROJECT_SOURCE_DIR}/doc/pdfdetach.1 DESTINATION man/man1) 
    218  
    219 #--- pdftoppm 
    220  
    221 if (HAVE_SPLASH) 
    222   add_executable(pdftoppm 
    223     $<TARGET_OBJECTS:xpdf_objs> 
    224     SplashOutputDev.cc 
    225     pdftoppm.cc 
    226   ) 
    227   target_link_libraries(pdftoppm goo fofi splash 
    228                         ${FREETYPE_LIBRARY} ${FREETYPE_OTHER_LIBS} 
    229             ${ZLIB_LIBRARIES} 
    230                         ${DTYPE_LIBRARY} 
    231300                        ${LCMS_LIBRARY} 
    232             Threads::Threads) 
     301            ${ZLIB_LIBRARIES}) 
     302  endif () 
    233303  install(TARGETS pdftoppm RUNTIME DESTINATION bin) 
    234304  install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftoppm.1 DESTINATION man/man1) 
     
    243313    pdftopng.cc 
    244314  ) 
    245   target_link_libraries(pdftopng goo fofi splash 
     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 
    246320                        ${FREETYPE_LIBRARY} ${FREETYPE_OTHER_LIBS} 
    247321                        ${DTYPE_LIBRARY} 
    248                         ${LCMS_LIBRARY} ${PNG_LIBRARIES} 
    249             Threads::Threads) 
     322                        ${LCMS_LIBRARY} ${PNG_LIBRARIES}) 
     323  endif () 
    250324  install(TARGETS pdftopng RUNTIME DESTINATION bin) 
    251325  install(FILES ${PROJECT_SOURCE_DIR}/doc/pdftopng.1 DESTINATION man/man1) 
     
    259333  pdfimages.cc 
    260334) 
    261 target_link_libraries(pdfimages goo fofi ${LCMS_LIBRARY} Threads::Threads) 
     335if(GSDLFLAG_STATIC_BUILD) 
     336  target_link_libraries(pdfimages goo fofi -static ${LCMS_LIBRARY} -lpthread) 
     337else () 
     338  target_link_libraries(pdfimages goo fofi ${LCMS_LIBRARY}) 
     339endif () 
    262340install(TARGETS pdfimages RUNTIME DESTINATION bin) 
    263341install(FILES ${PROJECT_SOURCE_DIR}/doc/pdfimages.1 DESTINATION man/man1)