DIPlib / diplib

Quantitative Image Analysis in C++, MATLAB and Python
https://diplib.org
Apache License 2.0
222 stars 49 forks source link

Please make Java and Python bindings conditional on cmake variables #119

Closed yurivict closed 1 year ago

yurivict commented 1 year ago

Ports/packages need to reliably build only components that they need to build.

crisluengo commented 1 year ago

There are CMake variables to control the build of each component:

By default these components will be built by make all if the required dependencies are found, you need to explicitly turn off components you don't want installed.

However, if you use the DIPlib project as a submodule of another CMake project, and in that project only link against, for example, the DIPlib library, then only the DIPlib library will be built.

If there is a better way to set up the project, other than splitting it up into a separate repository for each component, please let me know!

yurivict commented 1 year ago

Splitting into components is an optimal solution. For example, I was unable to build the Python bindings separately. They are practically a separate project, but they are bundled with the C++ project and aren't easily buildable separately.

crisluengo commented 1 year ago

Well, the Python bindings depend on the library, it makes no sense to build them without building the library.

If they are separate projects, it would be a lot more difficult to build the Python bindings, because you'd have to build two projects instead of one.

I guess I don't understand your use case.

yurivict commented 1 year ago

On FreeBSD (and in general) multiple Python versions can be installed at the same time. Python bindings should be built for each Python version.

One port/package would be for the C++ project, and another port/package would be for the Python bindings. This isn't difficult.

crisluengo commented 1 year ago

If you build the project for different Python versions sequentially, the DIPlib library will not be rebuild, only the bindings themselves will be.

This is how the GitHub Action builds the Python package for different versions of Python that you'll find on PyPI. See the script.

yurivict commented 1 year ago

But this would require to keep the build directory. We only keep the installed package, and not the build directory.

crisluengo commented 1 year ago

What if there was an alternate CMakeList.txt file that builds the Python bindings using an already installed version of DIPlib?

I’d be happy to help you write it and maintain it in the repository.

You’d have to replace the standard CMake script with this alternate one, then build the package. Or maybe it lives in a subdirectory, you’d have to run CMake in the subdirectory.

I think this would simplify your workflow significantly, and it would only duplicate a small bit of CMake script.

yurivict commented 1 year ago

Here is an example in the Faiss project.

It builds both as an embedded cmake script, and as a standalone project.

crisluengo commented 1 year ago

That's an interesting approach. I think I can rewrite the CMake script for the Python bindings in that way, but it'll be quite a bit of work.