Skip to content

Commit

Permalink
[build] Unified CMake thirdparty/build dir
Browse files Browse the repository at this point in the history
Just a passing thought, putting it up in a PR on GH for public archival/inspiration purposes or possibly to extend upon. This is a proof of concept of building in thirdparty/build/$(MACHINE) instead of thirdparty/build/$DEPENDENCY/$(MACHINE).

That way instead of using the Makefile.third with a lot of complex variable passing to CMake etc. you'd keep the logic almost entirely in CMake (not implemented in this proof of concept), so you should be able to write things like `add_dependencies(mupdf zlib)`.

Also the dist-clean command could be simplified to removing `THIRDPARTY_BUILD_DIR`.

Or to put it another way, if you're using CMake you might as well actually use it, so that errors like koreader#865 can't occur.
  • Loading branch information
Frenzie committed Mar 17, 2019
1 parent 1783337 commit 7275a71
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ build

kpvcrlib/build
thirdparty/*/build
thirdparty/build
kodebug-*
3 changes: 2 additions & 1 deletion Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,11 @@ LIB_EXT=$(if $(WIN32),.dll,$(if $(DARWIN),.dylib,.so))
# you can probably leave these settings alone:

THIRDPARTY_DIR=thirdparty
THIRDPARTY_BUILD_DIR=$(THIRDPARTY_DIR)/build/$(MACHINE)

LUAFILESYSTEM_DIR=luafilesystem

ZLIB_BUILD_DIR=$(THIRDPARTY_DIR)/zlib/build/$(MACHINE)
ZLIB_BUILD_DIR=$(THIRDPARTY_BUILD_DIR)/zlib-build
ZLIB_DIR=$(CURDIR)/$(ZLIB_BUILD_DIR)/zlib-prefix/src/zlib
ZLIB_STATIC=$(ZLIB_DIR)/libz.a

Expand Down
12 changes: 6 additions & 6 deletions Makefile.third
Original file line number Diff line number Diff line change
Expand Up @@ -300,27 +300,27 @@ $(GLIB_STATIC): $(LIBICONV) $(LIBGETTEXT) $(LIBFFI_DIR)/include $(THIRDPARTY_DIR
$(CMAKE_MAKE_PROGRAM) $(CMAKE_MAKE_PROGRAM_FLAGS)

$(ZLIB) $(ZLIB_STATIC): $(THIRDPARTY_DIR)/zlib/CMakeLists.txt
install -d $(ZLIB_BUILD_DIR)
install -d $(THIRDPARTY_BUILD_DIR)
-rm -f $(ZLIB_DIR)/../zlib-stamp/zlib-install $(ZLIB) $(ZLIB_STATIC)
ifdef ANDROID
cd $(ZLIB_BUILD_DIR) && \
cd $(THIRDPARTY_BUILD_DIR) && \
$(CMAKE) $(CMAKE_FLAGS) -DCC="$(CC)" -DCHOST="$(CHOST)" \
-DCFLAGS="$(CFLAGS)" \
-DLDFLAGS="$(LDFLAGS) -shared $(ZLIB_LDFLAGS)" \
$(CURDIR)/thirdparty/zlib && \
$(CURDIR)/$(THIRDPARTY_DIR) && \
$(CMAKE_MAKE_PROGRAM) $(CMAKE_MAKE_PROGRAM_FLAGS)
else
cd $(ZLIB_BUILD_DIR) && \
cd $(THIRDPARTY_BUILD_DIR) && \
$(CMAKE) $(CMAKE_FLAGS) -DCC="$(CC)" \
-DCFLAGS="$(CFLAGS)" \
-DLDFLAGS="$(LDFLAGS)" \
$(CURDIR)/thirdparty/zlib && \
$(CURDIR)/$(THIRDPARTY_DIR) && \
$(CMAKE_MAKE_PROGRAM) $(CMAKE_MAKE_PROGRAM_FLAGS)
endif
ifdef WIN32
cp -fL $(ZLIB_DIR)/$(notdir $(ZLIB)) $(ZLIB)
else
cp -fL $(ZLIB_DIR)/lib/$(notdir $(ZLIB)) $(ZLIB)
cp -fL $(ZLIB_DIR)/$(notdir $(ZLIB)) $(ZLIB)
endif

# ===========================================================================
Expand Down
20 changes: 20 additions & 0 deletions thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
PROJECT(koreader-base-thirdparty)
cmake_minimum_required(VERSION 3.5.1)

SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
include("koreader_thirdparty_common")

enable_language(C)

assert_var_defined(CC)
assert_var_defined(CFLAGS)
assert_var_defined(LDFLAGS)

message(STATUS "Thirdparty: zlib…")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/zlib/CMakeLists.txt
${CMAKE_BINARY_DIR}/zlib-src/CMakeLists.txt
@ONLY)
add_subdirectory("${CMAKE_BINARY_DIR}/zlib-src"
"${CMAKE_BINARY_DIR}/zlib-build")
message(STATUS "Thirdparty: zlib… DONE")
8 changes: 4 additions & 4 deletions thirdparty/zlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ if($ENV{WIN32})
# configure
set(optional_cfg_cmd "")
# build
set(BUILD_VARS DESTDIR=${SOURCE_DIR} INCLUDE_PATH=include LIBRARY_PATH=lib BIN_PATH=bin)
set(BUILD_VARS DESTDIR=${CMAKE_CURRENT_BINARY_DIR} INCLUDE_PATH=include LIBRARY_PATH=lib BIN_PATH=bin)
set(BUILD_ARGS CC="${CC}" CFLAGS="${CFLAGS}" RC="${CHOST}-windres" SHARED_MODE=1)
# TODO: also use -j for windows?
set(BUILD_CMD ${BUILD_VARS} ${KO_MAKE_RECURSIVE} -f win32/Makefile.gcc ${BUILD_ARGS})
# install
set(INSTALL_CMD ${BUILD_VARS} ${KO_MAKE_RECURSIVE} -f win32/Makefile.gcc ${BUILD_ARGS} install)
#set(INSTALL_CMD ${BUILD_VARS} ${KO_MAKE_RECURSIVE} -f win32/Makefile.gcc ${BUILD_ARGS} install)
else()
# configure
set(optional_cfg_cmd CONFIGURE_COMMAND sh -c "CC=\"${CC}\" CHOST=\"${CHOST}\" CFLAGS=\"${CFLAGS}\" LDFLAGS=\"${LDFLAGS}\" ./configure --prefix=${SOURCE_DIR}")
set(optional_cfg_cmd CONFIGURE_COMMAND sh -c "CC=\"${CC}\" CHOST=\"${CHOST}\" CFLAGS=\"${CFLAGS}\" LDFLAGS=\"${LDFLAGS}\" ./configure --prefix=${CMAKE_CURRENT_BINARY_DIR}")
# build
set(BUILD_CMD ${KO_MAKE_RECURSIVE} -j${PARALLEL_JOBS} --silent shared static)
# install
set(INSTALL_CMD ${KO_MAKE_RECURSIVE} install)
#set(INSTALL_CMD ${KO_MAKE_RECURSIVE} install)
endif()

include(ExternalProject)
Expand Down

0 comments on commit 7275a71

Please sign in to comment.