Skip to content

Commit

Permalink
PyIlmBase finished refactor, misc cleanup
Browse files Browse the repository at this point in the history
- add extra dist to automake for make dist
- finish numpy lookup
- add sample vfx 15 toolchain file for doc purposes
- merge cxx standard, pay attention to global setting if set
- merge clang tidy option
- add default build type if not set

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
  • Loading branch information
kdt3rd committed Jul 17, 2019
1 parent 0833204 commit 4d97270
Show file tree
Hide file tree
Showing 19 changed files with 600 additions and 352 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
@@ -1,4 +1,5 @@
# "More Modern" CMake version

cmake_minimum_required(VERSION 3.12)

# Hint: This can be set to enable custom find_package
Expand Down Expand Up @@ -48,6 +49,8 @@ if(BUILD_TESTING)
enable_testing()
endif()

#######################################

# Include these two modules without enable/disable options
add_subdirectory(IlmBase)
add_subdirectory(OpenEXR)
Expand Down
4 changes: 2 additions & 2 deletions IlmBase/Half/CMakeLists.txt
@@ -1,10 +1,10 @@

add_executable(eLut eLut.cpp)
target_compile_features(eLut PUBLIC cxx_std_${ILMBASE_CXX_STANDARD})
target_compile_features(eLut PUBLIC cxx_std_${OPENEXR_CXX_STANDARD})


add_executable(toFloat toFloat.cpp)
target_compile_features(toFloat PUBLIC cxx_std_${ILMBASE_CXX_STANDARD})
target_compile_features(toFloat PUBLIC cxx_std_${OPENEXR_CXX_STANDARD})

add_custom_command(
OUTPUT
Expand Down
26 changes: 20 additions & 6 deletions IlmBase/config/IlmBaseSetup.cmake
Expand Up @@ -10,7 +10,12 @@ option(ILMBASE_ENABLE_LARGE_STACK "Enables code to take advantage of large stack

# What C++ standard to compile for
# VFX Platform 18 is c++14, so let's enable that by default
set(ILMBASE_CXX_STANDARD "14" CACHE STRING "C++ standard to compile against")
set(tmp 14)
if(CMAKE_CXX_STANDARD)
set(tmp ${CMAKE_CXX_STANDARD})
endif()
set(OPENEXR_CXX_STANDARD "${tmp}" CACHE STRING "C++ standard to compile against")
set(tmp)

# Namespace-related settings, allows one to customize the
# namespace generated, and to version the namespaces
Expand Down Expand Up @@ -94,16 +99,25 @@ endif()

########################

# set a default build type if not set
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

# Code check related features
option(ILMBASE_USE_CLANG_TIDY "Check if clang-tidy is available, and enable that" OFF)
if(ILMBASE_USE_CLANG_TIDY)
find_program(ILMBASE_CLANG_TIDY_BIN clang-tidy)
if(ILMBASE_CLANG_TIDY_BIN-NOTFOUND)
option(OPENEXR_USE_CLANG_TIDY "Check if clang-tidy is available, and enable that" OFF)
if(OPENEXR_USE_CLANG_TIDY)
find_program(OPENEXR_CLANG_TIDY_BIN clang-tidy)
if(OPENEXR_CLANG_TIDY_BIN-NOTFOUND)
message(FATAL_ERROR "clang-tidy processing requested, but no clang-tidy found")
endif()
# TODO: Need to define the list of valid checks and add a file with said list
set(CMAKE_CXX_CLANG_TIDY
${ILMBASE_CLANG_TIDY_BIN};
${OPENEXR_CLANG_TIDY_BIN};
-header-filter=.;
-checks=*;
)
Expand Down
2 changes: 1 addition & 1 deletion IlmBase/config/LibraryDefine.cmake
Expand Up @@ -8,7 +8,7 @@ function(ILMBASE_DEFINE_LIBRARY libname)

set(objlib ${libname}_Object)
add_library(${objlib} OBJECT ${ILMBASE_CURLIB_SOURCES})
target_compile_features(${objlib} PUBLIC cxx_std_${ILMBASE_CXX_STANDARD})
target_compile_features(${objlib} PUBLIC cxx_std_${OPENEXR_CXX_STANDARD})
if(ILMBASE_CURLIB_PRIV_EXPORT AND BUILD_SHARED_LIBS)
target_compile_definitions(${objlib} PRIVATE ${ILMBASE_CURLIB_PRIV_EXPORT})
if(WIN32)
Expand Down
5 changes: 4 additions & 1 deletion OpenEXR/config/Makefile.am
Expand Up @@ -4,4 +4,7 @@ configincludedir = $(includedir)/OpenEXR

nodist_configinclude_HEADERS = OpenEXRConfig.h

EXTRA_DIST = OpenEXRConfig.h.in
EXTRA_DIST = OpenEXRConfig.h.in OpenEXRConfig.h.in_cmake \
OpenEXRConfigInternal.h.in OpenEXRConfigInternal.h.in_cmake \
CMakeLists.txt OpenEXRSetup.cmake LibraryDefine.cmake \
ParseConfigure.cmake
16 changes: 15 additions & 1 deletion OpenEXR/config/OpenEXRSetup.cmake
Expand Up @@ -6,7 +6,12 @@ include(GNUInstallDirs)

# What C++ standard to compile for
# VFX Platform 18 is c++14, so let's enable that by default
set(OPENEXR_CXX_STANDARD "14" CACHE STRING "C++ standard to compile against")
set(tmp 14)
if(CMAKE_CXX_STANDARD)
set(tmp ${CMAKE_CXX_STANDARD})
endif()
set(OPENEXR_CXX_STANDARD "${tmp}" CACHE STRING "C++ standard to compile against")
set(tmp)

set(OPENEXR_NAMESPACE_CUSTOM "0" CACHE STRING "Whether the namespace has been customized (so external users know)")
set(OPENEXR_INTERNAL_IMF_NAMESPACE "Imf_${OPENEXR_VERSION_API}" CACHE STRING "Real namespace for Imath that will end up in compiled symbols")
Expand Down Expand Up @@ -88,6 +93,15 @@ endif()

########################

# set a default build type if not set
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

# Code check related features
option(OPENEXR_USE_CLANG_TIDY "Check if clang-tidy is available, and enable that" OFF)
if(OPENEXR_USE_CLANG_TIDY)
Expand Down
55 changes: 48 additions & 7 deletions PyIlmBase/CMakeLists.txt
Expand Up @@ -33,8 +33,8 @@ find_package(IlmBase ${OPENEXR_VERSION} EXACT REQUIRED CONFIG)
find_package(Python REQUIRED)

# now determine which (or both), and compile for both
find_package(Python2 COMPONENTS Interpreter Development)
find_package(Python3 COMPONENTS Interpreter Development)
find_package(Python2 COMPONENTS Interpreter Development NumPy)
find_package(Python3 COMPONENTS Interpreter Development NumPy)
if(TARGET Python2::Python AND TARGET Python3::Python)
message(NOTICE ": Found Python ${Python2_VERSION} and ${Python3_VERSION}")
elseif(TARGET Python2::Python)
Expand All @@ -60,8 +60,45 @@ if (TARGET Python3::Python)
set(PYILMBASE_BOOST_NUMPY3_COMPONENT "numpy${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}")
message(STATUS "Found Python3 libraries: ${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}")
endif()
# different flavors of O.S. have multiple versions of python
# some of them have both. Then for boost, some versions of boost
# have just a python component, some it's by major version (python2/python3)
# and still others have maj/min (python27)
# let's run a search and see what we get instead of making it
# an explicit required. The older names are not portable, but
# we'll do the best we can
find_package(Boost REQUIRED OPTIONAL_COMPONENTS
python
python2
${PYILMBASE_BOOST_PY2_COMPONENT}
python3
${PYILMBASE_BOOST_PY3_COMPONENT})
if(Boost_python_FOUND AND NOT(
Boost_python2_FOUND OR
Boost_${PYILMBASE_BOOST_PY2_COMPONENT}_FOUND OR
Boost_python3_FOUND OR
Boost_${PYILMBASE_BOOST_PY3_COMPONENT}_FOUND))
# old boost case, I guess we just warn and assume it is python2 (likely)
message(WARNING "Ambiguous boost python module found, assuming python 2")
set(PYILMBASE_BOOST_PY2_COMPONENT python)
set(PYILMBASE_BOOST_PY3_COMPONENT pythonIgnore)
else()
if(Boost_python2_FOUND AND NOT Boost_${PYILMBASE_BOOST_PY2_COMPONENT}_FOUND)
message(WARNING "Legacy Boost python2 found, but does not include minor version, this is an old configuration and may not be portable")
set(PYILMBASE_BOOST_PY2_COMPONENT python2)
endif()
if(Boost_python3_FOUND AND NOT Boost_${PYILMBASE_BOOST_PY3_COMPONENT}_FOUND)
message(WARNING "Legacy Boost python3 found, but does not include minor version, this is an old configuration and may not be portable")
set(PYILMBASE_BOOST_PY3_COMPONENT python3)
endif()
endif()

# unfortunately, we can't use the boost numpy stuff, as that requires a
# version of boost that is newer than is mandated by many active versions
# of the VFX reference platform (numpy became active in 1.63 of boost).
# rather than make this an "official" find package thing
include(config/NumPyLocate.cmake)

find_package(Boost REQUIRED COMPONENTS ${PYILMBASE_BOOST_PY2_COMPONENT} ${PYILMBASE_BOOST_NUMPY2_COMPONENT} ${PYILMBASE_BOOST_PY3_COMPONENT} ${PYILMBASE_BOOST_NUMPY3_COMPONENT})

# utility function for the repeated boilerplate of defining
# the libraries and/or python modules
Expand All @@ -71,8 +108,10 @@ include(config/ModuleDefine.cmake)
add_subdirectory(config)

add_subdirectory( PyIex )
#add_subdirectory( PyImath )
#add_subdirectory( PyImathNumpy )
add_subdirectory( PyImath )
if(TARGET Python2::IlmBaseNumPy OR TARGET Python3::IlmBaseNumPy)
add_subdirectory( PyImathNumpy )
endif()

##########################
# Tests
Expand All @@ -81,6 +120,8 @@ include(CTest)
if(BUILD_TESTING)
enable_testing()
add_subdirectory( PyIexTest )
# add_subdirectory( PyImathTest )
# add_subdirectory( PyImathNumpyTest )
add_subdirectory( PyImathTest )
if(TARGET Python2::IlmBaseNumPy OR TARGET Python3::IlmBaseNumPy)
add_subdirectory( PyImathNumpyTest )
endif()
endif()
2 changes: 1 addition & 1 deletion PyIlmBase/PyIexTest/CMakeLists.txt
Expand Up @@ -8,7 +8,7 @@ if(TARGET Python2::Interpreter)
)
endif()

if(TARGET Python2::Interpreter)
if(TARGET Python3::Interpreter)
add_test(PyIlmBase.PyIexTest_Python3
${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyIexTest.in
)
Expand Down
1 change: 1 addition & 0 deletions PyIlmBase/PyImath/CMakeLists.txt
Expand Up @@ -79,4 +79,5 @@ pyilmbase_define_module(imath
PyImathVecOperators.h
DEPENDENCIES
IlmBase::Iex IlmBase::IexMath IlmBase::Imath
MODULE_DEPS PyIex
)
71 changes: 41 additions & 30 deletions PyIlmBase/PyImathNumpy/CMakeLists.txt
@@ -1,36 +1,47 @@
if(TARGET Python2::Python AND
TARGET Boost::${PYILMBASE_BOOST_PY2_COMPONENT} AND
TARGET Python2::IlmBaseNumPy)

# must be shared
ADD_LIBRARY ( imathnumpymodule SHARED
imathnumpymodule.cpp
)
set(moddeps_p2 PyIex PyImath)
list(TRANSFORM moddeps_p2 APPEND ${PYILMBASE_LIB_PYTHONVER_ROOT}${Python2_VERSION_MAJOR}_${Python2_VERSION_MINOR})

IF (WIN32)
SET_TARGET_PROPERTIES (imathnumpymodule
PROPERTIES
PREFIX ""
OUTPUT_NAME "imathnumpy"
SUFFIX ".pyd"
)
ELSE ()
SET_TARGET_PROPERTIES (imathnumpymodule
PROPERTIES PREFIX "" SUFFIX ".so" BUILD_WITH_INSTALL_RPATH ON
Python2_add_library(imathnumpy_python2 MODULE
imathnumpymodule.cpp
)
target_link_libraries(imathnumpy_python2
PRIVATE
IlmBase::Iex IlmBase::IexMath IlmBase::Imath
${moddeps_p2}
Python2::Python
Boost::${PYILMBASE_BOOST_PY2_COMPONENT}
Python2::IlmBaseNumPy
)
ENDIF ()
set_target_properties(imathnumpy_python2 PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python${Python2_VERSION_MAJOR}_${Python2_VERSION_MINOR}/"
LIBRARY_OUTPUT_NAME "imathnumpy"
)
endif()

INCLUDE_DIRECTORIES (
${NUMPY_INCLUDE_DIRS}
)
SET_ILMBASE_INCLUDE_DIRS( imathnumpymodule )
if(TARGET Python3::Python AND
TARGET Boost::${PYILMBASE_BOOST_PY3_COMPONENT} AND
TARGET Python3::IlmBaseNumPy)

# IlmBase::Imath${OPENEXR_TARGET_SUFFIX}
# IlmBase::Iex${OPENEXR_TARGET_SUFFIX}
TARGET_LINK_LIBRARIES ( imathnumpymodule
PyImath
PyIex
${Boost_LIBRARIES}
)

INSTALL ( TARGETS imathnumpymodule
DESTINATION lib/python${OPENEXR_PYTHON_MAJOR}.${OPENEXR_PYTHON_MINOR}/site-packages
)
set(moddeps_p3 PyIex PyImath)
list(TRANSFORM moddeps_p3 APPEND ${PYILMBASE_LIB_PYTHONVER_ROOT}${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR})

Python3_add_library(imathnumpy_python3 MODULE
imathnumpymodule.cpp
)
target_link_libraries(imathnumpy_python3
PRIVATE
IlmBase::Iex IlmBase::IexMath IlmBase::Imath
${moddeps_p3}
Python3::Python
Boost::${PYILMBASE_BOOST_PY3_COMPONENT}
Python3::IlmBaseNumPy
)
set_target_properties(imathnumpy_python3 PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR}/"
LIBRARY_OUTPUT_NAME "imathnumpy"
)
endif()
1 change: 1 addition & 0 deletions PyIlmBase/PyImathNumpy/imathnumpymodule.cpp
Expand Up @@ -38,6 +38,7 @@
#include <PyImathVec.h>
#include <iostream>
#include <boost/format.hpp>
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include <numpy/arrayobject.h>

using namespace boost::python;
Expand Down
21 changes: 17 additions & 4 deletions PyIlmBase/PyImathNumpyTest/CMakeLists.txt
@@ -1,5 +1,18 @@
ADD_TEST ( PyImathNumpyTest
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyImathNumpyTest.in -nocuda
)

SET_TESTS_PROPERTIES ( PyImathNumpyTest PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/../PyIex:${CMAKE_CURRENT_BINARY_DIR}/../PyImath:${CMAKE_CURRENT_BINARY_DIR}/../PyImathNumpy;LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../IlmBase/Iex:${CMAKE_CURRENT_BINARY_DIR}/../../IlmBase/IexMath:${CMAKE_CURRENT_BINARY_DIR}/../../IlmBase/Imath:${CMAKE_CURRENT_BINARY_DIR}/../PyIex:${CMAKE_CURRENT_BINARY_DIR}/../PyImath:${CMAKE_CURRENT_BINARY_DIR}/../PyImathNumpy" )
if(TARGET Python2::Interpreter)
add_test(PyIlmBase.PyImathNumpyTest_Python2
${Python2_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyImathNumpyTest.in
)
set_tests_properties(PyIlmBase.PyImathNumpyTest_Python2 PROPERTIES
ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/python${Python2_VERSION_MAJOR}_${Python2_VERSION_MINOR}"
)
endif()

if(TARGET Python3::Interpreter)
add_test(PyIlmBase.PyImathNumpyTest_Python3
${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyImathNumpyTest.in
)
set_tests_properties(PyIlmBase.PyImathNumpyTest_Python3 PROPERTIES
ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/python${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR}"
)
endif()
21 changes: 17 additions & 4 deletions PyIlmBase/PyImathTest/CMakeLists.txt
@@ -1,5 +1,18 @@
ADD_TEST ( PyImathTest
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyImathTest.in
)
if(TARGET Python2::Interpreter)
add_test(PyIlmBase.PyImathTest_Python2
${Python2_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyImathTest.in
)
set_tests_properties(PyIlmBase.PyImathTest_Python2 PROPERTIES
ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/python${Python2_VERSION_MAJOR}_${Python2_VERSION_MINOR}"
)
endif()

SET_TESTS_PROPERTIES ( PyImathTest PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/../PyIex:${CMAKE_CURRENT_BINARY_DIR}/../PyImath;LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../IlmBase/Iex:${CMAKE_CURRENT_BINARY_DIR}/../../IlmBase/IexMath:${CMAKE_CURRENT_BINARY_DIR}/../../IlmBase/Imath:${CMAKE_CURRENT_BINARY_DIR}/../PyIex:${CMAKE_CURRENT_BINARY_DIR}/../PyImath" )
if(TARGET Python3::Interpreter)
add_test(PyIlmBase.PyImathTest_Python3
${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyImathTest.in
)
set_tests_properties(PyIlmBase.PyImathTest_Python3 PROPERTIES
ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/python${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR}"
WILL_FAIL TRUE ###### TODO: Fix this once we officially support VFX platform 20 (currently broken)
)
endif()

0 comments on commit 4d97270

Please sign in to comment.