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

Set default value for CMAKE_INSTALL_PREFIX #208

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

traversaro
Copy link
Contributor

@traversaro traversaro commented Mar 21, 2024

CMake 3.29 added support for specifying the default for CMAKE_INSTALL_PREFIX via an environment variable, called CMAKE_INSTALL_PREFIX (see https://gitlab.kitware.com/cmake/cmake/-/issues/25023 and https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9200).

Without setting the CMAKE_INSTALL_PREFIX env variable, the default install prefix is /usr/local on *nix or some path based on C:\Program Files\ on Windows. In any case, this default values do not make sense w.r.t. to the CONDA_PREFIX .

This PR adds activation scripts to the cmake package to set the CMAKE_INSTALL_PREFIX env variable (and hence the default value of CMAKE_INSTALL_PREFIX to a useful value, according to the following logic:

  • If on *nix, set CMAKE_INSTALL_PREFIX to $CONDA_PREFIX, or $PREFIX when under conda-build
  • If on Windows, set CMAKE_INSTALL_PREFIX to %CONDA_PREFIX%\Library, or %PREFIX%\Library when under conda-build

The main advantage of this is that now downloading and installing a project via git clone https://github.com/someorg/someproj && cmake -Bbuild -Ssomeproj && cmake --build ./build && cmake --install ./build while automatically installs the cmake project in the environment, a bit like on Python git clone https://github.com/someorg/someproj && pip install --no-deps -e ./someproj installs the Python package in the environment.

If CMAKE_INSTALL_PREFIX is set via command line, the value specified via command line take the precedence over the default value set via the CMAKE_INSTALL_PREFIX environment variable, so this modification should be backward compatible with all conda recipes or any other cmake use that sets CMAKE_INSTALL_PREFIX either via $CMAKE_ARGS or explicitly.

Checklist

  • Used a personal fork of the feedstock to propose changes
  • Bumped the build number (if the version is unchanged)
  • Reset the build number to 0 (if the version changed)
  • Re-rendered with the latest conda-smithy (Use the phrase @conda-forge-admin, please rerender in a comment in this PR for automated rerendering)
  • Ensured the license file is being packaged.

@conda-forge-webservices
Copy link
Contributor

Hi! This is the friendly automated conda-forge-linting service.

I just wanted to let you know that I linted all conda-recipes in your PR (recipe) and found it was in an excellent condition.

@traversaro
Copy link
Contributor Author

@conda-forge-admin, please rerender

Copy link
Contributor

Hi! This is the friendly automated conda-forge-webservice.

I tried to rerender for you, but it looks like there was nothing to do.

This message was generated by GitHub actions workflow run https://github.com/conda-forge/cmake-feedstock/actions/runs/8382827218.

@jschueller
Copy link
Contributor

wouldnt it be easier to add this to the other flags generated by conda-build like CXXFLAGS, CMAKE_ARGS, etc ... rather than this specific feedstock ?

@traversaro
Copy link
Contributor Author

traversaro commented Mar 22, 2024

wouldnt it be easier to add this to the other flags generated by conda-build like CXXFLAGS, CMAKE_ARGS, etc ... rather than this specific feedstock ?

My rationale is that those variables are set in the compiler activation scripts, while you can use CMake projects also without any compiler, for example if you have a project that only install config files or CMake files. Those kind of packages tipically have LANGUAGES NONE passed to their project invocation exactly not to required any kind of compiler (by default CMake enables C and CXX languages).

@isuruf
Copy link
Member

isuruf commented Mar 22, 2024

I don't think it is a good idea to do this automatically. There are issues like conda-forge/ctng-compiler-activation-feedstock#77 which came up because CMAKE_ARGS was used automatically by scikit-build.

@traversaro
Copy link
Contributor Author

I don't think it is a good idea to do this automatically. There are issues like conda-forge/ctng-compiler-activation-feedstock#77 which came up because CMAKE_ARGS was used automatically by scikit-build.

This proposal only changes the default value of CMAKE_INSTALL_PREFIX , that is currently set to /usr/local. This value can be safely overriden by passing the -DCMAKE_INSTALL_PREFIX= argument to the command line. If this PR is merged, assuming that CMake >= 3.29 is used indeed we could solve conda-forge/ctng-compiler-activation-feedstock#77 by removing -DCMAKE_INSTALL_PREFIX from CMAKE_ARGS, so that users can just override the default value naturally by passing -DCMAKE_INSTALL_PREFIX=<..> to the CMake command line, as opposed to overriding the CMAKE_INSTAL_PREFIX set in CMAKE_ARGS that requires editing the CMAKE_ARGS environment value.

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

Successfully merging this pull request may close these issues.

3 participants