Skip to content

cmake setup hook: Allow passing environment variables to cmake invocation #79302

Open

Description

@nh2

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

Activity

  1. added
    0.kind: enhancement
    on Feb 6, 2020
  2. nh2 commented on Feb 6, 2020

    @nh2
    ContributorAuthor

    This would be required for #79303.

  3. stale commented on Aug 4, 2020

    @stale

    Hello, I'm a bot and I thank you in the name of the community for opening this issue.

    To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

    The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

    If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

    Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.

  4. added
    2.status: stale
    on Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: enhancement2.status: stale

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions