Skip to content
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

CFLAGS from environment are not respected #433

Open
mgorny opened this issue Dec 28, 2022 · 2 comments
Open

CFLAGS from environment are not respected #433

mgorny opened this issue Dec 28, 2022 · 2 comments

Comments

@mgorny
Copy link
Contributor

mgorny commented Dec 28, 2022

Describe the bug
Normally, CMake defaults the C compiler flags to the value of CFLAGS environment variable. However, c-blosc2 overrides CMAKE_C_FLAGS and prevents CMake from respecting that.

To Reproduce

CFLAGS="-frecord-gcc-switches" cmake .. -G Ninja
ninja -v |& grep record-gcc-switches

Expected behavior
-frecord-gcc-switches should be found on the compiler command-line.

Logs
n/a

System information:

  • OS: Gentoo Linux amd64
  • Compiler: gcc 12.2.1
  • Version: v2.6.1

Additional context
I suppose adding something like this on top would work. However, I'm not sure if there isn't a cleaner solution:

if(NOT CMAKE_C_FLAGS)
  set(CMAKE_C_FLAGS "$ENV{CFLAGS}")
endif()
@DimitriPapadopoulos
Copy link
Contributor

DimitriPapadopoulos commented Feb 15, 2023

Indeed CGLAGS seems to be the traditional standard approach to modify C options locally outside the build chain, but also inside the build chain. For example, in configure.ac you would write:

CFLAGS="$CFLAGS -std=c11"

Therefore, I wonder whether CMake should manipulate CFLAGS instead of directly modifying CMAKE_C_FLAGS:

CMake uses this environment variable value, in combination with its own builtin default flags for the toolchain, to initialize and store the CMAKE_C_FLAGS cache entry. [...] For any configuration run (including the first), the environment variable will be ignored if the CMAKE_C_FLAGS variable is already defined.

However, that approach might require some extra changes, for example here:

# Set the "-msse2" build flag only if the CMAKE_C_FLAGS is not already set.
# Probably "-msse2" should be appended to CMAKE_C_FLAGS_RELEASE.
if(CMAKE_C_COMPILER_ID STREQUAL GNU OR CMAKE_C_COMPILER_ID STREQUAL Clang OR CMAKE_C_COMPILER_ID STREQUAL Intel)
    if(NOT CMAKE_C_FLAGS AND COMPILER_SUPPORT_SSE2)
        set(CMAKE_C_FLAGS -msse2 CACHE STRING "C flags." FORCE)
    endif()
endif()

@DimitriPapadopoulos
Copy link
Contributor

DimitriPapadopoulos commented Apr 16, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants