deps build: add openjpeg to OIIO
[blender.git] / build_files / build_environment / cmake / openimageio.cmake
1 # ***** BEGIN GPL LICENSE BLOCK *****
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ***** END GPL LICENSE BLOCK *****
18
19 if(BUILD_MODE STREQUAL Release)
20         set(OIIO_TOOLS ON)
21 else()
22         set(OIIO_TOOLS OFF)
23 endif()
24
25 if(UNIX AND NOT APPLE)
26         # This causes linking to static pthread libraries which gives link errors.
27         # Since we manually specify library paths it should static link other libs.
28         set(OPENIMAGEIO_LINKSTATIC -DLINKSTATIC=OFF)
29 else()
30         set(OPENIMAGEIO_LINKSTATIC -DLINKSTATIC=ON)
31 endif()
32
33 if(WIN32)
34         set(PNG_LIBNAME libpng16_static${LIBEXT})
35         set(OIIO_SIMD_FLAGS -DUSE_SIMD=sse2)
36 else()
37         set(PNG_LIBNAME libpng${LIBEXT})
38         set(OIIO_SIMD_FLAGS)
39 endif()
40
41 set(OPENIMAGEIO_EXTRA_ARGS
42         -DBUILDSTATIC=ON
43         ${OPENIMAGEIO_LINKSTATIC}
44         -DOPENEXR_INCLUDE_DIR=${LIBDIR}/openexr/include/openexr/
45         -DOPENEXR_ILMIMF_LIBRARIES=${LIBDIR}/openexr/lib/IlmImf-2_2${LIBEXT}
46         -DBoost_COMPILER:STRING=${BOOST_COMPILER_STRING}
47         -DBoost_USE_MULTITHREADED=ON
48         -DBoost_USE_STATIC_LIBS=ON
49         -DBoost_USE_STATIC_RUNTIME=ON
50         -DBOOST_ROOT=${LIBDIR}/boost
51         -DBOOST_LIBRARYDIR=${LIBDIR}/boost/lib/
52         -DBoost_NO_SYSTEM_PATHS=ON
53         -OIIO_BUILD_CPP11=ON
54         -DUSE_OPENGL=OFF
55         -DUSE_TBB=OFF
56         -DUSE_FIELD3D=OFF
57         -DUSE_QT=OFF
58         -DUSE_PYTHON=OFF
59         -DUSE_GIF=OFF
60         -DUSE_OPENCV=OFF
61         -DUSE_OPENSSL=OFF
62         -DUSE_OPENJPEG=ON
63         -DUSE_FFMPEG=OFF
64         -DUSE_PTEX=OFF
65         -DUSE_FREETYPE=OFF
66         -DUSE_LIBRAW=OFF
67         -DUSE_PYTHON=OFF
68         -DUSE_PYTHON3=OFF
69         -DUSE_OCIO=OFF
70         -DOIIO_BUILD_TOOLS=${OIIO_TOOLS}
71         -DOIIO_BUILD_TESTS=OFF
72         -DBUILD_TESTING=OFF
73         -DZLIB_LIBRARY=${LIBDIR}/zlib/lib/${ZLIB_LIBRARY}
74         -DZLIB_INCLUDE_DIR=${LIBDIR}/zlib/include
75         -DPNG_LIBRARY=${LIBDIR}/png/lib/${PNG_LIBNAME}
76         -DPNG_PNG_INCLUDE_DIR=${LIBDIR}/png/include
77         -DTIFF_LIBRARY=${LIBDIR}/tiff/lib/${LIBPREFIX}tiff${LIBEXT}
78         -DTIFF_INCLUDE_DIR=${LIBDIR}/tiff/include
79         -DJPEG_LIBRARY=${LIBDIR}/jpg/lib/${JPEG_LIBRARY}
80         -DJPEG_INCLUDE_DIR=${LIBDIR}/jpg/include
81         -DOPENJPEG_INCLUDE_DIR=${LIBDIR}/openjpeg/include/openjpeg-${OPENJPEG_VERSION}
82         -DOPENJPEG_LIBRARY=${LIBDIR}/openjpeg/lib/${OPENJPEG_LIBRARY}
83         -DOCIO_PATH=${LIBDIR}/opencolorio/
84         -DOpenEXR_USE_STATIC_LIBS=On
85         -DOPENEXR_HOME=${LIBDIR}/openexr/
86         -DILMBASE_INCLUDE_PATH=${LIBDIR}/ilmbase/
87         -DILMBASE_PACKAGE_PREFIX=${LIBDIR}/ilmbase/
88         -DILMBASE_INCLUDE_DIR=${LIBDIR}/ilmbase/include/
89         -DOPENEXR_HALF_LIBRARY=${LIBDIR}/ilmbase/lib/${LIBPREFIX}Half${LIBEXT}
90         -DOPENEXR_IMATH_LIBRARY=${LIBDIR}/ilmbase/lib/${LIBPREFIX}Imath-2_2${LIBEXT}
91         -DOPENEXR_ILMTHREAD_LIBRARY=${LIBDIR}/ilmbase/lib/${LIBPREFIX}IlmThread-2_2${LIBEXT}
92         -DOPENEXR_IEX_LIBRARY=${LIBDIR}/ilmbase/lib/${LIBPREFIX}Iex-2_2${LIBEXT}
93         -DOPENEXR_INCLUDE_DIR=${LIBDIR}/openexr/include/
94         -DOPENEXR_ILMIMF_LIBRARY=${LIBDIR}/openexr/lib/${LIBPREFIX}IlmImf-2_2${LIBEXT}
95         -DSTOP_ON_WARNING=OFF
96         -DWEBP_INCLUDE_DIR=${LIBDIR}/webp/include
97         -DWEBP_LIBRARY=${LIBDIR}/webp/lib/${LIBPREFIX}webp${LIBEXT}
98         ${OIIO_SIMD_FLAGS}
99 )
100
101 ExternalProject_Add(external_openimageio
102         URL ${OPENIMAGEIO_URI}
103         DOWNLOAD_DIR ${DOWNLOAD_DIR}
104         URL_HASH MD5=${OPENIMAGEIO_HASH}
105         PREFIX ${BUILD_DIR}/openimageio
106         PATCH_COMMAND ${PATCH_CMD} -p 0 -N -d ${BUILD_DIR}/openimageio/src/external_openimageio/src/include < ${PATCH_DIR}/openimageio_gdi.diff &&
107                                 ${PATCH_CMD} -p 0 -N -d ${BUILD_DIR}/openimageio/src/external_openimageio/ < ${PATCH_DIR}/openimageio_staticexr.diff
108         CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${LIBDIR}/openimageio ${DEFAULT_CMAKE_FLAGS} ${OPENIMAGEIO_EXTRA_ARGS}
109         INSTALL_DIR ${LIBDIR}/openimageio
110 )
111
112 add_dependencies(external_openimageio external_png external_zlib external_ilmbase external_openexr external_jpeg external_boost external_tiff external_webp external_opencolorio external_openjpeg)
113 if(NOT WIN32)
114         add_dependencies(external_openimageio external_opencolorio_extra)
115 endif()