Skip to content

cmake: setup-hook.sh: split out cmakeDefaultFlags#335682

Open
ShamrockLee wants to merge 4 commits intoNixOS:stagingfrom
ShamrockLee:cmake-default-flags
Open

cmake: setup-hook.sh: split out cmakeDefaultFlags#335682
ShamrockLee wants to merge 4 commits intoNixOS:stagingfrom
ShamrockLee:cmake-default-flags

Conversation

@ShamrockLee
Copy link
Contributor

@ShamrockLee ShamrockLee commented Aug 18, 2024

Description of changes

This PR extracts the default CMake flags pretending code into its own Bash function genCmakeDefaultFlags(). Instead of pretending the flags to cmakeFlags, it collects them into a global Bash array cmakeDefaultFlags.

Original discussions:
#318614 (comment)
#299622 (comment)

Cc: @AndersonTorres @jtojnar @wolfgangwalther

Things done

  • Built on platform(s)
    • x86_64-linux (built cmakeMinimal)
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@ShamrockLee ShamrockLee force-pushed the cmake-default-flags branch 2 times, most recently from 52ec97d to f118c78 Compare August 18, 2024 22:01
@ShamrockLee
Copy link
Contributor Author

@ofborg build cmake

@ShamrockLee
Copy link
Contributor Author

@ofborg build cmakeMinimal

@ShamrockLee ShamrockLee marked this pull request as ready for review August 19, 2024 00:19
@ofborg ofborg bot added 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Aug 19, 2024
@ShamrockLee
Copy link
Contributor Author

I adjusted the style and changed the order to group all the non-conditional flags.

@wolfgangwalther, what do you think about the current style?

Copy link
Contributor

@wolfgangwalther wolfgangwalther left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first two commits LGTM. We'll need to assume that the order of flags for cmake doesn't matter, though.

The last commit says:

This enables developers to get the default CMake flags provided by Nixpkgs without having to use cmakeConfigurePhase.

I don't understand the reason for that last commit, yet. Why is that important, what would you do with those flags?

@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Aug 21, 2024

The last commit says:

This enables developers to get the default CMake flags provided by Nixpkgs without having to use cmakeConfigurePhase.

I don't understand the reason for that last commit, yet. Why is that important, what would you do with those flags?

In a build flow where other build tools control CMake, the package developer needs to configure the command-line arguments for CMake without executing CMake itself. A Bash function to provide the flags without running the whole cmakeConfigurePhase might be helpful in such circumstances.

Update: Such use cases are essentially edge cases. I shouldn't emphasize them too much.

@ShamrockLee ShamrockLee force-pushed the cmake-default-flags branch 2 times, most recently from dd0682d to a3cfdba Compare August 21, 2024 21:23
Copy link
Contributor

@wolfgangwalther wolfgangwalther left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First two commits LGTM. Only eye-balled the changes, did not build anything with it.

Last commit I can't say much about the usefulness, but it shouldn't do any harm.

@ShamrockLee
Copy link
Contributor Author

Would it sound more clearly if the function is called setCmakeDefaultFlags?

@wegank wegank added the 12.approvals: 2 This PR was reviewed and approved by two persons. label Aug 31, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 1, 2024
@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 25, 2025
Format with `shfmt -i 4 -w pkgs/by-name/cm/cmake/setup-hook.sh`.

Keeping the code auto-formatted makes refactoring easier.
Collect the default CMake configure flags collected by
cmakeConfigurePhase into a Bash array named cmakeDefaultFlags.
@ShamrockLee ShamrockLee force-pushed the cmake-default-flags branch from a3cfdba to 3cc89ba Compare July 30, 2025 21:22
@ShamrockLee
Copy link
Contributor Author

Rebased and resolved merge confilcts.

@nixpkgs-ci nixpkgs-ci bot removed 2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md labels Jul 30, 2025
@ShamrockLee ShamrockLee force-pushed the cmake-default-flags branch from 3cc89ba to 4d373dc Compare July 31, 2025 17:12
@ShamrockLee
Copy link
Contributor Author

I split the source-independent cmakeDefaultFlags and define it directly at the beginning of setup-hook.sh. The source-dependent -DCMAKE_INSTALL_DOCDIR is added inside cmakeConfigurePhase, but the logic to parse shareDocName from cmakeLists.txt is split out as a Bash function parseShareDocName.

@wolfgangwalther @AndersonTorres How do you fell about the new implementation? I could roll back to the previous one if the latter is preferred.

@ShamrockLee ShamrockLee changed the title cmake: setup-hook.sh: add genCmakeDefaultFlags() cmake: setup-hook.sh: split out cmakeDefaultFlags Jul 31, 2025
@ShamrockLee ShamrockLee force-pushed the cmake-default-flags branch 2 times, most recently from b46374b to 470e053 Compare July 31, 2025 21:58
@ShamrockLee ShamrockLee force-pushed the cmake-default-flags branch from 470e053 to fefeb96 Compare August 7, 2025 13:10
Copy link
Contributor

@wolfgangwalther wolfgangwalther left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My feedback from earlier still applies:

First two commits LGTM. Only eye-balled the changes, did not build anything with it.

Last [two] commit[s] I can't say much about the usefulness, but [they] shouldn't do any harm.

@ShamrockLee
Copy link
Contributor Author

OfBorg fails to build cmakeMinimal, complaining about unbound Bash variable CXX.

The CC and CXX environment variables seem to be set by the setup hook provided by the CC wrapper, which is sourced after sourcing our cmake setup hooks.

@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 22, 2025
@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge-bot eligible This PR can be merged by commenting "@NixOS/nixpkgs-merge-bot merge". label Nov 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 2.status: merge-bot eligible This PR can be merged by commenting "@NixOS/nixpkgs-merge-bot merge". 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 12.approvals: 2 This PR was reviewed and approved by two persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants