Skip to content

Commit

Permalink
build: Add support for pip install OpenImageIO
Browse files Browse the repository at this point in the history
- Add build scripts for wheel dependencies.
- Fix OpenColorIO.
- Working wheel build.
- Remove unused scripts.

Signed-off-by: Alex Clark <[email protected]>
  • Loading branch information
JeanChristopheMorinPerso authored and aclark4life committed Oct 13, 2023
1 parent 8981cdc commit d8ce54a
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 53 deletions.
24 changes: 13 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@ if (CMAKE_VERSION VERSION_LESS 3.21)
endif ()
endif ()

# If the user wants to use Conan to build dependencies, they will have done
# this prior to the cmake config:
# cd <build area>
# conan install <source area>
# and that will leave a conanbuildinfo.cmake in the build area for us.
if (EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include (${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
message (STATUS "Using Conan for dependencies")
conan_basic_setup()
endif()

if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE "Release")
endif ()
Expand Down Expand Up @@ -144,6 +133,7 @@ message(STATUS "Setting Namespace to: ${PROJ_NAMESPACE_V}")
add_definitions (-DOIIO_INTERNAL=1)

list (APPEND CMAKE_MODULE_PATH
"${PROJECT_SOURCE_DIR}/build"
"${PROJECT_SOURCE_DIR}/src/cmake/modules"
"${PROJECT_SOURCE_DIR}/src/cmake")

Expand All @@ -159,6 +149,18 @@ include (add_oiio_plugin)
# All the C++ and compiler related options and adjustments
include (compiler)

# If the user wants to use Conan to build dependencies, they will have done
# this prior to the cmake config:
# cd <build area>
# conan install <source area>
# and that will leave a conanbuildinfo.cmake in the build area for us.
if (EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include (${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
message (STATUS "Using Conan for dependencies")
conan_basic_setup()
endif()


# Utilities and options related to finding python and making python bindings
include (pythonutils)

Expand Down
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ Additionally, a few helpful modifiers alter some build-time options:
| make STOP_ON_WARNING=0 | Do not stop building if compiler warns |
| make EMBEDPLUGINS=0 ... | Don't compile the plugins into libOpenImageIO |
| make USE_OPENGL=0 ... | Skip anything that needs OpenGL |
| make USE_QT=0 ... | Skip anything that needs Qt |
| make USE_QT5=0 ... | Skip anything that needs Qt |
| make MYCC=xx MYCXX=yy ... | Use custom compilers |
| make USE_PYTHON=0 ... | Don't build the Python binding |
| make BUILD_SHARED_LIBS=0 | Build static library instead of shared |
Expand Down
38 changes: 24 additions & 14 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
[requires]
zlib/1.2.11
libtiff/4.0.9
boost/1.79.0
zlib/1.2.12
libtiff/4.3.0
libpng/1.6.37
openexr/2.4.0
boost/1.70.0
libjpeg/9c
libjpeg-turbo/2.0.2
giflib/5.1.4
freetype/2.10.0
#opencv/4.1.1@conan/stable
openjpeg/2.3.1
libwebp/1.0.3
tsl-robin-map/0.6.1@tessil/stable
giflib/5.2.1
freetype/2.12.1
#opencv/4.5.5
libjpeg/9d
openjpeg/2.5.0
libwebp/1.2.3
#tsl-robin-map/0.6.1@tessil/stable
tbb/2020.0
ffmpeg/5.0
libheif/1.12.0
lcms/2.13.1
libraw/0.20.2
ptex/2.4.0
yaml-cpp/0.6.3
pystring/1.1.3
expat/2.4.8
# To do:
# opencolorio? not on conan?
# pybind11/2.4.3 - conan doesn't have this minimum version
Expand All @@ -26,7 +32,11 @@ tbb/2020.0


[generators]
cmake
cmake_find_package

[options]
#libpng:shared=False
*:shared=False
*:fPIC=True
ffmpeg:with_vulkan=False
ffmpeg:with_asm=False
libx265:assembly=False
1 change: 1 addition & 0 deletions src/build-scripts/build_opencolorio.bash
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ OPENCOLORIO_BUILDOPTS="-DOCIO_BUILD_APPS=OFF -DOCIO_BUILD_NUKE=OFF \
-DOCIO_BUILD_GPU_TESTS=OFF \
-DOCIO_BUILD_PYTHON=OFF -DOCIO_BUILD_PYGLUE=OFF \
-DOCIO_BUILD_JAVA=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DBUILD_SHARED_LIBS=${OPENCOLORIO_BUILD_SHARED_LIBS:=ON}"
BASEDIR=`pwd`
pwd
Expand Down
17 changes: 16 additions & 1 deletion src/build-scripts/ci-build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@ if [[ ${GITHUB_ACTIONS} == true ]] ; then
OIIO_CMAKE_FLAGS+=" -DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD:=ON} -DCMAKE_UNITY_BUILD_MODE=${CMAKE_UNITY_BUILD_MODE:=BATCH}"
fi

cmake -S . -B build -G "$CMAKE_GENERATOR" \
pushd build

if [[ $(conan profile list | grep default) == '' ]]; then
conan profile new default --detect
fi
conan profile update settings.compiler=gcc default
conan profile update settings.compiler.version=8 default
conan profile update settings.compiler.libcxx=libstdc++11 default
echo -e '[conf]\ntools.system.package_manager:mode=install' >> ~/.conan/profiles/default
if [[ "$USE_FFMPEG" == '1' ]]; then
CONAN_SYSREQUIRES_SUDO=0 CONAN_SYSREQUIRES_MODE=enabled conan install .. --build=openjpeg --build=libx264 --build=ffmpeg --build=libx265
else
CONAN_SYSREQUIRES_SUDO=0 CONAN_SYSREQUIRES_MODE=enabled conan install ..
fi

cmake .. -G "$CMAKE_GENERATOR" \
-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
-DCMAKE_INSTALL_PREFIX="$OpenImageIO_ROOT" \
Expand Down
74 changes: 74 additions & 0 deletions src/build-scripts/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash

set -ex
apt update
# apt upgrade -y
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt install sudo wget gzip software-properties-common -y

if [[ ! -d /opt/cmake ]]; then
currentPath=$(pwd)
wget https://github.com/Kitware/CMake/releases/download/v3.23.2/cmake-3.23.2-linux-x86_64.tar.gz
mkdir -p /opt/cmake
cd /opt
tar -xzf "${currentPath}/cmake-3.23.2-linux-x86_64.tar.gz"
rm "${currentPath}/cmake-3.23.2-linux-x86_64.tar.gz"
mv cmake-3.23.2-linux-x86_64/* cmake/
rm -rf cmake-3.23.2-linux-x86_64/
cd "${currentPath}"
fi

export PATH=/opt/cmake/bin:$PATH

export CXX=g++-8
export CC=gcc-8
export COMPILER=gcc-8
export CMAKE_CXX_STANDARD=17

export USE_OPENVDB=0
export USE_QT5=0
export USE_OPENGL=0
export USE_NUKE=0
export USE_R3DSDK=0
export USE_JPEGTURBO=0

export USE_FFMPEG=1
export USE_PNG=1
export USE_OPENCV=0
export USE_GIF=1
export USE_PTEX=1
export USE_WEBP=1
export USE_OPENCOLORIO=1
export USE_OPENEXR=1
export USE_LIBHEIF=1
export USE_TIFF=1
export USE_LIBRAW=1
export USE_OPENJPEG=1
export USE_FREETYPE=1

export OPENCOLORIO_VERSION=v2.1.2
export PUGIXML_VERSION=v1.11.4
export FMT_VERSION=9.0.0
export OPENEXR_VERSION=v3.1.5
export PYBIND11_VERSION=v2.9.2

export OPENCOLORIO_BUILD_SHARED_LIBS=OFF
export OPENEXR_CMAKE_FLAGS=-DBUILD_SHARED_LIBS=OFF
export PUGIXML_BUILD_OPTS=-DBUILD_SHARED_LIBS=OFF

export MY_CMAKE_FLAGS="${MY_CMAKE_FLAGS} -DBUILD_SHARED_LIBS=OFF -DLINKSTATIC=ON -DOIIO_BUILD_TESTS=OFF -DOPENCOLORIO_NO_CONFIG=ON -DOIIO_BUILD_TOOLS=ON"
export PYTHON_VERSION=3.9

export OPENIMAGEIO_OPTIONS="openexr:core=1"

source src/build-scripts/ci-startup.bash

export CMAKE_BUILD_PARALLEL_LEVEL=16

unset TERM

apt install python3 python3-pip cmake pkg-config -y
python3 -m pip install conan

source src/build-scripts/gh-installdeps.bash

source src/build-scripts/ci-build.bash
28 changes: 26 additions & 2 deletions src/build-scripts/gh-installdeps.bash
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ if [[ "$ASWF_ORG" != "" ]] ; then
else
# Using native Ubuntu runner

sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
time sudo apt-get update

time sudo apt-get -q install -y \
Expand All @@ -83,7 +84,10 @@ else
locales wget \
libopencolorio-dev \
libopencv-dev \
libhdf5-dev
qt5-default \
libdeflate-dev libzstd-dev \
locales wget \
libx265-dev
if [[ "${QT_VERSION:-5}" == "5" ]] ; then
time sudo apt-get -q install -y \
qt5-default || /bin/true
Expand All @@ -96,7 +100,7 @@ else

# Nonstandard python versions
if [[ "${PYTHON_VERSION}" == "3.9" ]] ; then
time sudo apt-get -q install -y python3.9-dev python3-numpy
time sudo apt-get -q install -y python3.9-dev python3-numpy python3-pip
pip3 --version
pip3 install numpy
elif [[ "$PYTHON_VERSION" == "2.7" ]] ; then
Expand All @@ -112,6 +116,15 @@ else
libheif-plugin-aomenc libheif-plugin-libde265 \
libheif-plugin-x265 libheif-dev || true
fi
# if [[ "$USE_LIBHEIF" != "0" ]] ; then
# # echo 'deb http://ppa.launchpad.net/strukturag/libde265/ubuntu focal main' > /etc/apt/sources.list.d/strukturag-ubuntu-libde265-focal.list
# # echo 'deb http://ppa.launchpad.net/strukturag/libheif/ubuntu focal main' > /etc/apt/sources.list.d/strukturag-ubuntu-libheif-focal.list
# # apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv-key 9641080A705C2B92
# sudo add-apt-repository ppa:strukturag/libde265 -y
# sudo add-apt-repository ppa:strukturag/libheif -y
# time sudo apt-get update
# time sudo apt-get -q install -y libheif-dev
# fi

export CMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu:$CMAKE_PREFIX_PATH

Expand Down Expand Up @@ -205,6 +218,17 @@ if [[ "$LIBJPEGTURBO_VERSION" != "" ]] ; then
source src/build-scripts/build_libjpeg-turbo.bash
fi

if [[ "$LIBAOM_VERSION" != "" ]] ; then
source src/build-scripts/build_libaom.bash
fi

if [[ "$LIBDE265_VERSION" != "" ]] ; then
source src/build-scripts/build_libde265.bash
fi

if [[ "$LIBHEIF_VERSION" != "" ]] ; then
source src/build-scripts/build_libheif.bash

if [[ "$USE_ICC" != "" ]] ; then
# We used gcc for the prior dependency builds, but use icc for OIIO itself
echo "which icpc:" $(which icpc)
Expand Down
2 changes: 1 addition & 1 deletion src/cmake/compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ if (LINKSTATIC)
if (WIN32)
set (CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
else ()
set (CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
set (CMAKE_FIND_LIBRARY_SUFFIXES .a)
endif ()
endif ()

Expand Down
26 changes: 17 additions & 9 deletions src/cmake/externalpackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ if (OpenColorIO_FOUND)
endif ()
else ()
set (OpenColorIO_FOUND 0)
else ()
checked_find_package (yaml-cpp)
checked_find_package (pystring)
checked_find_package (EXPAT)
endif ()

checked_find_package (OpenCV 3.0
Expand All @@ -198,25 +202,29 @@ checked_find_package (TBB 2017
PREFER_CONFIG)

checked_find_package (DCMTK VERSION_MIN 3.6.1) # For DICOM images
checked_find_package (FFmpeg VERSION_MIN 3.0)
checked_find_package (ffmpeg
COMPONENTS avcodec avformat avutil swscale
VERSION_MIN 3.0)
checked_find_package (GIF
VERSION_MIN 4
RECOMMEND_MIN 5.0
RECOMMEND_MIN_REASON "for stability and thread safety")

# For HEIF/HEIC/AVIF formats
checked_find_package (Libheif VERSION_MIN 1.3
checked_find_package (libheif VERSION_MIN 1.3
RECOMMEND_MIN 1.7
RECOMMEND_MIN_REASON "for AVIF support")
if (APPLE AND LIBHEIF_VERSION VERSION_GREATER_EQUAL 1.10 AND LIBHEIF_VERSION VERSION_LESS 1.11)
message (WARNING "Libheif 1.10 on Apple is known to be broken, disabling libheif support")
set (Libheif_FOUND 0)
set (libheif_FOUND 0)
endif ()

checked_find_package (LibRaw
checked_find_package (libraw
VERSION_MIN 0.18
RECOMMEND_MIN 0.18
RECOMMEND_MIN_REASON "for ACES support and better camera metadata"
PRINT LibRaw_r_LIBRARIES)
if (LibRaw_FOUND AND LibRaw_VERSION VERSION_LESS 0.20 AND CMAKE_CXX_STANDARD VERSION_GREATER_EQUAL 17)
if (libraw_FOUND AND libraw_VERSION VERSION_LESS 0.20 AND CMAKE_CXX_STANDARD VERSION_GREATER_EQUAL 17)
message (STATUS "${ColorYellow}WARNING When building for C++17, LibRaw should be 0.20 or higher (found ${LibRaw_VERSION}). You may get errors, depending on the compiler.${ColorReset}")
# Currently, we issue the above warning and let them take their chances.
# If we wish to disable the LibRaw<0.20/C++17 combination that may fail,
Expand All @@ -236,12 +244,12 @@ checked_find_package (OpenVDB
DEPS TBB
DEFINITIONS -DUSE_OPENVDB=1)

checked_find_package (Ptex PREFER_CONFIG)
if (NOT Ptex_FOUND OR NOT Ptex_VERSION)
checked_find_package (ptex PREFER_CONFIG)
if (NOT ptex_FOUND OR NOT ptex_VERSION)
# Fallback for inadequate Ptex exported configs. This will eventually
# disappear when we can 100% trust Ptex's exports.
unset (Ptex_FOUND)
checked_find_package (Ptex)
unset (ptex_FOUND)
checked_find_package (ptex)
endif ()

checked_find_package (WebP)
Expand Down
5 changes: 3 additions & 2 deletions src/ffmpeg.imageio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

if (FFmpeg_FOUND)
if (FFmpeg_FOUND OR ffmpeg_FOUND)
if (LINKSTATIC)
set (_static_suffixes .lib .a)
set (_static_libraries_found 0)
Expand All @@ -26,9 +26,10 @@ if (FFmpeg_FOUND)
endif()

add_oiio_plugin (ffmpeginput.cpp
INCLUDE_DIRS ${FFMPEG_INCLUDES}
INCLUDE_DIRS ${FFMPEG_INCLUDES} ${ffmpeg_INCLUDES}
LINK_LIBRARIES ${FFMPEG_LIBRARIES}
${BZIP2_LIBRARIES}
ffmpeg::avcodec ffmpeg::avformat ffmpeg::avutil ffmpeg::swscale
DEFINITIONS "-DUSE_FFMPEG"
"-DOIIO_FFMPEG_VERSION=\"${FFMPEG_VERSION}\"")
else()
Expand Down
6 changes: 3 additions & 3 deletions src/heif.imageio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

if (Libheif_FOUND)
if (Libheif_FOUND OR libheif_FOUND)
if (LINKSTATIC)
set (_static_suffixes .lib .a)
set (_static_libraries_found 0)
Expand All @@ -26,8 +26,8 @@ if (Libheif_FOUND)
endif()

add_oiio_plugin (heifinput.cpp heifoutput.cpp
INCLUDE_DIRS ${LIBHEIF_INCLUDES}
LINK_LIBRARIES ${LIBHEIF_LIBRARIES}
INCLUDE_DIRS ${LIBHEIF_INCLUDES} ${libheif_INCLUDES}
LINK_LIBRARIES libheif::heif ${LIBHEIF_LIBRARIES} ${libheif_LIBRARIES}
DEFINITIONS "-DUSE_HEIF=1")
else ()
message (WARNING "heif plugin will not be built")
Expand Down
Loading

0 comments on commit d8ce54a

Please sign in to comment.