From 00b42207b25735a3665cf1909311aa54d9613f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Sonderfeld?= Date: Wed, 13 Jun 2012 00:32:01 +0200 Subject: [PATCH] Added support for static linking. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pass -DBUILD_STATIC=ON to configure. But be aware that this can easily fail due to missing dependencies! Signed-off-by: RĂ¼diger Sonderfeld --- CMakeLists.txt | 4 ++++ CMakeModules/FindTesseract.cmake | 26 +++++++++++++++++++++++++- README.org | 9 +++++++++ src/CMakeLists.txt | 5 +++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a8a780..88f6f52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/CMakeModules/FindTesseract.cmake b/CMakeModules/FindTesseract.cmake index 6fe841d..4b15d74 100644 --- a/CMakeModules/FindTesseract.cmake +++ b/CMakeModules/FindTesseract.cmake @@ -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() @@ -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) diff --git a/README.org b/README.org index 504a9c0..4d0de4d 100644 --- a/README.org +++ b/README.org @@ -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. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 98ad6b1..9eac1ad 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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})