Skip to content

Commit

Permalink
Added support for static linking.
Browse files Browse the repository at this point in the history
Pass -DBUILD_STATIC=ON to configure. But be aware that this can easily
fail due to missing dependencies!

Signed-off-by: Rüdiger Sonderfeld <[email protected]>
  • Loading branch information
ruediger committed Jun 12, 2012
1 parent 813a440 commit 00b4220
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ if(${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
message(FATAL_ERROR "In-source builds are not permitted. Make a separate folder for building:\nmkdir build; cd build; cmake ..\nBefore that, remove the files that cmake just created:\nrm -rf CMakeCache.txt CMakeFiles")
endif()

if(BUILD_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif()

set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)

Expand Down
26 changes: 25 additions & 1 deletion CMakeModules/FindTesseract.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ find_library(Tiff_LIBRARY NAMES tiff
/usr/lib
/usr/local/lib)

if(BUILD_STATIC)
# -llept -lgif -lwebp -ltiff -lpng -ljpeg -lz
find_library(Lept_LIBRARY NAMES lept
HINTS
/usr/lib
/usr/local/lib)

find_library(Webp_LIBRARY NAMES webp
HINTS
/usr/lib
/usr/local/lib)

find_package(GIF)
find_package(JPEG)
find_package(PNG)
#find_package(TIFF) TODO replace manual find_library call
find_package(ZLIB)

endif()

if(TESSERACT_DATA_PATH)
add_definitions(-DTESSERACT_DATA_PATH="${TESSERACT_DATA_PATH}")
endif()
Expand All @@ -37,7 +57,11 @@ else()
endif()
list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${Tesseract_INCLUDE_DIR})

set(Tesseract_LIBRARIES ${Tesseract_LIBRARIES} ${Tiff_LIBRARY})
if(BUILD_STATIC)
set(Tesseract_LIBRARIES ${Tesseract_LIBRARIES} ${Lept_LIBRARY} ${PNG_LIBRARY} ${Tiff_LIBRARY} ${Webp_LIBRARY} ${GIF_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARY})
else()
set(Tesseract_LIBRARIES ${Tesseract_LIBRARIES} ${Tiff_LIBRARY})
endif()

include(FindPackageHandleStandardArgs)

Expand Down
9 changes: 9 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ This should install the program vobsub2srt to =/usr/local/bin=. You can uninstal
./configure -DBASH_COMPLETION_PATH="$BASH_COMPLETION_DIR"
#+END_EXAMPLE

** Static binary
I recommend using the dynamic binary. However if you really need a static binary you can add the flag =-DBUILD_STATIC=ON= to the =./configure= call. But be aware that building static binaries can be quit troublesome. You need the static library files for tesseract, libtill, avutils, and for their dependencies as well. On Ubuntu 12.04 the static libraries are only included in the dev packages. For Ubuntu 12.04 you need the following extra packages:

#+BEGIN_EXAMPLE
sudo apt-get install libleptonica-dev libpng12-dev libwebp-dev libgif-dev zlib1g-dev libjpeg-dev
#+END_EXAMPLE

If linking fails with undefined references then checking what other dependencies your version of leptonica has is a good starting point. You can do this by running =ldd /usr/lib/liblept.so= (or whatever the path to leptonica is on your system). Add those dependencies to =CMakeModules/FindTesseract.cmake=.

** .deb (Debian/Ubuntu)
You can build a *.deb package (Debian/Ubuntu) with =make package=. The package is created in the =build= directory.

Expand Down
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ set(vobsub2srt_sources
cmd_options.c++)

add_executable(vobsub2srt ${vobsub2srt_sources})
if(BUILD_STATIC)
set_target_properties(vobsub2srt PROPERTIES
LINK_SEARCH_END_STATIC ON
LINK_FLAGS -static)
endif()
target_link_libraries(vobsub2srt mplayer ${Libavutil_LIBRARIES} ${Tesseract_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})

install(TARGETS vobsub2srt RUNTIME DESTINATION ${INSTALL_EXECUTABLES_PATH})

0 comments on commit 00b4220

Please sign in to comment.