OpenAssetIO / OpenAssetIO-MediaCreation

OpenAssetIO extensions for use in the Media Creation industry.
Apache License 2.0
12 stars 10 forks source link

cmake: add support for the python bindings #49

Closed lpapp-foundry closed 1 year ago

lpapp-foundry commented 1 year ago

What

As a host developer I would like to be able to build both the C++ and Python versions of MC in a fashion consistent with the core OpenAssetIO library so that I can vendor them within my own build system. Eg. Conan, etc... and be assured that the python and c++ builds are guaranteed to be in sync.

Why

Presently, if I need to vendor MC, I need two build phases and it is inconsistent with the core library.

ACs

Original request

I would like to write a conan recipe for media creation, both for the C++ and Python parts.

Similarly, to OpenAssetIO, it would be good if the python interface was deployed "automatically".

In this case, this would mean:

  1. Generating the python bindings.
  execute_process(COMMAND openassetio-traitgen ${PROJECT_BINARY_DIR}/traits.yml   
                -o ${PROJECT_BINARY_DIR}/python -g python
                COMMAND_ERROR_IS_FATAL ANY                                      
                COMMAND_ECHO STDERR)

or so.

  1. cmake installs them into the usual sites-packages structure.

    OpenAssetIO has a OPENASSETIO_PYTHON_SITEDIR variable fro this purpose, so there could be a similar OPENASSETIO_MEDIACREATION_PYTHON_SITEDIR.

set(OPENASSETIO_MEDIACREATION_PYTHON_SITEDIR                                           
"lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages")  
if (WIN32) # Should not use 'bin' for Windows                                   
    set(OPENASSETIO_MEDIACREATION_PYTHON_SITEDIR "Lib/site-packages")           
endif()

install(                                                                        
    DIRECTORY package/openassetio_mediacreation                                        
    DESTINATION "${OPENASSETIO_MEDIACREATION_PYTHON_SITEDIR}"                   
    FILES_MATCHING PATTERN "*.py"                                               
) 

or something like that.

So that the conan recipe consumer does not need to do any extra work.

foundrytom commented 1 year ago

Reminder: when we do this, we need to cross-reference with how we do this in OpenAssetIO (where iirc pip just copes out of dist made by cmake as it always requires c++). I don't think that makes as much sense in this case where you can legitimately build python on its own. We don't want to involve cmake then.