Skip to content

Commit

Permalink
Fix issues with rpath, message cleanup, checkpoint better python layer
Browse files Browse the repository at this point in the history
Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
  • Loading branch information
kdt3rd committed Jul 17, 2019
1 parent c236ed8 commit 0eff972
Show file tree
Hide file tree
Showing 18 changed files with 455 additions and 199 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ missing
.DS_Store
*.project
*.cproject
build/
build-win/
build-nuget/
*~
4 changes: 2 additions & 2 deletions IlmBase/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ install(
install(TARGETS IlmBaseConfig EXPORT ${PROJECT_NAME})
add_library(IlmBase::Config ALIAS IlmBaseConfig)

cmake_dependent_option(INSTALL_PKG_CONFIG "Install IlmBase.pc file" ON "WIN32" OFF)
if(INSTALL_PKG_CONFIG)
cmake_dependent_option(ILMBASE_INSTALL_PKG_CONFIG "Install IlmBase.pc file" ON "WIN32" OFF)
if(ILMBASE_INSTALL_PKG_CONFIG)
# use a helper function to avoid variable pollution, but pretty simple
function(ilmbase_pkg_config_help pcinfile)
set(prefix ${CMAKE_INSTALL_PREFIX})
Expand Down
21 changes: 19 additions & 2 deletions IlmBase/config/IlmBaseSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,29 @@ set(ILMBASE_LIB_SUFFIX "-${ILMBASE_VERSION_API}" CACHE STRING "string added to t
# would use -lImath_static (or target_link_libraries(xxx IlmBase::Imath_static))
set(ILMBASE_STATIC_LIB_SUFFIX "_static" CACHE STRING "When building both static and shared, name to append to static library (in addition to normal suffix)")

# rpath related setup - if the user sets an install rpath
# rpath related setup
# make sure we force an rpath to the rpath we're compiling
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# adds the automatically determined parts of the rpath
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# if the user sets an install rpath
# then just use that, or otherwise set one for them
if(NOT CMAKE_INSTALL_RPATH)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
if("${CMAKE_SYSTEM}" MATCHES "Linux")
get_filename_component(tmpSysPath "${CMAKE_INSTALL_FULL_LIBDIR}" NAME)
if(NOT tmpSysPath)
set(tmpSysPath "lib")
endif()
set(CMAKE_INSTALL_RPATH "\\\$ORIGIN/../${tmpSysPath}:${CMAKE_INSTALL_FULL_LIBDIR}")
elseif(APPLE)
set(CMAKE_INSTALL_RPATH "@rpath:${CMAKE_INSTALL_FULL_LIBDIR}")
else()
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
endif()
endif()
set(isSystemDir)
endif()
Expand Down
9 changes: 5 additions & 4 deletions IlmBase/config/LibraryDefine.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ function(ILMBASE_DEFINE_LIBRARY libname)
if(ILMBASE_CURLIB_PRIVATE_DEPS)
target_link_libraries(${objlib} PRIVATE ${ILMBASE_CURLIB_PRIVATE_DEPS})
endif()
set_property(TARGET ${objlib} PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET ${objlib} PROPERTY CXX_EXTENSIONS OFF)
set_property(TARGET ${objlib} PROPERTY POSITION_INDEPENDENT_CODE ON)

set_target_properties(${objlib} PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
)
set_property(TARGET ${objlib} PROPERTY PUBLIC_HEADER ${ILMBASE_CURLIB_HEADERS})

install(TARGETS ${objlib}
Expand Down
2 changes: 1 addition & 1 deletion IlmBase/config/ParseConfigure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ string(REGEX MATCH "LIBTOOL_AGE=([0-9]+)" DUMMY ${CONFIGURE_AC_CONTENTS})
set(ILMBASE_SOAGE ${CMAKE_MATCH_1})
math(EXPR ILMBASE_SOVERSION "${ILMBASE_SOCURRENT} - ${ILMBASE_SOAGE}")
set(ILMBASE_LIB_VERSION "${ILMBASE_SOVERSION}.${ILMBASE_SOAGE}.${ILMBASE_SOREVISION}")
message(NOTICE ": Configure ILMBASE Version: ${ILMBASE_VERSION} Lib API: ${ILMBASE_LIB_VERSION}")
message(STATUS "Configure ILMBASE Version: ${ILMBASE_VERSION} Lib API: ${ILMBASE_LIB_VERSION}")
unset(CONFIGURE_AC_CONTENTS)
4 changes: 2 additions & 2 deletions OpenEXR/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ install(
install(TARGETS IlmImfConfig EXPORT ${PROJECT_NAME})
add_library(${PROJECT_NAME}::Config ALIAS IlmImfConfig)

option(INSTALL_PKG_CONFIG "Install OpenEXR.pc file" ON)
if(INSTALL_PKG_CONFIG)
option(OPENEXR_INSTALL_PKG_CONFIG "Install OpenEXR.pc file" ON)
if(OPENEXR_INSTALL_PKG_CONFIG)
# use a helper function to avoid variable pollution, but pretty simple
function(openexr_pkg_config_help pcinfile)
set(prefix ${CMAKE_INSTALL_PREFIX})
Expand Down
9 changes: 5 additions & 4 deletions OpenEXR/config/LibraryDefine.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ function(OPENEXR_DEFINE_LIBRARY libname)
if(OPENEXR_CURLIB_PRIVATE_DEPS)
target_link_libraries(${objlib} PRIVATE ${OPENEXR_CURLIB_PRIVATE_DEPS})
endif()
set_property(TARGET ${objlib} PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET ${objlib} PROPERTY CXX_EXTENSIONS OFF)
set_property(TARGET ${objlib} PROPERTY POSITION_INDEPENDENT_CODE ON)

set_target_properties(${objlib} PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
)
set_property(TARGET ${objlib} PROPERTY PUBLIC_HEADER ${OPENEXR_CURLIB_HEADERS})

install(TARGETS ${objlib}
Expand Down
21 changes: 19 additions & 2 deletions OpenEXR/config/OpenEXRSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,29 @@ set(OPENEXR_LIB_SUFFIX "-${OPENEXR_VERSION_API}" CACHE STRING "string added to t
# would use -lImath_static (or target_link_libraries(xxx IlmBase::Imath_static))
set(OPENEXR_STATIC_LIB_SUFFIX "_static" CACHE STRING "When building both static and shared, name to append to static library (in addition to normal suffix)")

# rpath related setup - if the user sets an install rpath
# rpath related setup
# make sure we force an rpath to the rpath we're compiling
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# adds the automatically determined parts of the rpath
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# if the user sets an install rpath
# then just use that, or otherwise set one for them
if(NOT CMAKE_INSTALL_RPATH)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
if("${CMAKE_SYSTEM}" MATCHES "Linux")
get_filename_component(tmpSysPath "${CMAKE_INSTALL_FULL_LIBDIR}" NAME)
if(NOT tmpSysPath)
set(tmpSysPath "lib")
endif()
set(CMAKE_INSTALL_RPATH "\\\$ORIGIN/../${tmpSysPath}:${CMAKE_INSTALL_FULL_LIBDIR}")
elseif(APPLE)
set(CMAKE_INSTALL_RPATH "@rpath:${CMAKE_INSTALL_FULL_LIBDIR}")
else()
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
endif()
endif()
set(isSystemDir)
endif()
Expand Down
2 changes: 1 addition & 1 deletion OpenEXR/config/ParseConfigure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ string(REGEX MATCH "LIBTOOL_AGE=([0-9]+)" DUMMY ${CONFIGURE_AC_CONTENTS})
set(OPENEXR_SOAGE ${CMAKE_MATCH_1})
math(EXPR OPENEXR_SOVERSION "${OPENEXR_SOCURRENT} - ${OPENEXR_SOAGE}")
set(OPENEXR_LIB_VERSION "${OPENEXR_SOVERSION}.${OPENEXR_SOAGE}.${OPENEXR_SOREVISION}")
message(NOTICE ": Configure OpenEXR Version: ${OPENEXR_VERSION} Lib API: ${OPENEXR_LIB_VERSION}")
message(STATUS "Configure OpenEXR Version: ${OPENEXR_VERSION} Lib API: ${OPENEXR_LIB_VERSION}")
unset(CONFIGURE_AC_CONTENTS)
39 changes: 25 additions & 14 deletions PyIlmBase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ include(config/PyIlmBaseSetup.cmake)
find_package(IlmBase ${OPENEXR_VERSION} EXACT REQUIRED CONFIG)

# we are building a python extension, so of course we depend on
# python as well. Excepth we don't know which version...
# python as well. Except we don't know which version...
# cmake 3.14 can also search for numpy, but we only depend on 3.12
# in the rest of OpenEXR right now...
#find_package(Python2 COMPONENTS Development NumPy)

# first make sure we find *some* python
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)
if(TARGET Python2::Python AND TARGET Python3::Python)
Expand All @@ -46,18 +50,25 @@ endif()
# Boost Python has some .. annoyances in that the python module
# has version names attached to it
if (TARGET Python2::Python)
set(PYILMBASE_BOOST_PY2_COMPONENT "python${Python2_VERSION_MAJOR}${Python2_VERSION_MINOR}")
set(PYILMBASE_BOOST_NUMPY2_COMPONENT "numpy${Python2_VERSION_MAJOR}${Python2_VERSION_MINOR}")
message(": Python2 site lib: ${Python2_SITELIB}")
set(PYILMBASE_BOOST_PY2_COMPONENT "python${Python2_VERSION_MAJOR}${Python2_VERSION_MINOR}")
set(PYILMBASE_BOOST_NUMPY2_COMPONENT "numpy${Python2_VERSION_MAJOR}${Python2_VERSION_MINOR}")
message(STATUS "Found Python2 libraries: ${Python2_VERSION_MAJOR}${Python2_VERSION_MINOR}")
# ${Python2_SITELIB}
endif()
if (TARGET Python3::Python)
set(PYILMBASE_BOOST_PY3_COMPONENT "python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}")
set(PYILMBASE_BOOST_NUMPY3_COMPONENT "numpy${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}")
message(": Python3 site lib: ${Python3_SITELIB}")
set(PYILMBASE_BOOST_PY3_COMPONENT "python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}")
set(PYILMBASE_BOOST_NUMPY3_COMPONENT "numpy${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}")
message(STATUS "Found Python3 libraries: ${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}")
endif()

find_package(Boost COMPONENTS ${PYILMBASE_BOOST_PY2_COMPONENT} ${PYILMBASE_BOOST_NUMPY2_COMPONENT} ${PYILMBASE_BOOST_PY3_COMPONENT} ${PYILMBASE_BOOST_NUMPY3_COMPONENT})
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
include(config/ModuleDefine.cmake)

##########################
add_subdirectory(config)

add_subdirectory( PyIex )
#add_subdirectory( PyImath )
Expand All @@ -66,10 +77,10 @@ add_subdirectory( PyIex )
##########################
# Tests
##########################
#include(CTest)
#if(BUILD_TESTING)
# enable_testing()
# add_subdirectory( PyIexTest )
include(CTest)
if(BUILD_TESTING)
enable_testing()
add_subdirectory( PyIexTest )
# add_subdirectory( PyImathTest )
# add_subdirectory( PyImathNumpyTest )
#endif()
endif()
91 changes: 12 additions & 79 deletions PyIlmBase/PyIex/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,82 +1,15 @@

# can't re-use compile, so no sense for object library here...

if(TARGET Python2::Python AND TARGET Boost::${PYILMBASE_BOOST_PY2_COMPONENT})
Python2_add_library(iexmodule_p2 MODULE PyIex.cpp iexmodule.cpp)
target_link_libraries(iexmodule_p2
PRIVATE IlmBase::Iex IlmBase::IexMath
PRIVATE Boost::${PYILMBASE_BOOST_PY2_COMPONENT})
endif()

if(TARGET Python3::Python AND TARGET Boost::${PYILMBASE_BOOST_PY3_COMPONENT})
Python3_add_library(iexmodule_p3 MODULE PyIex.cpp iexmodule.cpp)
target_link_libraries(iexmodule_p3
PRIVATE IlmBase::Iex IlmBase::IexMath
PRIVATE Boost::${PYILMBASE_BOOST_PY3_COMPONENT})
endif()

#[==[
ADD_LIBRARY ( PyIex ${LIB_TYPE} PyIex.cpp)

target_compile_definitions( PyIex PRIVATE PYIEX_BUILD )

IF (WIN32)
target_compile_definitions( PyIex
PRIVATE OPENEXR_DLL)
ENDIF()

SET_ILMBASE_INCLUDE_DIRS( PyIex )

TARGET_LINK_LIBRARIES ( PyIex
PUBLIC IlmBase::Iex${OPENEXR_TARGET_SUFFIX}
PRIVATE ${PYTHON_LIBRARIES}
PRIVATE ${Boost_LIBRARIES}
)

INSTALL ( TARGETS PyIex
DESTINATION
lib
)

INSTALL (
FILES
pyilmbase_define_module(iex
LIBNAME PyIex
PRIV_EXPORT PYIEX_BUILD
CURDIR ${CMAKE_CURRENT_SOURCE_DIR}
LIBSOURCE
PyIex.cpp
MODSOURCE
iexmodule.cpp
HEADERS
PyIex.h
PyIexExport.h
PyIexTypeTranslator.h

DESTINATION
include/OpenEXR
)

# must be shared
ADD_LIBRARY ( iexmodule SHARED
iexmodule.cpp
)

if (WIN32)
SET_TARGET_PROPERTIES ( iexmodule
PROPERTIES
PREFIX ""
OUTPUT_NAME "iex"
SUFFIX ".pyd"
)
else()
SET_TARGET_PROPERTIES ( iexmodule
PROPERTIES PREFIX "" SUFFIX ".so" BUILD_WITH_INSTALL_RPATH ON
)
endif()

# IlmBase::Iex${OPENEXR_TARGET_SUFFIX}
TARGET_LINK_LIBRARIES ( iexmodule
PyIex
${PYTHON_LIBRARIES}
${Boost_LIBRARIES}
)

SET_ILMBASE_INCLUDE_DIRS( iexmodule )

INSTALL ( TARGETS iexmodule
DESTINATION lib/python${OPENEXR_PYTHON_MAJOR}.${OPENEXR_PYTHON_MINOR}/site-packages
)

#]==]
DEPENDENCIES
IlmBase::Iex IlmBase::IexMath
)
21 changes: 17 additions & 4 deletions PyIlmBase/PyIexTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
ADD_TEST ( PyIexTest
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyIexTest.in
)

SET_TESTS_PROPERTIES ( PyIexTest PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/../PyIex;LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../IlmBase/Iex:${CMAKE_CURRENT_BINARY_DIR}/../PyIex" )
if(TARGET Python2::Interpreter)
add_test(PyIlmBase.PyIexTest_Python2
${Python2_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyIexTest.in
)
set_tests_properties(PyIlmBase.PyIexTest_Python2 PROPERTIES
ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/python${Python2_VERSION_MAJOR}_${Python2_VERSION_MINOR}"
)
endif()

if(TARGET Python2::Interpreter)
add_test(PyIlmBase.PyIexTest_Python3
${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyIexTest.in
)
set_tests_properties(PyIlmBase.PyIexTest_Python3 PROPERTIES
ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/python${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR}"
)
endif()
Loading

0 comments on commit 0eff972

Please sign in to comment.