Skip to content

cmake: prefer COMPILE_OPTIONS over CMAKE_C_FLAGS for custom C options #17047

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

Closed
wants to merge 10 commits into from

Conversation

vszakats
Copy link
Member

@vszakats vszakats commented Apr 14, 2025

Also:

  • pass -D_GNU_SOURCE via COMPILE_DEFINITIONS.
  • make it explicit to pass these C flags to feature checks.
  • update _GNU_SOURCE comment with pipe2().
  • enable -pedantic-errors picky option for GCC with CMake <3.23.
  • drop redundant condition when stripping existing MSVC /Wn options.

CMake passes CMAKE_C_FLAGS to targets, feature checks and raw
try_compile() calls. With COMPILE_OPTIONS, this is limited to
targets, and we must explicitly pass them to feature checks. This
makes the build logic clearer, and offers more control. It also
reduces log noise by omitting these options from linker commands,
and from CMAKE_C_FLAGS dumps in feature checks.

@github-actions github-actions bot added the build label Apr 14, 2025
@vszakats vszakats marked this pull request as draft April 14, 2025 08:07
@vszakats vszakats marked this pull request as ready for review April 14, 2025 10:01
@github-actions github-actions bot added the CI Continuous Integration label Apr 14, 2025
@vszakats vszakats closed this in e865420 Apr 14, 2025
@vszakats vszakats deleted the cm-compoptions branch April 14, 2025 19:37
vszakats added a commit to vszakats/curl that referenced this pull request Apr 14, 2025
vszakats added a commit to vszakats/curl that referenced this pull request Apr 14, 2025
vszakats added a commit that referenced this pull request Apr 14, 2025
Also:
- drop unnecessary type conversion. `CMAKE_REQUIRED_FLAGS` is already
  space-separated.
  https://cmake.org/cmake/help/latest/module/CheckCSourceCompiles.html

Follow-up to e865420 #17047
Closes #17055
vszakats added a commit to vszakats/curl that referenced this pull request Apr 15, 2025
Safe to do this now, as the code no longer relies on setting these
options after feature detection.

Follow-up to e865420 curl#17047
vszakats added a commit that referenced this pull request Apr 15, 2025
Safe to do this now, as the code no longer relies on setting these
options after feature detection.

Also: Tidy up the way we handle options not to be passed to feature
checks, and make sure to show them in the configure log.

Follow-up to e865420 #17047
Closes #17062
vszakats added a commit to vszakats/curl that referenced this pull request Apr 24, 2025
vszakats added a commit to vszakats/curl that referenced this pull request Apr 25, 2025
vszakats added a commit that referenced this pull request Apr 25, 2025
1. `CMAKE_C_FLAGS` may apply to other projects, and deleting/altering it
   may be unexpected.

2. We pass `-W4`/`-Wall` internally now, which do override custom
   `-W<n>` options in all supported MSVC versions.
   (as tested with Visual Studio generators)
   Ref: https://ci.appveyor.com/project/curlorg/curl/builds/51945416

Follow-up to e865420 #17047
Ref: 866e029 #1711

Closes #17179
nbaws pushed a commit to nbaws/curl that referenced this pull request Apr 26, 2025
…ions

Also:
- pass `-D_GNU_SOURCE` via `COMPILE_DEFINITIONS`.
- make it explicit to pass these C flags to feature checks.
- update `_GNU_SOURCE` comment with `pipe2()`.
- enable `-pedantic-errors` picky option for GCC with CMake <3.23.
- drop redundant condition when stripping existing MSVC `/Wn` options.

CMake passes `CMAKE_C_FLAGS` to targets, feature checks and raw
`try_compile()` calls. With `COMPILE_OPTIONS`, this is limited to
targets, and we must explicitly pass them to feature checks. This
makes the build logic clearer, and offers more control. It also
reduces log noise by omitting these options from linker commands,
and from `CMAKE_C_FLAGS` dumps in feature checks.

Closes curl#17047
nbaws pushed a commit to nbaws/curl that referenced this pull request Apr 26, 2025
Also:
- drop unnecessary type conversion. `CMAKE_REQUIRED_FLAGS` is already
  space-separated.
  https://cmake.org/cmake/help/latest/module/CheckCSourceCompiles.html

Follow-up to e865420 curl#17047
Closes curl#17055
nbaws pushed a commit to nbaws/curl that referenced this pull request Apr 26, 2025
Safe to do this now, as the code no longer relies on setting these
options after feature detection.

Also: Tidy up the way we handle options not to be passed to feature
checks, and make sure to show them in the configure log.

Follow-up to e865420 curl#17047
Closes curl#17062
nbaws pushed a commit to nbaws/curl that referenced this pull request Apr 26, 2025
1. `CMAKE_C_FLAGS` may apply to other projects, and deleting/altering it
   may be unexpected.

2. We pass `-W4`/`-Wall` internally now, which do override custom
   `-W<n>` options in all supported MSVC versions.
   (as tested with Visual Studio generators)
   Ref: https://ci.appveyor.com/project/curlorg/curl/builds/51945416

Follow-up to e865420 curl#17047
Ref: 866e029 curl#1711

Closes curl#17179
nbaws pushed a commit to nbaws/curl that referenced this pull request Apr 26, 2025
…ions

Also:
- pass `-D_GNU_SOURCE` via `COMPILE_DEFINITIONS`.
- make it explicit to pass these C flags to feature checks.
- update `_GNU_SOURCE` comment with `pipe2()`.
- enable `-pedantic-errors` picky option for GCC with CMake <3.23.
- drop redundant condition when stripping existing MSVC `/Wn` options.

CMake passes `CMAKE_C_FLAGS` to targets, feature checks and raw
`try_compile()` calls. With `COMPILE_OPTIONS`, this is limited to
targets, and we must explicitly pass them to feature checks. This
makes the build logic clearer, and offers more control. It also
reduces log noise by omitting these options from linker commands,
and from `CMAKE_C_FLAGS` dumps in feature checks.

Closes curl#17047
nbaws pushed a commit to nbaws/curl that referenced this pull request Apr 26, 2025
Also:
- drop unnecessary type conversion. `CMAKE_REQUIRED_FLAGS` is already
  space-separated.
  https://cmake.org/cmake/help/latest/module/CheckCSourceCompiles.html

Follow-up to e865420 curl#17047
Closes curl#17055
nbaws pushed a commit to nbaws/curl that referenced this pull request Apr 26, 2025
Safe to do this now, as the code no longer relies on setting these
options after feature detection.

Also: Tidy up the way we handle options not to be passed to feature
checks, and make sure to show them in the configure log.

Follow-up to e865420 curl#17047
Closes curl#17062
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build CI Continuous Integration cmake tidy-up
Development

Successfully merging this pull request may close these issues.

1 participant