ukoethe / vigra

a generic C++ library for image analysis
http://ukoethe.github.io/vigra/
Other
410 stars 191 forks source link

Look for a better boost::python CMake macro #524

Open hmeine opened 1 year ago

hmeine commented 1 year ago

I always have to pass a lot of explicit variable definitions to CMake and wonder if there are better configuration macros nowadays.

From what I can see, we introduced quite some custom configuration code back then in order to work around limitations of the default macros coming with CMake, but CMake has improved a lot in the meantime.

For instance, there is this comment:

    # 'FIND_PACKAGE(Boost COMPONENTS python)' is unreliable because it often selects
    # boost_python for the wrong Python version

followed by 160 LOC of a workaround, and the python libraries themselves are also detected with custom routines, following

    #  'FIND_PACKAGE(PythonLibs)' is unreliable because results are often inconsistent
    #  with the Python interpreter found previously (e.g. libraries or includes
    #  from incompatible installations). Thus, we ask Python itself for the information.

When looking at https://cmake.org/cmake/help/latest/module/FindPythonLibs.html, it nowadays states

If calling both find_package(PythonInterp) and find_package(PythonLibs), call find_package(PythonInterp) first to get the currently active Python version by default with a consistent version of PYTHON_LIBRARIES.

indicating that that should no longer be necessary. Furthermore, PythonInterp+PythonLibs are deprecated in favor of Python3 (requiring CMake 3.12, which is not much more than 3.10 which we have been specifying as minimum version since March 2021).

Finally, https://cmake.org/cmake/help/latest/module/FindBoost.html has an example section that suggests that one can also specify the required python version:

find_package(Boost 1.67 REQUIRED COMPONENTS
             python36 numpy36)

so hopefully all previous issues with the default scripts are solved.

hmeine commented 1 year ago

So, I tried the default macros out, and while it feels better to have less code, I did not have more success with it. In particular, while FindPython3 supports more attractive COMPONENTS including "Numpy", it fails to detect my MacPorts-installed NumPy. (Our old code using numpy.distutils robustly does the detection, but throws a deprecation warning, because numpy.distutils will be removed following the deprecation of distutils itself, so we will eventually need an alternative.)

hmaarrfk commented 1 year ago

maybe try again now that some of the build system has been revamped