From 59054d906fa9b539a14768101ba66c1182c13f0f Mon Sep 17 00:00:00 2001 From: Ankit Meel Date: Mon, 1 Feb 2021 21:58:57 +0530 Subject: [PATCH] CMake/Windows/macOS: Add Libharu Decision: https://lists.blender.org/pipermail/bf-committers/2020-December/050836.html Adds CMake dependency builder support. Tested on macOS and Windows (Thanks @LazyDodo). Reviewed By: #platform_macos, LazyDodo, sebbas Maniphest Task: T84836 Differential Revision: https://developer.blender.org/D9928 --- CMakeLists.txt | 2 + build_files/build_environment/CMakeLists.txt | 1 + .../build_environment/cmake/haru.cmake | 46 +++++++++++++ .../build_environment/cmake/harvest.cmake | 2 + .../build_environment/cmake/versions.cmake | 4 ++ .../build_environment/patches/haru.diff | 12 ++++ build_files/cmake/Modules/FindHaru.cmake | 64 +++++++++++++++++++ build_files/cmake/config/blender_full.cmake | 1 + build_files/cmake/config/blender_lite.cmake | 1 + .../cmake/config/blender_release.cmake | 1 + .../cmake/platform/platform_apple.cmake | 13 ++++ .../cmake/platform/platform_win32.cmake | 12 ++++ 12 files changed, 159 insertions(+) create mode 100644 build_files/build_environment/cmake/haru.cmake create mode 100644 build_files/build_environment/patches/haru.diff create mode 100644 build_files/cmake/Modules/FindHaru.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 035cf81e1b3..ee743b7a5ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -205,6 +205,7 @@ option(WITH_OPENVDB_BLOSC "Enable blosc compression for OpenVDB, only enable if option(WITH_OPENVDB_3_ABI_COMPATIBLE "Assume OpenVDB library has been compiled with version 3 ABI compatibility" OFF) mark_as_advanced(WITH_OPENVDB_3_ABI_COMPATIBLE) option(WITH_NANOVDB "Enable usage of NanoVDB data structure for rendering on the GPU" ON) +option(WITH_HARU "Enable features relying on Libharu (Grease pencil PDF export)" ON) # GHOST Windowing Library Options option(WITH_GHOST_DEBUG "Enable debugging output for the GHOST library" OFF) @@ -1849,6 +1850,7 @@ if(FIRST_RUN) info_cfg_option(WITH_FFTW3) info_cfg_option(WITH_FREESTYLE) info_cfg_option(WITH_GMP) + info_cfg_option(WITH_HARU) info_cfg_option(WITH_IK_ITASC) info_cfg_option(WITH_IK_SOLVER) info_cfg_option(WITH_INPUT_NDOF) diff --git a/build_files/build_environment/CMakeLists.txt b/build_files/build_environment/CMakeLists.txt index dfbb0e824a0..672f5820a16 100644 --- a/build_files/build_environment/CMakeLists.txt +++ b/build_files/build_environment/CMakeLists.txt @@ -92,6 +92,7 @@ include(cmake/package_python.cmake) include(cmake/numpy.cmake) include(cmake/usd.cmake) include(cmake/potrace.cmake) +include(cmake/haru.cmake) # Boost needs to be included after python.cmake due to the PYTHON_BINARY variable being needed. include(cmake/boost.cmake) include(cmake/pugixml.cmake) diff --git a/build_files/build_environment/cmake/haru.cmake b/build_files/build_environment/cmake/haru.cmake new file mode 100644 index 00000000000..7382095f459 --- /dev/null +++ b/build_files/build_environment/cmake/haru.cmake @@ -0,0 +1,46 @@ +# ***** BEGIN GPL LICENSE BLOCK ***** +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ***** END GPL LICENSE BLOCK ***** + +set(HARU_EXTRA_ARGS + -DLIBHPDF_SHARED=OFF + -DLIBHPDF_STATIC=ON + -DLIBHPDF_EXAMPLES=OFF + -DLIBHPDF_ENABLE_EXCEPTIONS=ON +) + +ExternalProject_Add(external_haru + URL ${HARU_URI} + DOWNLOAD_DIR ${DOWNLOAD_DIR} + URL_HASH MD5=${HARU_HASH} + PREFIX ${BUILD_DIR}/haru + PATCH_COMMAND ${PATCH_CMD} -p 1 -d ${BUILD_DIR}/haru/src/external_haru < ${PATCH_DIR}/haru.diff + CMAKE_ARGS + -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=${LIBDIR}/haru + ${DEFAULT_CMAKE_FLAGS} ${HARU_EXTRA_ARGS} + INSTALL_DIR ${LIBDIR}/haru +) + +if(WIN32) + if(BUILD_MODE STREQUAL Release) + ExternalProject_Add_Step(external_haru after_install + COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/haru/include ${HARVEST_TARGET}/haru/include + COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR}/haru/lib/libhpdfs.lib ${HARVEST_TARGET}/haru/lib/libhpdfs.lib + DEPENDEES install + ) + endif() +endif() diff --git a/build_files/build_environment/cmake/harvest.cmake b/build_files/build_environment/cmake/harvest.cmake index 536907f563d..6785b727a69 100644 --- a/build_files/build_environment/cmake/harvest.cmake +++ b/build_files/build_environment/cmake/harvest.cmake @@ -187,6 +187,8 @@ harvest(usd/lib/usd usd/lib/usd "*") harvest(usd/plugin usd/plugin "*") harvest(potrace/include potrace/include "*.h") harvest(potrace/lib potrace/lib "*.a") +harvest(haru/include haru/include "*.h") +harvest(haru/lib haru/lib "*.a") if(UNIX AND NOT APPLE) harvest(libglu/lib mesa/lib "*.so*") diff --git a/build_files/build_environment/cmake/versions.cmake b/build_files/build_environment/cmake/versions.cmake index d4a2c715ecc..8d3793ef242 100644 --- a/build_files/build_environment/cmake/versions.cmake +++ b/build_files/build_environment/cmake/versions.cmake @@ -331,3 +331,7 @@ set(GMP_HASH a325e3f09e6d91e62101e59f9bda3ec1) set(POTRACE_VERSION 1.16) set(POTRACE_URI http://potrace.sourceforge.net/download/${POTRACE_VERSION}/potrace-${POTRACE_VERSION}.tar.gz) set(POTRACE_HASH 5f0bd87ddd9a620b0c4e65652ef93d69) + +set(HARU_VERSION 2_3_0) +set(HARU_URI https://github.com/libharu/libharu/archive/RELEASE_${HARU_VERSION}.tar.gz) +set(HARU_HASH 4f916aa49c3069b3a10850013c507460) diff --git a/build_files/build_environment/patches/haru.diff b/build_files/build_environment/patches/haru.diff new file mode 100644 index 00000000000..fed551b4bf0 --- /dev/null +++ b/build_files/build_environment/patches/haru.diff @@ -0,0 +1,12 @@ +diff --git a/src/hpdf_image_ccitt.c b/src/hpdf_image_ccitt.c +index 8672763..9be531a 100644 +--- a/src/hpdf_image_ccitt.c ++++ b/src/hpdf_image_ccitt.c +@@ -21,7 +21,6 @@ + #include + #include + +-#define G3CODES + #include "t4.h" + + typedef unsigned int uint32; diff --git a/build_files/cmake/Modules/FindHaru.cmake b/build_files/cmake/Modules/FindHaru.cmake new file mode 100644 index 00000000000..5774f83b8c5 --- /dev/null +++ b/build_files/cmake/Modules/FindHaru.cmake @@ -0,0 +1,64 @@ +# - Find HARU library +# Find the native Haru includes and library +# This module defines +# HARU_INCLUDE_DIRS, where to find hpdf.h, set when +# HARU_INCLUDE_DIR is found. +# HARU_LIBRARIES, libraries to link against to use Haru. +# HARU_ROOT_DIR, The base directory to search for Haru. +# This can also be an environment variable. +# HARU_FOUND, If false, do not try to use Haru. +# +# also defined, but not for general use are +# HARU_LIBRARY, where to find the Haru library. + +#============================================================================= +# Copyright 2021 Blender Foundation. +# +# Distributed under the OSI-approved BSD 3-Clause License, +# see accompanying file BSD-3-Clause-license.txt for details. +#============================================================================= + +# If HARU_ROOT_DIR was defined in the environment, use it. +if(NOT HARU_ROOT_DIR AND NOT $ENV{HARU_ROOT_DIR} STREQUAL "") + set(HARU_ROOT_DIR $ENV{HARU_ROOT_DIR}) +endif() + +set(_haru_SEARCH_DIRS + ${HARU_ROOT_DIR} + /opt/lib/haru +) + +find_path(HARU_INCLUDE_DIR + NAMES + hpdf.h + HINTS + ${_haru_SEARCH_DIRS} + PATH_SUFFIXES + include/haru +) + +find_library(HARU_LIBRARY + NAMES + hpdfs + HINTS + ${_haru_SEARCH_DIRS} + PATH_SUFFIXES + lib64 lib +) + +# Handle the QUIETLY and REQUIRED arguments and set HARU_FOUND to TRUE if +# all listed variables are TRUE. +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Haru DEFAULT_MSG HARU_LIBRARY HARU_INCLUDE_DIR) + +if(HARU_FOUND) + set(HARU_LIBRARIES ${HARU_LIBRARY}) + set(HARU_INCLUDE_DIRS ${HARU_INCLUDE_DIR}) +endif() + +mark_as_advanced( + HARU_INCLUDE_DIR + HARU_LIBRARY +) + +unset(_haru_SEARCH_DIRS) diff --git a/build_files/cmake/config/blender_full.cmake b/build_files/cmake/config/blender_full.cmake index aab997ab453..75f78befb60 100644 --- a/build_files/cmake/config/blender_full.cmake +++ b/build_files/cmake/config/blender_full.cmake @@ -19,6 +19,7 @@ set(WITH_DRACO ON CACHE BOOL "" FORCE) set(WITH_FFTW3 ON CACHE BOOL "" FORCE) set(WITH_FREESTYLE ON CACHE BOOL "" FORCE) set(WITH_GMP ON CACHE BOOL "" FORCE) +set(WITH_HARU ON CACHE BOOL "" FORCE) set(WITH_IK_ITASC ON CACHE BOOL "" FORCE) set(WITH_IK_SOLVER ON CACHE BOOL "" FORCE) set(WITH_IMAGE_CINEON ON CACHE BOOL "" FORCE) diff --git a/build_files/cmake/config/blender_lite.cmake b/build_files/cmake/config/blender_lite.cmake index 480548abca7..680734aba6e 100644 --- a/build_files/cmake/config/blender_lite.cmake +++ b/build_files/cmake/config/blender_lite.cmake @@ -24,6 +24,7 @@ set(WITH_DRACO OFF CACHE BOOL "" FORCE) set(WITH_FFTW3 OFF CACHE BOOL "" FORCE) set(WITH_FREESTYLE OFF CACHE BOOL "" FORCE) set(WITH_GMP OFF CACHE BOOL "" FORCE) +set(WITH_HARU OFF CACHE BOOL "" FORCE) set(WITH_IK_ITASC OFF CACHE BOOL "" FORCE) set(WITH_IK_SOLVER OFF CACHE BOOL "" FORCE) set(WITH_IMAGE_CINEON OFF CACHE BOOL "" FORCE) diff --git a/build_files/cmake/config/blender_release.cmake b/build_files/cmake/config/blender_release.cmake index 96101ee7bcc..973d6cdb34e 100644 --- a/build_files/cmake/config/blender_release.cmake +++ b/build_files/cmake/config/blender_release.cmake @@ -20,6 +20,7 @@ set(WITH_DRACO ON CACHE BOOL "" FORCE) set(WITH_FFTW3 ON CACHE BOOL "" FORCE) set(WITH_FREESTYLE ON CACHE BOOL "" FORCE) set(WITH_GMP ON CACHE BOOL "" FORCE) +set(WITH_HARU ON CACHE BOOL "" FORCE) set(WITH_IK_SOLVER ON CACHE BOOL "" FORCE) set(WITH_IK_ITASC ON CACHE BOOL "" FORCE) set(WITH_IMAGE_CINEON ON CACHE BOOL "" FORCE) diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake index 31da5292eaf..b4f201e1959 100644 --- a/build_files/cmake/platform/platform_apple.cmake +++ b/build_files/cmake/platform/platform_apple.cmake @@ -428,6 +428,19 @@ if(WITH_GMP) endif() endif() +if(WITH_HARU) + find_package(Haru) + if(NOT HARU_FOUND) + message(WARNING "Haru not found, disabling WITH_HARU") + set(WITH_HARU OFF) + endif() + if(NOT WITH_IMAGE_TIFF) + # Some symbols in libharu are provided by libtiff. + message(WARNING "WITH_IMAGE_TIFF not enabled, disabling WITH_HARU") + set(WITH_HARU OFF) + endif() +endif() + if(EXISTS ${LIBDIR}) without_system_libs_end() endif() diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake index 016ae58fde4..69a78ba7ca6 100644 --- a/build_files/cmake/platform/platform_win32.cmake +++ b/build_files/cmake/platform/platform_win32.cmake @@ -800,3 +800,15 @@ if(WITH_POTRACE) set(POTRACE_LIBRARIES ${LIBDIR}/potrace/lib/potrace.lib) set(POTRACE_FOUND On) endif() + +if(WITH_HARU) + if(EXISTS ${LIBDIR}/haru) + set(HARU_FOUND On) + set(HARU_ROOT_DIR ${LIBDIR}/haru) + set(HARU_INCLUDE_DIRS ${HARU_ROOT_DIR}/include) + set(HARU_LIBRARIES ${HARU_ROOT_DIR}/lib/libhpdfs.lib) + else() + message(WARNING "Haru was not found, disabling WITH_HARU") + set(WITH_HARU OFF) + endif() +endif()