Fix CXXFLAGS when coverage enabled.#1902
Conversation
WalkthroughThe changes introduce new options in the CMake configuration for enabling C++ support based on specific conditions. Three options are added: Changes
Sequence Diagram(s)sequenceDiagram
participant CMake as CMakeLists.txt
participant Condition as IF Statement
participant CXX as C++ Language Enabler
CMake->>Condition: Check WITH_GTEST, WITH_FUZZERS, or WITH_BENCHMARKS flags
alt One or more flags are true
Condition->>CXX: Call enable_language(CXX)
else No flags are true
Condition->>CMake: Proceed without enabling C++
end
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS.html:
As I see, Line 13 in e4a31e0 zlib-ng/.github/workflows/pkgcheck.yml Line 24 in e4a31e0 zlib-ng/.github/workflows/cmake.yml Line 91 in e4a31e0 Maybe it makes sense to fix these workflows instead of duplicate |
The issue is with cmake populating When coverity scan is not enabled, there is no issue and the workaround is skipped. |
What do you mean by too late? |
Clearly when I and dead2 tested, those variables were empty when cmake hit the function in the PR. See for example https://github.com/zlib-ng/zlib-ng/actions/runs/14375470240/job/40306746506?pr=1892 |
|
This may be why I had to turn off gtest for PPC64LE ci run. |
You can verify that locally by re-enabling gtest for PPC64LE after checking out branch from this PR. |
Nope this PR doesn't fix that. |
At least this workaround allows enabling benchmarks on 32-bit ARM with hard-float on CI. |
I have one idea. I'll check it now and write the result... |
@mtl1979 , @Dead2 , this is incorrect PR! The C++ language is enabled too late. After the We need to enable C++ directly in Line 50 in e4a31e0 See fix commit phprus@0667808 |
A lot of operating systems don't come with C++ compiler installed by default. I'd rather enable C++ only when it's actually needed... |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #1902 +/- ##
===========================================
- Coverage 83.42% 83.38% -0.04%
===========================================
Files 144 144
Lines 12948 12948
Branches 2857 2857
===========================================
- Hits 10802 10797 -5
+ Misses 1202 1201 -1
- Partials 944 950 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
CMakeLists.txt (1)
50-54: Enabling C++ Early for Proper Flag Initialization
The newly added block correctly callsenable_language(CXX)when eitherWITH_GTESTorWITH_BENCHMARKSis enabled. This is an important step to ensure that the C++ compiler flags (CXXFLAGS) are properly initialized—especially critical when code coverage is enabled and the default behavior (i.e. using only CFLAGS and not propagating CXXFLAGS) might otherwise lead to errors in test configurations.It would be helpful to add or update an inline comment to clarify that this conditional is chosen because test targets (typically using gtest or benchmarks) require a C++ compiler to be configured early, which in turn forces CMake to initialize CXXFLAGS from the CXXFLAGS environment variable. Additionally, consider whether other cases (for example, when code coverage is enabled in a context that uses C++ features) might also require C++ support—if so, extending the condition (e.g. to include a check for
WITH_CODE_COVERAGE) might be warranted.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
CMakeLists.txt(1 hunks)test/CMakeLists.txt(0 hunks)test/benchmarks/CMakeLists.txt(0 hunks)
💤 Files with no reviewable changes (2)
- test/benchmarks/CMakeLists.txt
- test/CMakeLists.txt
🧰 Additional context used
🪛 GitHub Actions: Package Check
CMakeLists.txt
[error] 1-1: CMake Error in test/CMakeLists.txt: No known features for CXX compiler version.
🪛 GitHub Actions: Static Analysis
CMakeLists.txt
[error] 1-1: CMake Error in test/CMakeLists.txt: No known features for CXX compiler version.
[warning] 1509-1509: CMake Warning: Building to source folder is not recommended. Cpack will be unable to generate source package.
⏰ Context from checks skipped due to timeout of 90000ms (48)
- GitHub Check: macOS Clang Native Instructions (ARM64)
- GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
- GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
- GitHub Check: Ubuntu GCC -O3 OSB
- GitHub Check: Ubuntu GCC Symbol Prefix
- GitHub Check: macOS Clang Native Instructions (ARM64)
- GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
- GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
- GitHub Check: Ubuntu GCC -O3 OSB
- GitHub Check: Ubuntu GCC Symbol Prefix
- GitHub Check: macOS Clang Native Instructions (ARM64)
- GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
- GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
- GitHub Check: Ubuntu GCC -O3 OSB
- GitHub Check: Ubuntu GCC Symbol Prefix
- GitHub Check: macOS Clang Native Instructions (ARM64)
- GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
- GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
- GitHub Check: Ubuntu GCC -O3 OSB
- GitHub Check: Ubuntu GCC Symbol Prefix
- GitHub Check: macOS Clang Native Instructions (ARM64)
- GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
- GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
- GitHub Check: Ubuntu GCC -O3 OSB
- GitHub Check: Ubuntu GCC Symbol Prefix
- GitHub Check: macOS Clang Native Instructions (ARM64)
- GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
- GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
- GitHub Check: Ubuntu GCC -O3 OSB
- GitHub Check: Ubuntu GCC Symbol Prefix
- GitHub Check: macOS Clang Native Instructions (ARM64)
- GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
- GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
- GitHub Check: Ubuntu GCC -O3 OSB
- GitHub Check: Ubuntu GCC Symbol Prefix
- GitHub Check: macOS Clang Native Instructions (ARM64)
- GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
- GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
- GitHub Check: Ubuntu GCC -O3 OSB
- GitHub Check: Ubuntu GCC Symbol Prefix
- GitHub Check: macOS Clang Native Instructions (ARM64)
- GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
- GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
- GitHub Check: Ubuntu GCC Symbol Prefix
- GitHub Check: macOS Clang Native Instructions (ARM64)
- GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
- GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
- GitHub Check: Ubuntu GCC Symbol Prefix
Yes, you are right. The previous commit was a proof of concept only. |
034321d to
c7bce0b
Compare
Dead2
left a comment
There was a problem hiding this comment.
Yeah, this looks like a better solution 👍
Once this PR is merged, #1892 needs to be rebased for CI to pass on all except EL9... |
This allows CI to add flags for C++ compiler even when coverage is enabled. According to CMake documentation
CXXFLAGSis only used ifCMAKE_CXX_FLAGSis unset. Enable C++ support early enough soCMAKE_CXX_FLAGSis correctly populated.Summary by CodeRabbit