From 0eff97241f495027021b54978028475f0b2459dd Mon Sep 17 00:00:00 2001 From: Kimball Thurston Date: Wed, 17 Jul 2019 00:15:45 +1200 Subject: [PATCH] Fix issues with rpath, message cleanup, checkpoint better python layer Signed-off-by: Kimball Thurston --- .gitignore | 1 + IlmBase/config/CMakeLists.txt | 4 +- IlmBase/config/IlmBaseSetup.cmake | 21 +++- IlmBase/config/LibraryDefine.cmake | 9 +- IlmBase/config/ParseConfigure.cmake | 2 +- OpenEXR/config/CMakeLists.txt | 4 +- OpenEXR/config/LibraryDefine.cmake | 9 +- OpenEXR/config/OpenEXRSetup.cmake | 21 +++- OpenEXR/config/ParseConfigure.cmake | 2 +- PyIlmBase/CMakeLists.txt | 39 ++++--- PyIlmBase/PyIex/CMakeLists.txt | 91 ++------------- PyIlmBase/PyIexTest/CMakeLists.txt | 21 +++- PyIlmBase/PyIexTest/pyIexTest.in | 36 +++--- PyIlmBase/PyImath/CMakeLists.txt | 115 ++++++++----------- PyIlmBase/config/CMakeLists.txt | 23 ++++ PyIlmBase/config/ModuleDefine.cmake | 156 ++++++++++++++++++++++++++ PyIlmBase/config/ParseConfigure.cmake | 18 +++ PyIlmBase/config/PyIlmBaseSetup.cmake | 82 ++++++++++++++ 18 files changed, 455 insertions(+), 199 deletions(-) create mode 100644 PyIlmBase/config/CMakeLists.txt create mode 100644 PyIlmBase/config/ModuleDefine.cmake create mode 100644 PyIlmBase/config/ParseConfigure.cmake create mode 100644 PyIlmBase/config/PyIlmBaseSetup.cmake diff --git a/.gitignore b/.gitignore index a9c8e94770..b483fa49e2 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ missing .DS_Store *.project *.cproject +build/ build-win/ build-nuget/ *~ diff --git a/IlmBase/config/CMakeLists.txt b/IlmBase/config/CMakeLists.txt index 0e59653292..dd2b6ad157 100644 --- a/IlmBase/config/CMakeLists.txt +++ b/IlmBase/config/CMakeLists.txt @@ -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}) diff --git a/IlmBase/config/IlmBaseSetup.cmake b/IlmBase/config/IlmBaseSetup.cmake index d9bdfe2c89..f0fbbb1ccb 100644 --- a/IlmBase/config/IlmBaseSetup.cmake +++ b/IlmBase/config/IlmBaseSetup.cmake @@ -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() diff --git a/IlmBase/config/LibraryDefine.cmake b/IlmBase/config/LibraryDefine.cmake index c256aaf432..034da3c698 100644 --- a/IlmBase/config/LibraryDefine.cmake +++ b/IlmBase/config/LibraryDefine.cmake @@ -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} diff --git a/IlmBase/config/ParseConfigure.cmake b/IlmBase/config/ParseConfigure.cmake index e903768787..6ffae357e9 100644 --- a/IlmBase/config/ParseConfigure.cmake +++ b/IlmBase/config/ParseConfigure.cmake @@ -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) diff --git a/OpenEXR/config/CMakeLists.txt b/OpenEXR/config/CMakeLists.txt index 0652f795a1..12382102c4 100644 --- a/OpenEXR/config/CMakeLists.txt +++ b/OpenEXR/config/CMakeLists.txt @@ -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}) diff --git a/OpenEXR/config/LibraryDefine.cmake b/OpenEXR/config/LibraryDefine.cmake index ad31ca304f..f19218fa4d 100644 --- a/OpenEXR/config/LibraryDefine.cmake +++ b/OpenEXR/config/LibraryDefine.cmake @@ -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} diff --git a/OpenEXR/config/OpenEXRSetup.cmake b/OpenEXR/config/OpenEXRSetup.cmake index 7505007415..dfdc2f6cfa 100644 --- a/OpenEXR/config/OpenEXRSetup.cmake +++ b/OpenEXR/config/OpenEXRSetup.cmake @@ -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() diff --git a/OpenEXR/config/ParseConfigure.cmake b/OpenEXR/config/ParseConfigure.cmake index b4c6ebd07e..9623db428b 100644 --- a/OpenEXR/config/ParseConfigure.cmake +++ b/OpenEXR/config/ParseConfigure.cmake @@ -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) diff --git a/PyIlmBase/CMakeLists.txt b/PyIlmBase/CMakeLists.txt index a6d5b2f4f0..92d3b6607f 100644 --- a/PyIlmBase/CMakeLists.txt +++ b/PyIlmBase/CMakeLists.txt @@ -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) @@ -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 ) @@ -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() diff --git a/PyIlmBase/PyIex/CMakeLists.txt b/PyIlmBase/PyIex/CMakeLists.txt index 44fe95336b..fd97241370 100644 --- a/PyIlmBase/PyIex/CMakeLists.txt +++ b/PyIlmBase/PyIex/CMakeLists.txt @@ -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 + ) diff --git a/PyIlmBase/PyIexTest/CMakeLists.txt b/PyIlmBase/PyIexTest/CMakeLists.txt index 9ccbe1331c..bf6fdf19ed 100644 --- a/PyIlmBase/PyIexTest/CMakeLists.txt +++ b/PyIlmBase/PyIexTest/CMakeLists.txt @@ -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() diff --git a/PyIlmBase/PyIexTest/pyIexTest.in b/PyIlmBase/PyIexTest/pyIexTest.in index 5ce2b3152e..f96b73ce6d 100755 --- a/PyIlmBase/PyIexTest/pyIexTest.in +++ b/PyIlmBase/PyIexTest/pyIexTest.in @@ -2,16 +2,16 @@ import iex -print "" -print "testing exception inheritance" +print ("") +print ("testing exception inheritance") e = iex.BaseExc('test') assert(isinstance(e,iex.BaseExc)) assert(isinstance(e,RuntimeError)) del e -print "ok" -print "" +print ("ok") +print ("") -print "testing C++ to Python exception translation" +print ("testing C++ to Python exception translation") #----------------------------------------------------------------------------- # Test if the exception class hierarchy works @@ -19,7 +19,7 @@ print "testing C++ to Python exception translation" try: raise iex.BaseExc('test') -except iex.BaseExc, e: +except iex.BaseExc as e: pass except: assert 0 @@ -100,16 +100,16 @@ except: else: assert 0 -print "ok" -print "" +print ("ok") +print ("") -print 'testing exception raising' +print ('testing exception raising') try: raise iex.BaseExc('new BaseExc from python') -except iex.ArgExc, e: +except iex.ArgExc as e: traceback.print_exc() assert False -except iex.BaseExc, e: +except iex.BaseExc as e: pass except: traceback.print_exc() @@ -119,9 +119,9 @@ else: try: raise iex.ArgExc('new ArgExc from python') -except iex.ArgExc, e: +except iex.ArgExc as e: pass -except iex.BaseExc, e: +except iex.BaseExc as e: traceback.print_exc() assert False except: @@ -130,10 +130,10 @@ except: else: assert False -print "ok" -print "" +print ("ok") +print ("") -print 'testing exception conversion' +print ('testing exception conversion') be = iex.testMakeBaseExc('testStr') assert (isinstance(be,iex.BaseExc)) assert (be.__class__ == iex.BaseExc) @@ -145,5 +145,5 @@ assert (iex.testBaseExcString(be) == 'testStr') assert (iex.testBaseExcString(ae) == 'testStr') assert (iex.testArgExcString(ae) == 'testStr') -print "ok" -print "" +print ("ok") +print ("") diff --git a/PyIlmBase/PyImath/CMakeLists.txt b/PyIlmBase/PyImath/CMakeLists.txt index 3f4e67fbe1..f69c3413c8 100644 --- a/PyIlmBase/PyImath/CMakeLists.txt +++ b/PyIlmBase/PyImath/CMakeLists.txt @@ -1,5 +1,8 @@ - -ADD_LIBRARY ( PyImath ${LIB_TYPE} +pyilmbase_define_module(imath + LIBNAME PyImath + PRIV_EXPORT PYIMATH_BUILD + CURDIR ${CMAKE_CURRENT_SOURCE_DIR} + LIBSOURCE PyImath.cpp PyImathAutovectorize.cpp PyImathBox2Array.cpp @@ -30,70 +33,50 @@ ADD_LIBRARY ( PyImath ${LIB_TYPE} PyImathVec4fd.cpp PyImathVec4siArray.cpp PyImathVec4si.cpp -) - -target_compile_definitions( PyImath PRIVATE -DPYIMATH_BUILD ) - -IF (WIN32) - target_compile_definitions( PyImath - PRIVATE OPENEXR_DLL) -ENDIF() - - - -SET_ILMBASE_INCLUDE_DIRS( PyImath ) - -# IlmBase::Iex${OPENEXR_TARGET_SUFFIX} -TARGET_LINK_LIBRARIES ( PyImath - IlmBase::IexMath${OPENEXR_TARGET_SUFFIX} - IlmBase::Imath${OPENEXR_TARGET_SUFFIX} - PyIex - ${Boost_LIBRARIES} - ${PYTHON_LIBRARIES} -) - -INSTALL ( TARGETS PyImath - DESTINATION - lib -) - -INSTALL (DIRECTORY ./ - DESTINATION include/OpenEXR - FILES_MATCHING PATTERN "*.h" -) - -# must be shared -ADD_LIBRARY ( imathmodule SHARED + MODSOURCE imathmodule.cpp PyImathFun.cpp PyImathBasicTypes.cpp -) - -IF (WIN32) - SET_TARGET_PROPERTIES ( imathmodule - PROPERTIES - PREFIX "" - OUTPUT_NAME "imath" - SUFFIX ".pyd" - ) -ELSE () - SET_TARGET_PROPERTIES ( imathmodule - PROPERTIES PREFIX "" SUFFIX ".so" BUILD_WITH_INSTALL_RPATH ON - ) -ENDIF () - -SET_ILMBASE_INCLUDE_DIRS( imathmodule ) - -# IlmBase::Imath${OPENEXR_TARGET_SUFFIX} -# IlmBase::Iex${OPENEXR_TARGET_SUFFIX} -TARGET_LINK_LIBRARIES ( imathmodule - PyImath - PyIex - ${Boost_LIBRARIES} - ${PYTHON_LIBRARIES} -) - -INSTALL ( TARGETS imathmodule - DESTINATION lib/python${OPENEXR_PYTHON_MAJOR}.${OPENEXR_PYTHON_MINOR}/site-packages -) - + HEADERS + PyImath.h + PyImathAutovectorize.h + PyImathBasicTypes.h + PyImathBox.h + PyImathBoxArrayImpl.h + PyImathColor.h + PyImathColor3ArrayImpl.h + PyImathColor4Array2DImpl.h + PyImathColor4ArrayImpl.h + PyImathDecorators.h + PyImathEuler.h + PyImathExport.h + PyImathFixedArray.h + PyImathFixedArray2D.h + PyImathFixedMatrix.h + PyImathFixedVArray.h + PyImathFrustum.h + PyImathFun.h + PyImathLine.h + PyImathM44Array.h + PyImathMathExc.h + PyImathMatrix.h + PyImathOperators.h + PyImathPlane.h + PyImathQuat.h + PyImathRandom.h + PyImathShear.h + PyImathStringArray.h + PyImathStringArrayRegister.h + PyImathStringTable.h + PyImathTask.h + PyImathUtil.h + PyImathVec.h + PyImathVec2Impl.h + PyImathVec3ArrayImpl.h + PyImathVec3Impl.h + PyImathVec4ArrayImpl.h + PyImathVec4Impl.h + PyImathVecOperators.h + DEPENDENCIES + IlmBase::Iex IlmBase::IexMath IlmBase::Imath + ) diff --git a/PyIlmBase/config/CMakeLists.txt b/PyIlmBase/config/CMakeLists.txt new file mode 100644 index 0000000000..0b306a5c79 --- /dev/null +++ b/PyIlmBase/config/CMakeLists.txt @@ -0,0 +1,23 @@ + +### The autoconf setup for this folder generates a PyIlmBaseConfig.h file +### but no source actually uses that, so let's elide that for now + +# The main export of the configuration - This is the +# moral equivalent of a pkg-config file for cmake +# and replaces the Find*.cmake of the "old" cmake +if(PYILMBASE_BUILD_SUPPORT_LIBRARIES) + include(CMakePackageConfigHelpers) + write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${PYILMBASE_VERSION} + COMPATIBILITY SameMajorVersion + ) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + ) + install(EXPORT ${PROJECT_NAME} + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + FILE ${PROJECT_NAME}Config.cmake + NAMESPACE ${PROJECT_NAME}:: + EXPORT_LINK_INTERFACE_LIBRARIES + ) +endif() diff --git a/PyIlmBase/config/ModuleDefine.cmake b/PyIlmBase/config/ModuleDefine.cmake new file mode 100644 index 0000000000..884524e0b9 --- /dev/null +++ b/PyIlmBase/config/ModuleDefine.cmake @@ -0,0 +1,156 @@ + +function(PYILMBASE_ADD_LIBRARY_PRIV libname) + set(options) + set(oneValueArgs PRIV_EXPORT CURDIR CURBINDIR OUTROOT) + set(multiValueArgs SOURCE HEADERS DEPENDENCIES PRIVATE_DEPS) + cmake_parse_arguments(PYILMBASE_CURLIB "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + set(objlib ${libname}_Object) + add_library(${objlib} OBJECT ${PYILMBASE_CURLIB_SOURCE}) + target_compile_features(${objlib} PUBLIC cxx_std_${PYILMBASE_CXX_STANDARD}) + if(PYILMBASE_CURLIB_PRIV_EXPORT AND BUILD_SHARED_LIBS) + target_compile_definitions(${objlib} PRIVATE ${PYILMBASE_CURLIB_PRIV_EXPORT}) + if(WIN32) + target_compile_definitions(${objlib} PUBLIC OPENEXR_DLL) + endif() + endif() + if(PYILMBASE_CURLIB_CURDIR) + target_include_directories(${objlib} INTERFACE $) + endif() + if(PYILMBASE_CURLIB_CURBINDIR) + target_include_directories(${objlib} PRIVATE $) + endif() + target_link_libraries(${objlib} PUBLIC ${PYILMBASE_CURLIB_DEPENDENCIES}) + if(PYILMBASE_CURLIB_PRIVATE_DEPS) + target_link_libraries(${objlib} PRIVATE ${PYILMBASE_CURLIB_PRIVATE_DEPS}) + endif() + set_target_properties(${objlib} PROPERTIES + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + POSITION_INDEPENDENT_CODE ON + ) + set_property(TARGET ${objlib} PROPERTY PUBLIC_HEADER ${PYILMBASE_CURLIB_HEADERS}) + + install(TARGETS ${objlib} + EXPORT ${PROJECT_NAME} + PUBLIC_HEADER + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PYILMBASE_OUTPUT_SUBDIR} + ) + + # let the default behaviour BUILD_SHARED_LIBS control the + # disposition of the default library... + add_library(${libname} $) + target_link_libraries(${libname} PUBLIC ${objlib}) + if(BUILD_SHARED_LIBS) + set_target_properties(${libname} PROPERTIES + SOVERSION ${PYILMBASE_SOVERSION} + VERSION ${PYILMBASE_LIB_VERSION} + ) + endif() + set_target_properties(${libname} PROPERTIES + OUTPUT_NAME "${PYILMBASE_OUTPUT_OUTROOT}${libname}${PYILMBASE_LIB_SUFFIX}" + ) + add_library(${PROJECT_NAME}::${libname} ALIAS ${libname}) + + install(TARGETS ${libname} + EXPORT ${PROJECT_NAME} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endfunction() + +# NB: This function has a number if specific names / variables +# not to mention behavior, so be careful copying... +function(PYILMBASE_DEFINE_MODULE modname) + set(options) + set(oneValueArgs PRIV_EXPORT CURDIR CURBINDIR LIBNAME) + set(multiValueArgs LIBSOURCE MODSOURCE HEADERS DEPENDENCIES PRIVATE_DEPS) + cmake_parse_arguments(PYILMBASE_CURMOD "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(PYILMBASE_BUILD_SUPPORT_LIBRARIES) + set(libarglist SOURCE ${PYILMBASE_CURMOD_LIBSOURCE}) + if(PYILMBASE_CURMOD_HEADERS) + list(APPEND libarglist HEADERS ${PYILMBASE_CURMOD_HEADERS}) + endif() + if(PYILMBASE_CURMOD_CURDIR) + list(APPEND libarglist CURDIR ${PYILMBASE_CURMOD_CURDIR}) + endif() + if(PYILMBASE_CURMOD_CURBINDIR) + list(APPEND libarglist CURDIR ${PYILMBASE_CURMOD_CURBINDIR}) + endif() + if(PYILMBASE_CURMOD_DEPENDENCIES) + list(APPEND libarglist DEPENDENCIES ${PYILMBASE_CURMOD_DEPENDENCIES}) + endif() + # NB: make this one last so we can cheat and add the python and boost + # libs as private deps at the end regardless of whether it was provided + list(APPEND libarglist PRIVATE_DEPS ${PYILMBASE_CURMOD_PRIVATE_DEPS}) + if(TARGET Python2::Python AND TARGET Boost::${PYILMBASE_BOOST_PY2_COMPONENT}) + set(libname "${PYILMBASE_CURMOD_LIBNAME}${PYILMBASE_LIB_PYTHONVER_ROOT}${Python2_VERSION_MAJOR}_${Python2_VERSION_MINOR}") + pyilmbase_add_library_priv(${libname} + OUTROOT "Python${Python2_VERSION_MAJOR}_${Python2_VERSION_MINOR}/" + ${libarglist} Python2::Python Boost::${PYILMBASE_BOOST_PY2_COMPONENT} + ) + Python2_add_library(${modname}_python2 MODULE ${PYILMBASE_CURMOD_MODSOURCE}) + target_link_libraries(${modname}_python2 + PRIVATE ${libname}) + set_target_properties(${modname}_python2 PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python${Python2_VERSION_MAJOR}_${Python2_VERSION_MINOR}/" + LIBRARY_OUTPUT_NAME "${modname}" + ) + + #### TODO: Define installation rules + endif() + if(TARGET Python3::Python AND TARGET Boost::${PYILMBASE_BOOST_PY3_COMPONENT}) + set(libname "${PYILMBASE_CURMOD_LIBNAME}${PYILMBASE_LIB_PYTHONVER_ROOT}${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR}") + pyilmbase_add_library_priv(${libname} + OUTROOT "Python${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR}/" + ${libarglist} Python3::Python Boost::${PYILMBASE_BOOST_PY3_COMPONENT} + ) + Python3_add_library(${modname}_python3 MODULE ${PYILMBASE_CURMOD_MODSOURCE}) + target_link_libraries(${modname}_python3 + PRIVATE ${libname}) + + set_target_properties(${modname}_python3 PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR}/" + LIBRARY_OUTPUT_NAME "${modname}" + ) + #### TODO: Define installation rules + endif() + else() + if(TARGET Python2::Python AND TARGET Boost::${PYILMBASE_BOOST_PY2_COMPONENT}) + Python2_add_library(${modname}_python2 MODULE + ${PYILMBASE_CURMOD_LIBSOURCE} + ${PYILMBASE_CURMOD_MODSOURCE}) + # add library will already depend on python... + target_link_libraries(${modname}_python2 + PRIVATE + Boost::${PYILMBASE_BOOST_PY2_COMPONENT} + ${PYILMBASE_CURMOD_DEPENDENCIES} + ${PYILMBASE_CURMOD_PRIVATE_DEPS}) + set_target_properties(${modname}_python2 PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python${Python2_VERSION_MAJOR}_${Python2_VERSION_MINOR}/" + LIBRARY_OUTPUT_NAME "${modname}" + ) + + #### TODO: Define installation rules + endif() + + if(TARGET Python3::Python AND TARGET Boost::${PYILMBASE_BOOST_PY3_COMPONENT}) + Python3_add_library(${modname}_python3 MODULE + ${PYILMBASE_CURMOD_LIBSOURCE} + ${PYILMBASE_CURMOD_MODSOURCE}) + # add library will already depend on python... + target_link_libraries(${modname}_python3 + PRIVATE + Boost::${PYILMBASE_BOOST_PY3_COMPONENT} + ${PYILMBASE_CURMOD_DEPENDENCIES} + ${PYILMBASE_CURMOD_PRIVATE_DEPS}) + set_target_properties(${modname}_python3 PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR}/" + LIBRARY_OUTPUT_NAME "${modname}" + ) + + #### TODO: Define installation rules + endif() + endif() +endfunction() diff --git a/PyIlmBase/config/ParseConfigure.cmake b/PyIlmBase/config/ParseConfigure.cmake new file mode 100644 index 0000000000..f1c32dc281 --- /dev/null +++ b/PyIlmBase/config/ParseConfigure.cmake @@ -0,0 +1,18 @@ + +file(READ configure.ac CONFIGURE_AC_CONTENTS) +string(REGEX MATCH "AC_INIT\\(PyIlmBase,[ ]*([0-9]+).([0-9]+).([0-9]+)" DUMMY ${CONFIGURE_AC_CONTENTS}) +set(PYILMBASE_VERSION_MAJOR ${CMAKE_MATCH_1}) +set(PYILMBASE_VERSION_MINOR ${CMAKE_MATCH_2}) +set(PYILMBASE_VERSION_PATCH ${CMAKE_MATCH_3}) +set(PYILMBASE_VERSION ${PYILMBASE_VERSION_MAJOR}.${PYILMBASE_VERSION_MINOR}.${PYILMBASE_VERSION_PATCH}) +set(PYILMBASE_VERSION_API ${PYILMBASE_VERSION_MAJOR}_${PYILMBASE_VERSION_MINOR}) +string(REGEX MATCH "LIBTOOL_CURRENT=([0-9]+)" DUMMY ${CONFIGURE_AC_CONTENTS}) +set(PYILMBASE_SOCURRENT ${CMAKE_MATCH_1}) +string(REGEX MATCH "LIBTOOL_REVISION=([0-9]+)" DUMMY ${CONFIGURE_AC_CONTENTS}) +set(PYILMBASE_SOREVISION ${CMAKE_MATCH_1}) +string(REGEX MATCH "LIBTOOL_AGE=([0-9]+)" DUMMY ${CONFIGURE_AC_CONTENTS}) +set(PYILMBASE_SOAGE ${CMAKE_MATCH_1}) +math(EXPR PYILMBASE_SOVERSION "${PYILMBASE_SOCURRENT} - ${PYILMBASE_SOAGE}") +set(PYILMBASE_LIB_VERSION "${PYILMBASE_SOVERSION}.${PYILMBASE_SOAGE}.${PYILMBASE_SOREVISION}") +message(STATUS "Configure PyIlmBase Version: ${PYILMBASE_VERSION} Lib API: ${PYILMBASE_LIB_VERSION}") +unset(CONFIGURE_AC_CONTENTS) diff --git a/PyIlmBase/config/PyIlmBaseSetup.cmake b/PyIlmBase/config/PyIlmBaseSetup.cmake new file mode 100644 index 0000000000..14c9f3baf5 --- /dev/null +++ b/PyIlmBase/config/PyIlmBaseSetup.cmake @@ -0,0 +1,82 @@ + +include(GNUInstallDirs) + +######################## +## Target configuration + +# TODO: Right now, we support compiling for multiple pythons at once +set(PYILMBASE_OVERRIDE_PYTHON2_INSTALL_DIR "" CACHE STRING "Override the install location for any python 2.x modules compiled") +set(PYILMBASE_OVERRIDE_PYTHON3_INSTALL_DIR "" CACHE STRING "Override the install location for any python 3.x modules compiled") + +######################## +## Build related options + +# This option builds the python modules with an extra library layer +# for the various modules. This was originally done for a larger +# internal system, but is unlikely to work on systems such as +# windows, or with compiling for multiple python platforms at once, +# without larger intervention and as such is disabled. +option(PYILMBASE_BUILD_SUPPORT_LIBRARIES "Build python modules with library layer (see comments before enabling)" OFF) +# Suffix to append to root name, this helps with version management +# but can be turned off if you don't care, or otherwise customized +# +set(PYILMBASE_LIB_SUFFIX "-${PYILMBASE_VERSION_API}" CACHE STRING "String added to the end of all the libraries (if on)") +set(PYILMBASE_LIB_PYTHONVER_ROOT "_Python" CACHE STRING "String added as a root to the python version in the libraries (if libs are on)") + +# This is a variable here for use in install lines when creating +# libraries (otherwise ignored). Care must be taken when changing this, +# as many things assume this is OpenEXR +set(PYILMBASE_OUTPUT_SUBDIR OpenEXR CACHE STRING "Destination sub-folder of the include path for install") + +# This does not seem to be available as a per-target property, +# but is pretty harmless to set globally +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +# rpath related setup +# +# NB: This is global behavior. This can be made to be +# set on a per-target basis, but that places a larger burden +# on the cmake add_library / add_executable call sites +# +# 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") + 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() + +######################## + +# Code check related features +option(PYILMBASE_USE_CLANG_TIDY "Check if clang-tidy is available, and enable that" OFF) +if(PYILMBASE_USE_CLANG_TIDY) + find_program(PYILMBASE_CLANG_TIDY_BIN clang-tidy) + if(PYILMBASE_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 + ${PYILMBASE_CLANG_TIDY_BIN}; + -header-filter=.; + -checks=*; + ) +endif()