conda-forge / cmake-feedstock

A conda-smithy repository for cmake.
BSD 3-Clause "New" or "Revised" License
4 stars 43 forks source link

Set default value for CMAKE_INSTALL_PREFIX #208

Open traversaro opened 7 months ago

traversaro commented 7 months ago

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:

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

conda-forge-webservices[bot] commented 7 months ago

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 commented 7 months ago

@conda-forge-admin, please rerender

github-actions[bot] commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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

traversaro commented 7 months ago

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.