Skip to content

Commit

Permalink
crengine: cleanup compilation flags handling
Browse files Browse the repository at this point in the history
Generate a custom `crsetup.h`, so users of the library will be sure to use the correct (same) flags.
  • Loading branch information
benoit-pierre committed Oct 26, 2023
1 parent 2f0985e commit d3535e0
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 46 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@ endif
$(OUTPUT_DIR)/libs/libkoreader-cre.so: cre.cpp \
$(if $(USE_LUAJIT_LIB),$(LUAJIT_LIB),) \
$(CRENGINE_LIB)
$(CXX) -I$(CRENGINE_SRC_DIR)/crengine/include/ $(DYNLIB_CXXFLAGS) \
-DLDOM_USE_OWN_MEM_MAN=$(if $(WIN32),0,1) -DUSE_SRELL_REGEX=1 \
$(if $(WIN32),-DQT_GL=1) $(SYMVIS_FLAGS) $(LDFLAGS) -o $@ cre.cpp $(LUAJIT_LIB_LINK_FLAG) \
$(CXX) $(CRENGINE_CFLAGS) $(DYNLIB_CXXFLAGS) \
$(SYMVIS_FLAGS) $(LDFLAGS) -o $@ cre.cpp $(LUAJIT_LIB_LINK_FLAG) \
-lcrengine
ifdef DARWIN
install_name_tool -change \
Expand Down
6 changes: 6 additions & 0 deletions Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,12 @@ 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_CFLAGS = \
--include '$(CRENGINE_BUILD_DIR)/crsetup.h' \
'-I$(CRENGINE_SRC_DIR)/crengine/include' \
'-I$(FREETYPE_DIR)/include/freetype2' \
'-I$(HARFBUZZ_DIR)/include/harfbuzz' \
'-I$(LIBUNIBREAK_DIR)/include' \

LUAJIT_BUILD_DIR=$(THIRDPARTY_DIR)/luajit/build/$(MACHINE)
LUAJIT_DIR=$(CURDIR)/$(LUAJIT_BUILD_DIR)/luajit-prefix/src/luajit
Expand Down
51 changes: 8 additions & 43 deletions thirdparty/kpvcrlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,55 +51,27 @@ include_directories(
${CREGINE_INCLUDE_DIR}
)

if(DEFINED ENV{WIN32})
add_definitions(-DWIN32=1 -D_WIN32=1 -DQT_GL=1 -DMINGW -DHAVE_BOOLEAN)
else()
add_definitions(-DLINUX=1 -D_LINUX=1)
endif()

include(CheckTypeSize)

if(DEFINED ENV{LEGACY})
add_definitions(-DDISABLE_CLOEXEC)
set(DISABLE_CLOEXEC 1)
else()
# Test and Enable LFS Support in glibc, based on zlib
set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
check_type_size(off64_t OFF64_T)
if(HAVE_OFF64_T)
add_definitions(-D_LARGEFILE64_SOURCE=1)
add_definitions(-DHAVE_STAT64=1)
endif()
set(CMAKE_REQUIRED_DEFINITIONS)
endif()

add_definitions(
-DUSE_FONTCONFIG=0
-DUSE_FREETYPE=1
-DUSE_HARFBUZZ=1
-DUSE_FRIBIDI=1
-DUSE_LIBUNIBREAK=1
-DUSE_UTF8PROC=1
-DUSE_NANOSVG=0 # better SVG support via LunaSVG
-DUSE_LUNASVG=1
-DUSE_LIBWEBP=1
-DUSE_ZSTD=1
-DUSE_SRELL_REGEX=1
-DALLOW_KERNING=1
-DCR3_PATCH=1
-DMATHML_SUPPORT=1
)

if(${CMAKE_BUILD_TYPE} STREQUAL Debug)
add_definitions(
-D_DEBUG=1
-DDEBUG=1
)
else()
add_definitions(
-DNDEBUG=1
)
set(_DEBUG 1)
endif()

configure_file(crsetup.h.cmake crsetup.h)
# Some source files use `#include "crsetup.h"`, others
# `#include "../include/crsetup.h"`, so use the brute
# 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})
Expand Down Expand Up @@ -143,19 +115,12 @@ else()
endif()

message("Will build LIBCHM library")
add_definitions(-DCHM_SUPPORT_ENABLED=1)
add_subdirectory(${CR_3RDPARTY_DIR}/chmlib)

message("Will build ANTIWORD library")
add_definitions(-DENABLE_ANTIWORD=1)
add_definitions(-DCR3_ANTIWORD_PATCH=1)
add_subdirectory(${CR_3RDPARTY_DIR}/antiword)

message("Will build crengine library")
add_definitions(-DHAVE_PROTOTYPES)
add_definitions(-DHAVE_UNSIGNED_CHAR)
add_definitions(-DCR_EMULATE_GETTEXT)
add_definitions(-Dmain=xxxmain)
set (CRENGINE_SOURCES
${CRE_DIR}/qimagescale/qimagescale.cpp
${CRE_DIR}/src/cp_stats.cpp
Expand Down
81 changes: 81 additions & 0 deletions thirdparty/kpvcrlib/crsetup.h.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#ifndef CRSETUP_H_INCLUDED
#define CRSETUP_H_INCLUDED

#if defined(__linux__)
# define LINUX 1
# define _LINUX 1
#endif

#cmakedefine _DEBUG 1
#cmakedefine DISABLE_CLOEXEC 1
#cmakedefine HAVE_OFF64_T 1
#ifdef HAVE_OFF64_T
# define _LARGEFILE64_SOURCE 1
#endif

/// Compression.
#define USE_ZLIB 1
#define USE_ZSTD 1
#define ZIP_STREAM_BUFFER_SIZE 0x40000 // 256.0 KiB

/// Documents cache.
#define DOCUMENT_CACHING_MIN_SIZE 0x10000 // 64.0 KiB
#define DOCUMENT_CACHING_SIZE_THRESHOLD 0x100000 // 1.0 MiB

/// Document formats.
#define CHM_SUPPORT_ENABLED 1
#define CR3_ANTIWORD_PATCH 1
#define ENABLE_ANTIWORD 1

/// Files.
#define LVLONG_FILE_SUPPORT 0
#define USE_ANSI_FILES 1
#define FILE_STREAM_BUFFER_SIZE 0x20000

/// I18N
#define CR_EMULATE_GETTEXT 1

/// Images.
#define ARBITRARY_IMAGE_SCALE_ENABLED 1
#define MAX_IMAGE_SCALE_MUL 2
#define USE_GIF 1
#define USE_LIBJPEG 1
#define USE_LIBPNG 1
#define USE_LIBWEBP 1
#define USE_LUNASVG 1
#define USE_NANOSVG 0 // better SVG support via LunaSVG

/// Miscellaneous.
#define MATHML_SUPPORT 1
#define USE_SRELL_REGEX 1

/// Output buffer.
#define COLOR_BACKBUFFER 1
#define CR_INTERNAL_PAGE_ORIENTATION 1
#define GRAY_BACKBUFFER_BITS 2
#define GRAY_INVERSE 0

/// Skin support.
// FIXME: to be removed once we stop compiling `crskin.cpp`.
#define MAX_SKIN_IMAGE_CACHE_ITEM_UNPACKED_SIZE (80*80*4)
#define MAX_SKIN_IMAGE_CACHE_ITEM_RAM_COPY_PACKED_SIZE 10000

/// System.
#define CR_USE_THREADS 0
#define LDOM_USE_OWN_MEM_MAN 1

/// Text.
#define ALLOW_KERNING 1
#define GLYPH_CACHE_SIZE 0x40000 // 256.0 KiB
#define USE_BITMAP_FONTS 0
#define USE_FONTCONFIG 0
#define USE_FREETYPE 1
#define USE_FRIBIDI 1
#define USE_GLYPHCACHE_HASHTABLE 0
#define USE_HARFBUZZ 1
#define USE_LIBUNIBREAK 1
#define USE_LIMITED_FONT_SIZES_SET 0
#define USE_UTF8PROC 1
#define USE_WIN32_FONTS 0

#endif//CRSETUP_H_INCLUDED

0 comments on commit d3535e0

Please sign in to comment.