Skip to content

Commit

Permalink
crengine: compile libcrengine statically
Browse files Browse the repository at this point in the history
There's only one user: `libkoreader-cre.so`.
  • Loading branch information
benoit-pierre committed Oct 26, 2023
1 parent d3535e0 commit 8b8db24
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 87 deletions.
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,24 @@ endif

$(OUTPUT_DIR)/libs/libkoreader-cre.so: cre.cpp \
$(if $(USE_LUAJIT_LIB),$(LUAJIT_LIB),) \
$(CRENGINE_LIB)
$(CRENGINE_LIB) $(CRENGINE_THIRDPARTY_LIBS) \
$(FREETYPE_LIB) $(FRIBIDI_LIB) $(HARFBUZZ_LIB) \
$(JPEG_LIB) $(LIBWEBP_LIB) $(LIBWEBPDEMUX_LIB) \
$(LIBUNIBREAK_LIB) $(LUNASVG_LIB) $(PNG_LIB) \
$(UTF8PROC_LIB) $(ZLIB) $(ZSTD_LIB)
$(CXX) $(CRENGINE_CFLAGS) $(DYNLIB_CXXFLAGS) \
$(SYMVIS_FLAGS) $(LDFLAGS) -o $@ cre.cpp $(LUAJIT_LIB_LINK_FLAG) \
-lcrengine
$(CRENGINE_LIB) $(CRENGINE_THIRDPARTY_LIBS) $(FREETYPE_LIB_LINK_FLAG) \
$(FRIBIDI_LIB) $(HARFBUZZ_LIB_LINK_FLAG) $(JPEG_LIB_LINK_FLAG) \
$(LIBWEBP_LIB) $(LIBWEBPDEMUX_LIB) $(LIBUNIBREAK_LIB_LINK_FLAG) \
$(LUNASVG_LIB) $(PNG_LIB) $(UTF8PROC_LIB) $(ZLIB) $(ZSTD_LIB) \
$(LUAJIT_LIB_LINK_FLAG) \
$(if $(ANDROID),$(SHARED_STL_LINK_FLAG),)
ifdef DARWIN
install_name_tool -change \
`otool -L "$@" | grep "libluajit" | awk '{print $$1}'` \
libs/$(notdir $(LUAJIT_LIB)) \
$@
install_name_tool -change \
`otool -L "$@" | grep "$(notdir $(CRENGINE_LIB)) " | awk '{print $$1}'` \
libs/$(notdir $(CRENGINE_LIB)) \
$@
endif

$(OUTPUT_DIR)/libs/libkoreader-xtext.so: xtext.cpp \
Expand Down
3 changes: 2 additions & 1 deletion Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,8 @@ CRENGINE_SRC_FILES=$(wildcard $(CRENGINE_SRC_DIR)/crengine/src/*.cpp)
CRENGINE_SRC_FILES+=$(wildcard $(CRENGINE_SRC_DIR)/crengine/include/*.h)
CRENGINE_SRC_FILES+=$(wildcard $(CRENGINE_SRC_DIR)/crengine/src/*.h)
CRENGINE_SRC_FILES+=$(wildcard $(CRENGINE_SRC_DIR)/crengine/src/*_h.*)
CRENGINE_LIB=$(OUTPUT_DIR)/libs/libcrengine$(LIB_EXT)
CRENGINE_LIB = $(CRENGINE_BUILD_DIR)/libcrengine.a
CRENGINE_THIRDPARTY_LIBS = $(addprefix $(CRENGINE_BUILD_DIR)/crengine/thirdparty/, antiword/libantiword.a chmlib/libchmlib.a)
CRENGINE_CFLAGS = \
--include '$(CRENGINE_BUILD_DIR)/crsetup.h' \
'-I$(CRENGINE_SRC_DIR)/crengine/include' \
Expand Down
49 changes: 15 additions & 34 deletions Makefile.third
Original file line number Diff line number Diff line change
Expand Up @@ -251,24 +251,23 @@ ifdef DARWIN
endif

# crengine, fetched via GIT as a submodule
$(CRENGINE_LIB): $(ZLIB) $(ZSTD_LIB) $(PNG_LIB) $(FREETYPE_LIB) $(HARFBUZZ_LIB) $(FRIBIDI_LIB) \
$(LIBUNIBREAK_LIB) $(UTF8PROC_LIB) $(JPEG_LIB) $(LIBWEBP_LIB) $(LUNASVG_LIB) \
$(CRENGINE_SRC_FILES) $(THIRDPARTY_DIR)/kpvcrlib/*.*
$(CRENGINE_LIB): $(CRENGINE_SRC_FILES) \
$(FREETYPE_DIR)/include \
$(FRIBIDI_DIR)/include \
$(HARFBUZZ_DIR)/include \
$(JPEG_DIR)/include \
$(LIBUNIBREAK_DIR)/include \
$(LIBWEBP_DIR)/include \
$(LUNASVG_DIR)/include \
$(MUPDF_DIR)/scripts \
$(PNG_DIR)/include \
$(SRELL_INCLUDE_DIR) \
$(UTF8PROC_DIR) \
$(ZLIB_DIR)/include \
$(ZSTD_DESTDIR)/include \
$(THIRDPARTY_DIR)/kpvcrlib/*.*
install -d $(CRENGINE_BUILD_DIR)
cd $(CRENGINE_BUILD_DIR) && \
JPEG_LIB='$(CURDIR)/$(JPEG_LIB)' \
PNG_LIB='$(CURDIR)/$(PNG_LIB)' \
FREETYPE_LIB='$(CURDIR)/$(FREETYPE_LIB)' \
HARFBUZZ_LIB='$(CURDIR)/$(HARFBUZZ_LIB)' \
FRIBIDI_LIB='$(CURDIR)/$(FRIBIDI_LIB)' \
LIBWEBP_LIB='$(CURDIR)/$(LIBWEBP_LIB)' \
LIBWEBPDEMUX_LIB='$(CURDIR)/$(LIBWEBPDEMUX_LIB)' \
LUNASVG_LIB='$(CURDIR)/$(LUNASVG_LIB)' \
LIBUNIBREAK_LIB='$(CURDIR)/$(LIBUNIBREAK_LIB)' \
UTF8PROC_LIB='$(CURDIR)/$(UTF8PROC_LIB)' \
ZLIB='$(CURDIR)/$(ZLIB)' \
ZSTD_LIB='$(CURDIR)/$(ZSTD_LIB)' \
LIBS_DIR='$(CURDIR)/$(OUTPUT_DIR)/libs' \
$(CMAKE) $(CMAKE_FLAGS) \
-DJPEGLIB_INCLUDE_DIR='$(JPEG_DIR)/include' \
-DJCONFIG_INCLUDE_DIR='$(MUPDF_DIR)/scripts' \
Expand All @@ -289,24 +288,6 @@ $(CRENGINE_LIB): $(ZLIB) $(ZSTD_LIB) $(PNG_LIB) $(FREETYPE_LIB) $(HARFBUZZ_LIB)
$(if $(ANDROID),-DCMAKE_SYSTEM_VERSION=1,) \
$(CURDIR)/$(THIRDPARTY_DIR)/kpvcrlib && \
$(CMAKE_MAKE_PROGRAM) $(CMAKE_MAKE_PROGRAM_FLAGS)
cp -fL $(CRENGINE_DIR)/$(notdir $(CRENGINE_LIB)) $(CRENGINE_LIB)
ifdef DARWIN
install_name_tool -id \
libs/$(notdir $(CRENGINE_LIB)) \
$@
install_name_tool -change \
`otool -L '$@' | grep '$(notdir $(UTF8PROC_LIB)) ' | awk '{print $$1}'` \
libs/$(notdir $(UTF8PROC_LIB)) \
$@
install_name_tool -change \
`otool -L '$@' | grep '$(notdir $(JPEG_LIB)) ' | awk '{print $$1}'` \
libs/$(notdir $(JPEG_LIB)) \
$@
install_name_tool -change \
`otool -L '$@' | grep '$(notdir $(ZSTD_LIB)) ' | awk '{print $$1}'` \
libs/$(notdir $(ZSTD_LIB)) \
$@
endif

$(LUAJIT) $(LUAJIT_LIB) $(LUAJIT_JIT): $(THIRDPARTY_DIR)/luajit/*.*
install -d $(LUAJIT_BUILD_DIR)
Expand Down
47 changes: 1 addition & 46 deletions thirdparty/kpvcrlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,48 +72,6 @@ configure_file(crsetup.h.cmake crsetup.h)
# force approach…
add_definitions(--include "${CMAKE_CURRENT_BINARY_DIR}/crsetup.h")

if(DEFINED ENV{WIN32})
find_library(ZLIB NAMES "zlib1" PATHS $ENV{LIBS_DIR})
find_library(ZSTD NAMES "zstd" PATHS $ENV{LIBS_DIR})
find_library(PNG_LIB NAMES "png16-16" PATHS $ENV{LIBS_DIR})
find_library(FREETYPE_LIB NAMES "freetype-6" PATHS $ENV{LIBS_DIR})
find_library(HARFBUZZ_LIB NAMES "harfbuzz-0" PATHS $ENV{LIBS_DIR})
find_library(FRIBIDI_LIB NAMES "fribidi-0" PATHS $ENV{LIBS_DIR})
find_library(LIBUNIBREAK_LIB NAMES "libunibreak-5" PATHS $ENV{LIBS_DIR})
find_library(UTF8PROC_LIB NAMES "utf8proc-2" PATHS $ENV{LIBS_DIR})
find_library(JPEG_LIB NAMES "jpeg-8" PATHS $ENV{LIBS_DIR})
find_library(LUNASVG_LIB NAMES "lunasvg" PATHS $ENV{LIBS_DIR})
find_library(LIBWEBP_LIB NAMES "webp-7" PATHS $ENV{LIBS_DIR})
find_library(LIBWEBPDEMUX_LIB NAMES "webpdemux-2" PATHS $ENV{LIBS_DIR})
set(THIRDPARTY_LIBS ${ZLIB} ${ZSTD} ${FREETYPE_LIB} ${HARFBUZZ_LIB} ${FRIBIDI_LIB} ${LIBUNIBREAK_LIB} ${UTF8PROC_LIB} ${JPEG_LIB} ${PNG_LIB} ${LIBWEBP_LIB} ${LIBWEBPDEMUX_LIB} ${LUNASVG_LIB})
else()
add_library(PNG_LIB SHARED IMPORTED)
set_target_properties(PNG_LIB PROPERTIES IMPORTED_LOCATION $ENV{PNG_LIB})
add_library(FREETYPE_LIB SHARED IMPORTED)
set_target_properties(FREETYPE_LIB PROPERTIES IMPORTED_LOCATION $ENV{FREETYPE_LIB})
add_library(HARFBUZZ_LIB SHARED IMPORTED)
set_target_properties(HARFBUZZ_LIB PROPERTIES IMPORTED_LOCATION $ENV{HARFBUZZ_LIB})
add_library(FRIBIDI_LIB SHARED IMPORTED)
set_target_properties(FRIBIDI_LIB PROPERTIES IMPORTED_LOCATION $ENV{FRIBIDI_LIB})
add_library(LIBUNIBREAK_LIB SHARED IMPORTED)
set_target_properties(LIBUNIBREAK_LIB PROPERTIES IMPORTED_LOCATION $ENV{LIBUNIBREAK_LIB})
add_library(UTF8PROC_LIB SHARED IMPORTED)
set_target_properties(UTF8PROC_LIB PROPERTIES IMPORTED_LOCATION $ENV{UTF8PROC_LIB})
add_library(JPEG_LIB SHARED IMPORTED)
set_target_properties(JPEG_LIB PROPERTIES IMPORTED_LOCATION $ENV{JPEG_LIB})
add_library(LIBWEBP_LIB SHARED IMPORTED)
set_target_properties(LIBWEBP_LIB PROPERTIES IMPORTED_LOCATION $ENV{LIBWEBP_LIB})
add_library(LIBWEBPDEMUX_LIB SHARED IMPORTED)
set_target_properties(LIBWEBPDEMUX_LIB PROPERTIES IMPORTED_LOCATION $ENV{LIBWEBPDEMUX_LIB})
add_library(LUNASVG_LIB SHARED IMPORTED)
set_target_properties(LUNASVG_LIB PROPERTIES IMPORTED_LOCATION $ENV{LUNASVG_LIB})
add_library(ZLIB SHARED IMPORTED)
set_target_properties(ZLIB PROPERTIES IMPORTED_LOCATION $ENV{ZLIB})
add_library(ZSTD SHARED IMPORTED)
set_target_properties(ZSTD PROPERTIES IMPORTED_LOCATION $ENV{ZSTD_LIB})
set(THIRDPARTY_LIBS ZLIB ZSTD FREETYPE_LIB HARFBUZZ_LIB FRIBIDI_LIB LIBUNIBREAK_LIB UTF8PROC_LIB JPEG_LIB PNG_LIB LIBWEBP_LIB LIBWEBPDEMUX_LIB LUNASVG_LIB)
endif()

message("Will build LIBCHM library")
add_subdirectory(${CR_3RDPARTY_DIR}/chmlib)

Expand Down Expand Up @@ -164,9 +122,6 @@ set (CRENGINE_SOURCES
${CRE_DIR}/src/cri18n.cpp
${CRE_DIR}/src/crconcurrent.cpp
)
add_library(crengine SHARED ${CRENGINE_SOURCES})
add_library(crengine STATIC ${CRENGINE_SOURCES})
# Make sure we get full `constexpr` support.
target_compile_features(crengine PRIVATE cxx_std_17)

target_link_libraries(crengine PRIVATE chmlib antiword)
target_link_libraries(crengine PRIVATE ${THIRDPARTY_LIBS})

0 comments on commit 8b8db24

Please sign in to comment.