Some CMake settings cann only be properly set using environment variables, such as CC, CXX, CFLAGS and CXXFLAGS. CMake has no CLI argument to do that instead; it is designed to take this from environment variables.
In nixpkgs we don't really support that. You can do e.g.
{
preConfigure = ''
export CLFAGS="-march=haswell"
'';
}
or
{
CXXFLAGS = "-march=haswell";
}
but this will pollute the entire build environment, instead of being given specifically to CMake's configure phase.
NIX_CFLAGS_COMPILE = "-march=haswell"; is a workaround, but it is a hack that sneaks flags past cmake directly to the compiler, and I think it should be avoided (it has various drawbacks, such as CMake not seeing what your compiler flag wishes are; see also #77979 (comment)).
In general I think that CXXFLAGS = "-march=haswell"; is fine for most cases but there may be builds that require it not polluting the environment.
Proposal
I propose that we replace
|
cmake ${cmakeDir:-.} $cmakeFlags "${cmakeFlagsArray[@]}" |
by something like
"${cmakeEnvVarsArray[@]}" cmake ${cmakeDir:-.} $cmakeFlags "${cmakeFlagsArray[@]}"
to allow using CMake as it is intended.
CC @ttuegel @LnL7
Some CMake settings cann only be properly set using environment variables, such as
CC,CXX,CFLAGSandCXXFLAGS. CMake has no CLI argument to do that instead; it is designed to take this from environment variables.In nixpkgs we don't really support that. You can do e.g.
or
but this will pollute the entire build environment, instead of being given specifically to CMake's configure phase.
NIX_CFLAGS_COMPILE = "-march=haswell";is a workaround, but it is a hack that sneaks flags past cmake directly to the compiler, and I think it should be avoided (it has various drawbacks, such as CMake not seeing what your compiler flag wishes are; see also #77979 (comment)).In general I think that
CXXFLAGS = "-march=haswell";is fine for most cases but there may be builds that require it not polluting the environment.Proposal
I propose that we replace
nixpkgs/pkgs/development/tools/build-managers/cmake/setup-hook.sh
Line 107 in f498ceb
by something like
to allow using CMake as it is intended.
CC @ttuegel @LnL7