Skip to content

Commit

Permalink
🧰 Replace build script by cmake for external projects
Browse files Browse the repository at this point in the history
  • Loading branch information
dbouron committed Aug 12, 2020
1 parent 505bcdb commit e37c1a6
Show file tree
Hide file tree
Showing 16 changed files with 303 additions and 273 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ jobs:
- name: Set version
id: version
run: |
source lib/variables.sh
VERSION="$VIPS_VERSION-$(git rev-parse --short HEAD)"
source lib/VERSIONS
VERSION="${VIPS_VERSION}-$(git rev-parse --short HEAD)"
mvn -B versions:set -DnewVersion=$VERSION
echo "::set-output name=version::$VERSION"
Expand Down
39 changes: 27 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
project(JVIPS C)
project(JVIPS C Java)
cmake_minimum_required(VERSION 3.6.0)

set(JVIPS_VERSION 8.9.0)

set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${JVIPS_VERSION}")
set(CPACK_SOURCE_GENERATOR "TGZ")

find_package(PkgConfig REQUIRED)

find_package(Java 1.8 REQUIRED)
include(UseJava)

set(JVIPS_VERSION 1.0.1)

set(CMAKE_C_FLAGS "-std=c99")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g3")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3 -g")
Expand All @@ -30,26 +33,38 @@ if (DEFINED JNI_INCLUDE_DIRS)
endif()
include_directories(${JNI_INCLUDE_DIRS})

# BUILD_TARGET should be define in Toolchain file
set(ENV{PKG_CONFIG_PATH} "${CMAKE_SOURCE_DIR}/build/${BUILD_TARGET}/inst/lib/pkgconfig/")
set(EXT_INSTALL_DIR "${CMAKE_SOURCE_DIR}/build/${BUILD_TARGET}/inst")

include_directories(SYSTEM "${EXT_INSTALL_DIR}/include/")
link_directories("${EXT_INSTALL_DIR}/lib/")

set(ENV{PKG_CONFIG_PATH} "${EXT_INSTALL_DIR}/lib/pkgconfig/")

pkg_check_modules(GLIB2 REQUIRED glib-2.0)
if (GLIB2_FOUND)
message (STATUS "GLIB2_INCLUDE_DIRS=${GLIB2_INCLUDE_DIRS}")
message (STATUS "GLIB2_LIBRARIES=${GLIB2_LIBRARIES}")
message (STATUS "GLIB2_LIBRARY_DIRS=${GLIB2_LIBRARY_DIRS}")
message (STATUS "GLIB2_LDFLAGS=${GLIB2_LDFLAGS}")
endif()
link_directories(${GLIB2_LIBRARY_DIRS})
include_directories(${GLIB2_INCLUDE_DIRS})

pkg_check_modules(VIPS REQUIRED vips)
if (VIPS_FOUND)
message (STATUS "VIPS_INCLUDE_DIRS=${VIPS_INCLUDE_DIRS}")
message (STATUS "VIPS_LIBRARIES=${VIPS_LIBRARIES}")
message (STATUS "VIPS_LIBRARY_DIRS=${VIPS_LIBRARY_DIRS}")
# Under macOS libvips will not build as is, but you can rely on Homebrew.
# Here's a formula for vips 8.8.3:
# $ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/39ba7794c1678b0d61b179239f93e9ac553c045b/Formula/vips.rb
if(NOT ${BUILD_TARGET} STREQUAL "macOS")
add_subdirectory(lib)
else()
pkg_check_modules(VIPS REQUIRED vips)
if (VIPS_FOUND)
message (STATUS "VIPS_INCLUDE_DIRS=${VIPS_INCLUDE_DIRS}")
message (STATUS "VIPS_LIBRARIES=${VIPS_LIBRARIES}")
message (STATUS "VIPS_LIBRARY_DIRS=${VIPS_LIBRARY_DIRS}")
endif()
link_directories(${VIPS_LIBRARY_DIRS})
include_directories(${VIPS_INCLUDE_DIRS})
endif()
link_directories(${VIPS_LIBRARY_DIRS})
include_directories(${VIPS_INCLUDE_DIRS})

add_subdirectory(src/main/java/com/criteo/vips/)
add_subdirectory(src/main/c)
Expand Down
2 changes: 1 addition & 1 deletion Toolchain-x86_64-w64-mingw32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SET(CMAKE_LINKER x86_64-w64-mingw32-ld)
SET(CMAKE_RANLIB x86_64-w64-mingw32-ranlib)

# target environment location
SET(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32 /usr/ ${CMAKE_SOURCE_DIR}/build/${BUILD_TARGET}/inst)
SET(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32 /usr/bin/ /usr/ ${CMAKE_SOURCE_DIR}/build/${BUILD_TARGET}/inst)

# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
Expand Down
33 changes: 5 additions & 28 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,12 @@ if [ ${BUILD_LINUX} -gt 0 ]; then
export CXX=g++
export CPP=cpp
export RANLIB=ranlib

export HOST="--host=x86_64-pc-linux"
export TARGET=linux
export PREFIX="${BUILDDIR}/${TARGET}"/inst/
export TOOLCHAIN="${BASEDIR}"/Toolchain-linux.cmake
export PKG_CONFIG_PATH=/usr/lib64/pkgconfig
pushd "${BASEDIR}"/lib
./build.sh || {
echo "Linux dependencies build failed"
exit 1
}
popd

mkdir -p "${BUILDDIR}/${TARGET}"/JVips
rm -rf "${BUILDDIR}/${TARGET}"/JVips/*
pushd "${BUILDDIR}/${TARGET}"/JVips
Expand Down Expand Up @@ -118,12 +112,7 @@ if [ ${BUILD_WIN64} -gt 0 ]; then
export TOOLCHAIN="${BASEDIR}"/Toolchain-x86_64-w64-mingw32.cmake
export PKG_CONFIG_PATH=/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig/
export PKG_CONFIG="x86_64-w64-mingw32-pkg-config"
pushd "${BASEDIR}"/lib
./build.sh || {
echo "Windows 64 dependencies build failed"
exit 1
}
popd

mkdir -p "${BUILDDIR}/${TARGET}"/JVips
rm -rf "${BUILDDIR}/${TARGET}"/JVips/*
pushd "${BUILDDIR}/${TARGET}"/JVips
Expand All @@ -134,7 +123,7 @@ if [ ${BUILD_WIN64} -gt 0 ]; then
}
popd

LIBS="inst/bin/libimagequant.dll JVips/src/main/c/JVips.dll"
LIBS="inst/lib/libimagequant.dll JVips/src/main/c/JVips.dll"

if [ ${RUN_TEST} -gt 0 ]; then
LIBS+=" JVips/src/test/c/JVipsTest.dll"
Expand All @@ -155,18 +144,6 @@ if [ ${BUILD_MACOS} -gt 0 ]; then
export PREFIX="${BUILDDIR}/${TARGET}"/inst/
export TOOLCHAIN="${BASEDIR}"/Toolchain-macOS.cmake

# Under macOS libvips will not build as is, but you can rely on Homebrew.
# Here's a formula for vips 8.8.3:
# $ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/39ba7794c1678b0d61b179239f93e9ac553c045b/Formula/vips.rb

# pushd "${BASEDIR}/lib"
# ./build.sh
# if [ $? -ne 0 ]; then
# echo "macOS dependencies build failed"
# exit 1
# fi
# popd

mkdir -p "${BUILDDIR}/${TARGET}"/JVips
rm -rf "${BUILDDIR}/${TARGET}"/JVips/*
pushd "${BUILDDIR}/${TARGET}/JVips"
Expand All @@ -189,8 +166,8 @@ if [ ${BUILD_MACOS} -gt 0 ]; then

fi

source lib/variables.sh
VERSION="$VIPS_VERSION-$(git rev-parse --short HEAD)"
source lib/VERSIONS
VERSION="${VIPS_VERSION}-$(git rev-parse --short HEAD)"

mvn ${MAVEN_ARGS} -DnewVersion=${VERSION} versions:set
mvn ${MAVEN_ARGS} -DskipTests clean package
Expand Down
4 changes: 0 additions & 4 deletions clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

BASEDIR=$(pwd)

pushd "lib/"
./clean.sh
popd

rm -rf build target
rm -f JVips.jar
rm -f JVips-*.tar.gz
171 changes: 171 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
include(ExternalProject)

# Read external project versions
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/VERSIONS VERSIONS_LIST)
foreach(ITEM ${VERSIONS_LIST})
string(REPLACE "=" ";" ARGS ${ITEM})
list(GET ARGS 0 LIB)
list(GET ARGS 1 VERSION)
set(${LIB} ${VERSION})
endforeach()

set(VIPS_VERSION ${VIPS_VERSION} PARENT_SCOPE)
string(REPLACE "." "_" EXIF_VERSION_TAG ${EXIF_VERSION})

# Set the host target
if (NOT DEFINED BUILD_TARGET)
set(CONFIGURE_HOST "--host=x86_64-pc-linux")
elseif(${BUILD_TARGET} STREQUAL "w64")
set(CONFIGURE_HOST "--host=x86_64-w64-mingw32")
endif()

if (NOT DEFINED CMAKE_BUILD_TYPE)
set(CONFIGURE_CFLAGS "${CMAKE_C_FLAGS}")
set(CONFIGURE_CXXFLAGS "${CMAKE_CXX_FLAGS}")
elseif (${CMAKE_BUILD_TYPE} STREQUAL "Release")
set(CONFIGURE_CFLAGS ${CMAKE_C_FLAGS_RELEASE})
set(CONFIGURE_CXXFLAGS ${CMAKE_CXX_FLAGS_RELEASE})
elseif (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(CONFIGURE_CFLAGS ${CMAKE_C_FLAGS_DEBUG})
set(CONFIGURE_CXXFLAGS ${CMAKE_CXX_FLAGS_DEBUG})
endif()

# Workaround to set more than one compiler flags
string(REPLACE " " "\ " CONFIGURE_CFLAGS "${CONFIGURE_CFLAGS}")
string(REPLACE " " "\ " CONFIGURE_CXXFLAGS "${CONFIGURE_CXXFLAGS}")

list(APPEND CONFIGURE_VARS
PKG_CONFIG_PATH=${EXT_INSTALL_DIR}/lib/pkgconfig:$PKG_CONFIG_PATH
CFLAGS=${CONFIGURE_CFLAGS}
CXXFLAGS=${CONFIGURE_CXXFLAGS}
LDFLAGS=-L${EXT_INSTALL_DIR}/lib,-Wl,-rpath=${EXT_INSTALL_DIR}/lib
CPPFLAGS=-I${EXT_INSTALL_DIR}/include
--prefix=${EXT_INSTALL_DIR}
${CONFIGURE_HOST}
)

ExternalProject_Add(libimagequant
URL "https://github.com/ImageOptim/libimagequant/archive/${LIQ_VERSION}.tar.gz"
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libimagequant"
CONFIGURE_COMMAND ./configure CC=${CMAKE_C_COMPILER} CFLAGS=${CONFIGURE_CFLAGS} --prefix=${EXT_INSTALL_DIR} --with-sse --without-openmp
BUILD_IN_SOURCE 1
)

if(${BUILD_TARGET} STREQUAL "w64")
ExternalProject_Add_Step(libimagequant rename-dll
COMMAND mv libimagequant.so libimagequant.dll
WORKING_DIRECTORY ${EXT_INSTALL_DIR}/lib/
DEPENDEES install
)
ExternalProject_Add_StepTargets(libimagequant rename-dll)
endif()

ExternalProject_Add(libexif
URL "https://github.com/libexif/libexif/releases/download/libexif-${EXIF_VERSION_TAG}-release/libexif-${EXIF_VERSION}.tar.gz"
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libexif"
CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/libexif/src/libexif/configure
${CONFIGURE_VARS}
--enable-shared
--disable-static
--disable-docs
)

ExternalProject_Add(libjpeg-turbo
URL "https://github.com/libjpeg-turbo/libjpeg-turbo/archive/${JPG_VERSION}.tar.gz"
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libjpeg-turbo"
PATCH_COMMAND autoreconf -fiv
CONFIGURE_COMMAND ./configure
${CONFIGURE_VARS}
--enable-shared
--disable-static
--with-jpeg8
BUILD_IN_SOURCE 1
)

ExternalProject_Add(libpng
URL "https://downloads.sourceforge.net/libpng/libpng-${PNG_VERSION}.tar.gz"
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libpng"
CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/libpng/src/libpng/configure
${CONFIGURE_VARS}
--enable-shared
--disable-static
--disable-dependency-tracking
--disable-silent-rules
)

# giflib hasn't a standard build system, don't append CONFIGURE_VARS
ExternalProject_Add(giflib
URL "https://downloads.sourceforge.net/project/giflib/giflib-${GIF_VERSION}.tar.bz2"
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/giflib"
CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/giflib/src/giflib/configure
--prefix=${EXT_INSTALL_DIR}
${CONFIGURE_HOST}
--enable-shared
--disable-static
--disable-dependency-tracking
)

ExternalProject_Add(libwebp
URL "http://downloads.webmproject.org/releases/webp/libwebp-${WEBP_VERSION}.tar.gz"
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libwebp"
CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/libwebp/src/libwebp/configure
${CONFIGURE_VARS}
--with-gifincludedir=${EXT_INSTALL_DIR}/include
--with-giflibdir=${EXT_INSTALL_DIR}/lib
--with-jpegincludedir=${EXT_INSTALL_DIR}/include
--with-jpeglibdir=${EXT_INSTALL_DIR}/lib
--with-pngincludedir=${EXT_INSTALL_DIR}/include
--with-pnglibdir=${EXT_INSTALL_DIR}/lib
--enable-shared
--disable-static
--disable-dependency-tracking
--enable-libwebpmux
--without-orc
--disable-assert
--enable-avx2
--enable-sse4.1
--enable-sse2
--enable-threading
DEPENDS libjpeg-turbo libpng giflib
)

ExternalProject_Add(lcms2
URL "https://github.com/mm2/Little-CMS/archive/lcms${LCMS2_VERSION}.tar.gz"
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/lcms2"
CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/lcms2/src/lcms2/configure
${CONFIGURE_VARS}
--enable-shared
--disable-static
--disable-dependency-tracking
)

# Cannot set CFLAGS with space separated flags
ExternalProject_Add(libvips
URL "https://github.com/libvips/libvips/archive/v${VIPS_VERSION}.tar.gz"
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libvips"
CONFIGURE_COMMAND ./autogen.sh
PKG_CONFIG_PATH=${EXT_INSTALL_DIR}/lib/pkgconfig:$PKG_CONFIG_PATH
LDFLAGS=-L${EXT_INSTALL_DIR}/lib,-Wl,-rpath=${EXT_INSTALL_DIR}/lib
CPPFLAGS=-I${EXT_INSTALL_DIR}/include
--prefix=${EXT_INSTALL_DIR}
${CONFIGURE_HOST}
--enable-shared
--disable-static
--disable-dependency-tracking
--with-libwebp
--with-lcms
--with-imagequant
--with-jpeg
--with-jpeg-includes=${EXT_INSTALL_DIR}/include
--with-jpeg-libraries=${EXT_INSTALL_DIR}/lib
--without-magick
--without-orc
--without-gsf
--without-rsvg
DEPENDS libimagequant libjpeg-turbo libpng giflib libwebp lcms2
BUILD_IN_SOURCE 1
)

set(VIPS_INCLUDE_DIRS CACHE INTERNAL "${EXT_INSTALL_DIR}/include")
set(VIPS_LIBRARY_DIRS CACHE INTERNAL "${EXT_INSTALL_DIR}/lib")
set(VIPS_LIBRARIES CACHE INTERNAL "-lvips")
8 changes: 8 additions & 0 deletions lib/VERSIONS
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
LIQ_VERSION=2.12.2
EXIF_VERSION=0.6.22
JPG_VERSION=1.4.2
PNG_VERSION=1.6.34
GIF_VERSION=5.1.4
WEBP_VERSION=1.0.2
LCMS2_VERSION=2.9
VIPS_VERSION=8.9.0
Loading

0 comments on commit e37c1a6

Please sign in to comment.