diff --git a/CMakeLists.txt b/CMakeLists.txt index a892d047c..80dc793b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,14 +44,14 @@ if(OTIO_PYTHON_INSTALL) # that default behaviors match a reasonable expectation, as follows: # # if nothing has been set, - # Python: ${Python_SITEARCH}/opentimelineio - # C++: ${Python_SITEARCH}/opentimelineio/cxx-libs + # Python: ${OTIO_RESOLVED_PYTHON_INSTALL_DIR}/opentimelineio + # C++: ${OTIO_RESOLVED_PYTHON_INSTALL_DIR}/opentimelineio/cxx-sdk # if only CMAKE_INSTALL_PREFIX has been set, # Python: ${CMAKE_INSTALL_PREFIX}/opentimelineio/python # C++: ${CMAKE_INSTALL_PREFIX}/opentimelineio # if only OTIO_PYTHON_INSTALL_DIR has been set, # Python: ${OTIO_PYTHON_INSTALL_DIR}/opentimelineio - # C++: ${OTIO_PYTHON_INSTALL_DIR}/opentimelineio/cxx-libs + # C++: ${OTIO_PYTHON_INSTALL_DIR}/opentimelineio/cxx-sdk # # In a python install, the dylibs/dlls need to be installed where __init.py # can find them, rather as part of the C++ sdk package; so the variable @@ -60,19 +60,13 @@ if(OTIO_PYTHON_INSTALL) if(OTIO_PYTHON_INSTALL_DIR STREQUAL "" AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) # neither install directory supplied from the command line find_package(Python REQUIRED COMPONENTS Interpreter Development) - set(OTIO_RESOLVED_PYTHON_INSTALL_DIR "${Python_SITEARCH}") - set(OTIO_RESOLVED_CXX_INSTALL_DIR "${Python_SITEARCH}/opentimelineio/cxx-libs") - set(OTIO_RESOLVED_CXX_DYLIB_INSTALL_DIR "${Python_SITEARCH}/opentimelineio") + set(OTIO_RESOLVED_PYTHON_INSTALL_DIR "${OTIO_RESOLVED_PYTHON_INSTALL_DIR}") + set(OTIO_RESOLVED_CXX_INSTALL_DIR "${OTIO_RESOLVED_PYTHON_INSTALL_DIR}/opentimelineio/cxx-sdk") + set(OTIO_RESOLVED_CXX_DYLIB_INSTALL_DIR "${OTIO_RESOLVED_PYTHON_INSTALL_DIR}/opentimelineio") message(INFO, "OTIO Defaulting both Python and C++ install to ${OTIO_RESOLVED_PYTHON_INSTALL_DIR}") else() # either python_install or install_prefix have been set - if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - # OTIO_PYTHON_INSTALL_DIR was set, so install everything into the python package - set(OTIO_RESOLVED_PYTHON_INSTALL_DIR "${OTIO_PYTHON_INSTALL_DIR}") - set(OTIO_RESOLVED_CXX_INSTALL_DIR "${OTIO_PYTHON_INSTALL_DIR}/opentimelineio/lib") - set(OTIO_RESOLVED_CXX_DYLIB_INSTALL_DIR "${OTIO_PYTHON_INSTALL_DIR}/opentimelineio") - message(INFO, "OTIO Defaulting C++ install to ${OTIO_RESOLVED_CXX_INSTALL_DIR}") - else() + if(OTIO_PYTHON_INSTALL_DIR_INITIALIZED_TO_DEFAULT) # CMAKE_INSTALL_PREFIX was set, so install the python components there set(OTIO_RESOLVED_PYTHON_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/python") set(OTIO_RESOLVED_CXX_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}") @@ -80,9 +74,15 @@ if(OTIO_PYTHON_INSTALL) # In order to not require setting $PYTHONPATH to point at the .so, # the shared libraries are installed into the python library # location. - set(OTIO_RESOLVED_CXX_DYLIB_INSTALL_DIR "${OTIO_PYTHON_INSTALL_DIR}/opentimelineio") + set(OTIO_RESOLVED_CXX_DYLIB_INSTALL_DIR "${OTIO_RESOLVED_PYTHON_INSTALL_DIR}/opentimelineio") message(INFO, "OTIO Defaulting Python install to ${OTIO_RESOLVED_PYTHON_INSTALL_DIR}") - message(INFO, "Note: C++ linkable-shared libraries can be found: ${OTIO_PYTHON_INSTALL_DIR}/opentimelineio") + message(INFO, "Note: C++ linkable-shared libraries can be found: ${CMAKE_INSTALL_PREFIX}/opentimelineio") + else() + # OTIO_PYTHON_INSTALL_DIR was set, so install everything into the python package + set(OTIO_RESOLVED_PYTHON_INSTALL_DIR "${OTIO_PYTHON_INSTALL_DIR}") + set(OTIO_RESOLVED_CXX_INSTALL_DIR "${OTIO_PYTHON_INSTALL_DIR}/opentimelineio/cxx-sdk") + set(OTIO_RESOLVED_CXX_DYLIB_INSTALL_DIR "${OTIO_PYTHON_INSTALL_DIR}/opentimelineio") + message(INFO, "OTIO Defaulting C++ install to ${OTIO_PYTHON_INSTALL_DIR}") endif() endif() else() diff --git a/setup.py b/setup.py index 539b6f6a4..ce9cacf73 100755 --- a/setup.py +++ b/setup.py @@ -29,6 +29,14 @@ import distutils +# XXX: If there is a better way to find the value of --prefix, please notify +# the maintainers of OpenTimelineIO. +_dist = distutils.dist.Distribution() +_dist.parse_config_files() +_dist.parse_command_line() +PREFIX = _dist.get_option_dict('install').get('prefix', [None, None])[1] + + class _Ctx(object): pass @@ -77,21 +85,30 @@ def cmake_generate(): '-DCMAKE_BUILD_TYPE=' + ('Debug' if _ctx.debug else 'Release') ] - if "--user" in sys.argv: - cmake_args += [ - '-DOTIO_PYTHON_INSTALL_DIR=' + _ctx.install_usersite, - '-DCMAKE_INSTALL_PREFIX=' + os.path.join(_ctx.install_usersite, - "opentimelineio", "cxx-libs"), - '-DOTIO_PYTHON_PACKAGE_DIR=' + os.path.join(_ctx.install_usersite, - "opentimelineio") - ] - else: - cmake_args += [ - '-DOTIO_PYTHON_INSTALL_DIR=' + get_python_lib(), - '-DCMAKE_INSTALL_PREFIX=' + os.path.join(get_python_lib(), - "opentimelineio", "cxx-libs"), - '-DOTIO_PYTHON_PACKAGE_DIR=' + get_python_lib() - ] + python_inst_dir = get_python_lib() + + if PREFIX: + # XXX: is there a better way to find this? This is the suffix from + # where it would have been installed pasted onto the PREFIX as passed + # in by --prefix. + python_inst_dir = ( + distutils.sysconfig.get_python_lib().replace(sys.prefix, PREFIX) + ) + elif "--user" in sys.argv: + python_inst_dir = _ctx.install_usersite + + # install the C++ into the opentimelineio/cxx-sdk directory under the + # python installation + cmake_install_prefix = os.path.join( + python_inst_dir, + "opentimelineio", + "cxx-sdk" + ) + + cmake_args += [ + '-DOTIO_PYTHON_INSTALL_DIR=' + python_inst_dir, + '-DCMAKE_INSTALL_PREFIX=' + cmake_install_prefix, + ] if platform.system() == "Windows": if sys.maxsize > 2**32: @@ -369,7 +386,7 @@ def test_otio(): ], 'opentimelineio_contrib': [ 'adapters/contrib_adapters.plugin_manifest.json', - ] + ], }, include_package_data=True,