Respect CMake defaults for `CMAKE_CXX_FLAGS`
envgap__RobotLocomotion__drake-24580
01 / FAILURE SIGNATURE
As reported upstream
No identifying execution failure has been captured.
Not a benchmark task.
- In a clean container the reported failure did not reproduce, or the known fix did not make the project run.
02 / ENVIRONMENT RECIPE
- Base commit
6314eb386da5ce4298aead4e2532e5ba5a05ddd6- Manifest
CMakeLists.txt- Reproduce
Awaiting issue-specific recipe- Run under trace
Awaiting a meaningful runtime command
03 / ORIGINAL ISSUE TEXT
RobotLocomotion/drake #24580 · read the original issue
**Is your feature request related to a problem? Please describe.** In #24456 we discovered that rules_cc has a fundamentally different C/C++ toolchain model than CMake: namely, that it ignores `CXX` and expects `CC` to be a compiler driver than can handle both C and C++. As such, we had CMake not even bother to search for C++ as a language via the `project()` command. However, CMake has built-in defaults for [`CMAKE_<LANG>_FLAGS`](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS.html), like `-O3 -DNDEBUG` under a release build. When `CXX` is not specified as a language for the project, these defaults for `CMAKE_CXX_FLAGS` are not initialized. In the context of #24526, this may be problematic; at least, when running with [`cmake --warn-uninitialized`](https://cmake.org/cmake/help/v4.3/manual/cmake.1.html#cmdoption-cmake-warn-uninitialized), something like the following will be produced: ``` CMake Warning (dev) at CMakeLists.txt:175 (separate_arguments): uninitialized variable 'CMAKE_CXX_FLAGS' This warning is for project developers. Use -Wno-dev to suppress it. CMake Warning (dev) at CMakeLists.txt:175 (separate_arguments): uninitialized variable 'CMAKE_CXX_FLAGS_RELEASE' This warning is for project developers. Use -Wno-dev to suppress it. ``` **Describe the solution you'd like** Either respect CMake's default `CMAKE_CXX_FLAGS` by re-enabling it as a language in the `project` command, or at least guard the logic from 24526 behind whether those variables are non-empty. If the former, in order to support Bazel's compiler-driver-based model, the CML should probably enforce that `CMAKE_C_COMPILER` and `CMAKE_CXX_COMPILER` are the same. **Describe alternatives you've considered** The two alternative options I see at this point are listed above. **Additional context** N/A
04 / LABELS
Labels from the report text only; not yet run
No supported category has been assigned.
Label rules and the text that matched
[]