Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hmeine opened this issue Oct 24, 2022 · 2 comments
Open

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

hmeine opened this issue Oct 24, 2022 · 2 comments

Comments

@hmeine
Copy link
Collaborator

hmeine commented Oct 24, 2022

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
Copy link
Collaborator Author

hmeine commented Oct 24, 2022

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
Copy link
Collaborator

hmaarrfk commented Oct 1, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants