Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/wheel_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
platforms: all

- name: Build wheels
uses: pypa/cibuildwheel@v2.12.0
uses: pypa/cibuildwheel@v2.13.1
env:
CIBW_BUILD: ${{ matrix.python }}
CIBW_ARCHS: ${{ matrix.arch }}
Expand Down Expand Up @@ -194,7 +194,7 @@ jobs:
python-version: '3.8'

- name: Build wheels
uses: pypa/cibuildwheel@v2.12.0
uses: pypa/cibuildwheel@v2.13.1
env:
CIBW_BUILD: ${{ matrix.python }}
CIBW_ARCHS: ${{ matrix.arch }}
Expand Down Expand Up @@ -245,7 +245,7 @@ jobs:
python-version: '3.8'

- name: Build wheels
uses: pypa/cibuildwheel@v2.12.0
uses: pypa/cibuildwheel@v2.13.1
env:
CIBW_BUILD: ${{ matrix.python }}
CIBW_ARCHS: ${{ matrix.arch }}
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ endif()

###############################################################################
# Other preferences

option(OCIO_VERBOSE "Display more information when searching or installing dependencies" OFF)
option(OCIO_USE_SOVERSION "Enable versioning in OCIO shared library name" ON)

###############################################################################
# Warnings / debugging settings
Expand Down Expand Up @@ -190,6 +192,7 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(AMD64|IA64|EM64T|X86|x86_64|i386|i686)
set(OCIO_ARCH_X86 1)
endif()


###############################################################################
# GPU configuration
message(STATUS "")
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ build-backend = "setuptools.build_meta"
[tool.cibuildwheel]
build-verbosity = "1"

test-command = "python -m PyOpenColorIO.tests.OpenColorIOTestSuite"
test-requires = ["numpy"]
test-command = [
"python {project}/tests/python/OpenColorIOTestSuite.py",
"ociocheck"
]

manylinux-x86_64-image = "manylinux2014"
manylinux-i686-image = "manylinux2014"
Expand Down
109 changes: 84 additions & 25 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import os
import re
import shutil
import subprocess
import sys
import tempfile
Expand All @@ -16,27 +15,49 @@


# Extract the project version from CMake generated ABI header.
# NOTE: When droping support for Python2 we can use
# tempfile.TemporaryDirectory() context manager instead of try...finally.
def get_version():
VERSION_REGEX = re.compile(
r"^\s*#\s*define\s+OCIO_VERSION_FULL_STR\s+\"(.*)\"\s*$", re.MULTILINE)

here = os.path.abspath(os.path.dirname(__file__))
dirpath = tempfile.mkdtemp()

try:
stdout = subprocess.check_output(["cmake", here], cwd=dirpath)
path = os.path.join(dirpath, "include", "OpenColorIO", "OpenColorABI.h")
with open(path) as f:
match = VERSION_REGEX.search(f.read())
return match.group(1)
except Exception as e:
raise RuntimeError(
"Unable to find OpenColorIO version: {}".format(str(e))
)
finally:
shutil.rmtree(dirpath)

with tempfile.TemporaryDirectory() as tmpdir:
try:
subprocess.check_call(["cmake", here], cwd=tmpdir)
path = os.path.join(tmpdir, "include", "OpenColorIO", "OpenColorABI.h")
with open(path) as f:
match = VERSION_REGEX.search(f.read())
return match.group(1)
except Exception as e:
raise RuntimeError(
"Unable to find OpenColorIO version: {}".format(str(e))
)


# Call CMake find_package from a dummy script and return whether the package
# has been found or not.
def cmake_find_package(package_name):
with tempfile.TemporaryDirectory() as tmpdir:
try:
cmakelist_path = os.path.join(tmpdir, "CMakeLists.txt")
with open(cmakelist_path, "w") as f:
f.write("""
cmake_minimum_required(VERSION 3.13)
project(test LANGUAGES CXX)

find_package({} REQUIRED)
""".format(package_name)
)

subprocess.check_call(
["cmake", tmpdir],
cwd=tmpdir,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
return True
except Exception as e:
return False


# Convert distutils Windows platform specifiers to CMake -A arguments
Expand All @@ -59,6 +80,7 @@ def __init__(self, name, sourcedir=""):
class CMakeBuild(build_ext):
def build_extension(self, ext):
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
bindir = os.path.join(extdir, "bin")

# required for auto-detection & inclusion of auxiliary "native" libs
if not extdir.endswith(os.path.sep):
Expand All @@ -73,12 +95,13 @@ def build_extension(self, ext):

cmake_args = [
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}".format(extdir),
"-DCMAKE_RUNTIME_OUTPUT_DIRECTORY={}".format(bindir),
"-DPython_EXECUTABLE={}".format(sys.executable),
# Not used on MSVC, but no harm
"-DCMAKE_BUILD_TYPE={}".format(cfg),
"-DBUILD_SHARED_LIBS=OFF",
"-DOCIO_BUILD_DOCS=ON",
"-DOCIO_BUILD_APPS=OFF",
"-DBUILD_SHARED_LIBS=ON",
"-DOCIO_USE_SOVERSION=OFF",
"-DOCIO_BUILD_APPS=ON",
"-DOCIO_BUILD_TESTS=OFF",
"-DOCIO_BUILD_GPU_TESTS=OFF",
# Make sure we build everything for the requested architecture(s)
Expand Down Expand Up @@ -121,7 +144,8 @@ def build_extension(self, ext):
# Multi-config generators have a different way to specify configs
if not single_config:
cmake_args += [
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(cfg.upper(), extdir)
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(cfg.upper(), extdir),
"-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_{}={}".format(cfg.upper(), bindir),
]
build_args += ["--config", cfg]

Expand All @@ -131,6 +155,19 @@ def build_extension(self, ext):
if archs:
cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]

# When building the wheel, the install step is not executed so we need
# to have the correct RPATH directly from the build tree output.
cmake_args += ["-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON"]
if sys.platform.startswith("linux"):
cmake_args += ["-DCMAKE_INSTALL_RPATH={}".format("$ORIGIN;$ORIGIN/..")]
if sys.platform.startswith("darwin"):
cmake_args += ["-DCMAKE_INSTALL_RPATH={}".format("@loader_path;@loader_path/..")]

# Documentation is used for Python docstrings but we allow to build
# the wheel without docs to remove a hard dependency on doxygen.
if cmake_find_package("Doxygen"):
cmake_args += ["-DOCIO_BUILD_DOCS=ON"]

# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
# across all generators.
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
Expand All @@ -156,11 +193,33 @@ def build_extension(self, ext):
version=get_version(),
package_dir={
'PyOpenColorIO': 'src/bindings/python/package',
'PyOpenColorIO.tests': 'tests/python',
'PyOpenColorIO.data': 'tests/data',
'PyOpenColorIO.bin.pyocioamf': 'src/apps/pyocioamf',
'PyOpenColorIO.bin.pyociodisplay': 'src/apps/pyociodisplay',
},
packages=['PyOpenColorIO', 'PyOpenColorIO.tests', 'PyOpenColorIO.data'],
packages=[
'PyOpenColorIO',
'PyOpenColorIO.bin.pyocioamf',
'PyOpenColorIO.bin.pyociodisplay',
],
ext_modules=[CMakeExtension("PyOpenColorIO.PyOpenColorIO")],
cmdclass={"build_ext": CMakeBuild},
include_package_data=True
include_package_data=True,
entry_points={
'console_scripts': [
# Native applications
'ocioarchive=PyOpenColorIO.command_line:main',
'ociobakelut=PyOpenColorIO.command_line:main',
'ociocheck=PyOpenColorIO.command_line:main',
'ociochecklut=PyOpenColorIO.command_line:main',
'ocioconvert=PyOpenColorIO.command_line:main',
'ociodisplay=PyOpenColorIO.command_line:main',
'ociolutimage=PyOpenColorIO.command_line:main',
'ociomakeclf=PyOpenColorIO.command_line:main',
'ocioperf=PyOpenColorIO.command_line:main',
'ociowrite=PyOpenColorIO.command_line:main',
# Python applications
'pyocioamf=PyOpenColorIO.bin.pyocioamf.pyocioamf:main',
'pyociodisplay=PyOpenColorIO.bin.pyociodisplay.pyociodisplay:main',
]
},
)
23 changes: 23 additions & 0 deletions share/cmake/macros/StripUtils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright Contributors to the OpenColorIO Project.

# This function is based on Pybind11's pybind11_strip.

macro(ocio_strip_binary target_name)
string(TOUPPER "${CMAKE_BUILD_TYPE}" _uppercase_CMAKE_BUILD_TYPE)
if(NOT MSVC AND NOT "${_uppercase_CMAKE_BUILD_TYPE}" MATCHES DEBUG|RELWITHDEBINFO)
if(CMAKE_STRIP)
if(APPLE)
set(_strip_opt -x)
endif()

add_custom_command(
TARGET ${target_name}
POST_BUILD
COMMAND ${CMAKE_STRIP} ${_strip_opt} $<TARGET_FILE:${target_name}>
)
unset(_strip_opt)
endif()
endif()
unset(_uppercase_CMAKE_BUILD_TYPE)
endmacro()
2 changes: 1 addition & 1 deletion share/cmake/utils/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ endif()
###############################################################################
# Define RPATH.

if (UNIX AND NOT CMAKE_SKIP_RPATH)
if (UNIX AND NOT CMAKE_SKIP_RPATH AND NOT CMAKE_INSTALL_RPATH)
# With the 'usual' install path structure in mind, search from the bin directory
# (i.e. a binary loading a dynamic library) and then from the current directory
# (i.e. dynamic library loading another dynamic library).
Expand Down
9 changes: 7 additions & 2 deletions src/OpenColorIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,17 @@ elseif(APPLE)
endif()
endif()

if (OCIO_USE_SOVERSION)
set_target_properties(OpenColorIO PROPERTIES
VERSION ${OpenColorIO_VERSION}
SOVERSION ${SOVERSION}
)
endif()

set_target_properties(OpenColorIO PROPERTIES
OUTPUT_NAME ${PROJECT_NAME}${OCIO_LIBNAME_SUFFIX}
COMPILE_OPTIONS "${PLATFORM_COMPILE_OPTIONS}"
LINK_OPTIONS "${CUSTOM_LINK_FLAGS}"
VERSION ${OpenColorIO_VERSION}
SOVERSION ${SOVERSION}
PUBLIC_HEADER "${INSTALL_HEADERS}"
)

Expand Down
3 changes: 0 additions & 3 deletions src/OpenColorIO/ops/lut3d/Lut3DOpCPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,6 @@ void InvLut3DRenderer::apply(const void * inImg, void * outImg, long numPixels)
// For now, if no result is found, return 0.
float result[3] = { 0.f, 0.f, 0.f };

unsigned long cnt = 0;
long level = 0;
while (level >= 0)
{
Expand All @@ -1680,7 +1679,6 @@ void InvLut3DRenderer::apply(const void * inImg, void * outImg, long numPixels)
B <= levels[level].maxVals[node * chans + 2];
currentChild[level]++;
currentChildInd[level]++;
cnt++;

if (inRange)
{
Expand Down Expand Up @@ -1757,4 +1755,3 @@ ConstOpCPURcPtr GetLut3DRenderer(ConstLut3DOpDataRcPtr & lut)
}

} // namespace OCIO_NAMESPACE

3 changes: 3 additions & 0 deletions src/apps/ocioarchive/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ target_link_libraries(ocioarchive
MINIZIP::minizip-ng
)

include(StripUtils)
ocio_strip_binary(ocioarchive)

install(TARGETS ocioarchive
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
3 changes: 3 additions & 0 deletions src/apps/ociobakelut/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ target_link_libraries(ociobakelut
OpenColorIO
)

include(StripUtils)
ocio_strip_binary(ociobakelut)

install(TARGETS ociobakelut
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
3 changes: 3 additions & 0 deletions src/apps/ociocheck/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ target_link_libraries(ociocheck
OpenColorIO
)

include(StripUtils)
ocio_strip_binary(ociocheck)

install(TARGETS ociocheck
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
3 changes: 3 additions & 0 deletions src/apps/ociochecklut/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ target_link_libraries(ociochecklut
OpenColorIO
)

include(StripUtils)
ocio_strip_binary(ociochecklut)

install(TARGETS ociochecklut
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
3 changes: 3 additions & 0 deletions src/apps/ocioconvert/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ target_link_libraries(ocioconvert
OpenColorIO
)

include(StripUtils)
ocio_strip_binary(ocioconvert)

install(TARGETS ocioconvert
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
3 changes: 3 additions & 0 deletions src/apps/ociodisplay/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ target_link_libraries(ociodisplay
OpenColorIO
)

include(StripUtils)
ocio_strip_binary(ociodisplay)

install(TARGETS ociodisplay
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
3 changes: 3 additions & 0 deletions src/apps/ociolutimage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ target_link_libraries(ociolutimage
utils::strings
)

include(StripUtils)
ocio_strip_binary(ociolutimage)

install(TARGETS ociolutimage
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
3 changes: 3 additions & 0 deletions src/apps/ociomakeclf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ target_link_libraries(ociomakeclf
utils::strings
)

include(StripUtils)
ocio_strip_binary(ociomakeclf)

install(TARGETS ociomakeclf
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
3 changes: 3 additions & 0 deletions src/apps/ocioperf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ target_link_libraries(ocioperf
utils::strings
)

include(StripUtils)
ocio_strip_binary(ocioperf)

install(TARGETS ocioperf
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
3 changes: 3 additions & 0 deletions src/apps/ociowrite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ target_link_libraries(ociowrite
OpenColorIO
)

include(StripUtils)
ocio_strip_binary(ociowrite)

install(TARGETS ociowrite
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
Loading