Repository navigation
refactor: cmake use target_compile_flags - #7857
Conversation
|
Probably that weird NNLS code that was copied from the internet somewhere |
|
Had to fix quite some things here: https://github.com/OpenMS/OpenMS/pull/7298/files Not sure how compiler flags might help here though. |
|
You are probably not adding the flags to the tests, or are you? |
|
I got it to compile and tests pass. I would highly appreciate it if our cmake gurus @jpfeuffer and @cbielow can take a close look. |
|
We should really check why those flags are necessary. By the way, if downstream executables actually need those flags to run, when using OpenMS, the flags actually should be public, such that they show up in the CMake config for our exported targets. |
WalkthroughThe pull request refactors the project's CMake configuration to simplify and centralize compiler flag management. It removes the obsolete Changes
Sequence Diagram(s)sequenceDiagram
participant EXE as Executable Target
participant CSL as CMakeLists Loop
participant FLAG as openms_add_executable_compiler_flags
EXE->>CSL: add_executable(...)
CSL->>EXE: target_link_libraries(...)
CSL->>FLAG: call openms_add_executable_compiler_flags(target)
FLAG-->>EXE: Apply compiler flags
sequenceDiagram
participant LIB as Library Target
participant AM as add_library_macros.cmake
participant FLAG as openms_add_library_compiler_flags
LIB->>AM: Define library target
AM->>FLAG: call openms_add_library_compiler_flags(target)
FLAG-->>LIB: Apply compiler flags
Poem
🪧 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 (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (5)
cmake/compiler_flags.cmake (5)
43-45: Consider validating custom user flags.Currently, user-defined flags are simply appended. If a user-supplied flag clashes with or negates essential project-wide flags, it could silently degrade functionality. Adding a validation or conflict-resolution step can help maintain consistent builds.
56-71: Add Intel-specific flags if needed.Currently, Intel detection only sets an internal variable without adding relevant flags. If the project requires Intel optimizations or warnings, consider extending this section to ensure consistent behavior across compilers.
82-85: Consider extending conversion checks to more compilers.At the moment,
CXX_WARN_CONVERSIONonly applies to GCC. If you intend to standardize conversion warnings, you could introduce similar logic for other compilers (e.g., Clang’s-Wconversion).
112-116: Re-examine forcing AVX/SSSE3 by default.Setting
/arch:AVXon MSVC and-mssse3on non-MSVC compilers is effective for performance but may break compatibility with older x64 hardware lacking these instructions. A runtime feature check or fallback might be safer if broad compatibility is required.
90-199: Consider modularizing the large function.While this is a clean, centralized approach, the function covers many distinct compiler paths and warning sets for different compilers. Extracting smaller helper functions or grouping them by compiler could simplify maintenance.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
CMakeLists.txt(0 hunks)cmake/add_library_macros.cmake(1 hunks)cmake/compiler_flags.cmake(1 hunks)src/tests/class_tests/openms/CMakeLists.txt(1 hunks)src/tests/class_tests/openms_gui/CMakeLists.txt(1 hunks)src/topp/CMakeLists.txt(2 hunks)
💤 Files with no reviewable changes (1)
- CMakeLists.txt
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
- GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
- GitHub Check: build-and-test (macos-13, xcode, 14.2)
- GitHub Check: build-and-test (windows-2022, cl.exe, default)
- GitHub Check: cppcheck-test
🔇 Additional comments (10)
src/tests/class_tests/openms_gui/CMakeLists.txt (1)
66-66: Properly applied compiler flags to GUI test executablesThis addition ensures that all Visual test executables receive consistent compiler flags through the centralized
openms_add_executable_compiler_flagsfunction, aligning with the project's strategy to use target-specific compiler flags.src/tests/class_tests/openms/CMakeLists.txt (1)
68-68: Properly applied compiler flags to test executablesThe addition of
openms_add_executable_compiler_flags(${_class_test})ensures that all test executables receive consistent compiler flags through the centralized function, improving maintainability.src/topp/CMakeLists.txt (2)
43-43: Applied target-specific compiler flags to TOPP executablesGood use of the new
openms_add_executable_compiler_flagsfunction to ensure consistent compiler flags for non-GUI TOPP executables.
58-58: Applied target-specific compiler flags to GUI TOPP executablesCorrectly applies the centralized compiler flags to GUI TOPP executables. Note that the call to
openms_add_executable_compiler_flagsis placed before theinstall_toolcall and after the executable definition, maintaining the proper order of operations.cmake/add_library_macros.cmake (1)
164-165:Details
❓ Verification inconclusive
Improved compiler flag management with centralized helper function
Replacing direct compiler flag assignments with a call to the new helper function
openms_add_library_compiler_flagsis a good modernization of the CMake configuration. This centralizes compiler flag management and follows modern CMake best practices of using target-specific properties.Per jpfeuffer's concern in the PR comments, verify that these flags are made appropriately visible to downstream executables if they're required for correct operation with OpenMS libraries.
🏁 Script executed:
#!/bin/bash # Find the implementation of the helper functions to understand what flags are being set # and whether they're properly exported to downstream targets # Look for the compiler_flags.cmake or similar files that would define these functions fd "compiler_flags.cmake" --type f # Examine how the function is defined rg -A 15 "function\(openms_add_library_compiler_flags" # Check how INTERFACE or PUBLIC flags are handled for downstream targets rg "target_compile_options.*INTERFACE|PUBLIC" --include="*.cmake"Length of output: 1541
Action Required: Confirm proper flag propagation for downstream dependencies
The changes in
cmake/add_library_macros.cmake(lines 164–165) replace direct compiler flag assignments with a call to the centralized helper functionopenms_add_library_compiler_flags, which aligns with modern CMake best practices. However, after verifying the implementation incmake/compiler_flags.cmake, it appears that the helper function applies compiler flags (such as-Wno-non-virtual-dtorfor GNUC++ and address sanitizer options) using thePRIVATEscope. Please confirm that this is intentional. If downstream executables require these flags for correct operation with the OpenMS libraries, you may need to adjust the implementation to export the flags viaPUBLICorINTERFACEscopes.
- Verify if the PRIVATE flag setting correctly meets your dependency propagation requirements.
- Consider updating the scope to PUBLIC/INTERFACE for targets that need to inherit these flags.
cmake/compiler_flags.cmake (5)
37-41: No functional impact detected here.These added lines mainly provide documentation and structure, which looks fine.
48-48: Clear ARM handling is appreciated.The explanatory comments for ARM processors and references to SIMDe help future maintainers understand why no special flags are needed. This clarity is beneficial.
Also applies to: 52-55
72-81: Position-independent code logic is appropriate.Conditionally enabling
-fPICfor non-Windows platforms aligns with standard conventions and avoids linker conflicts on shared libraries.
201-215: Verify whether library flags should be public.The library-specific flags (e.g.,
-Wno-non-virtual-dtor) are set to PRIVATE here. If external linking depends on certain flags or definitions, ensure these are declared as PUBLIC.
217-228: Executable flags are neatly encapsulated.Separating these from library flags is good practice. Consider whether any essential definitions or warnings should also be public to propagate into downstream executables.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
cmake/compiler_flags.cmake (2)
123-180: Consider warning configuration effect on contributors.The warning configuration is comprehensive and well-organized by compiler. However, disabling too many warnings (especially in Clang) might hide potential issues that contributors could fix. Consider documenting the rationale for disabling specific warnings, particularly the numerous ones disabled for Clang.
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") target_compile_options(${target_name} PRIVATE -ffp-contract=off -Wall -Wextra + # Disable warnings that are not applicable or too strict for our codebase: -Wno-sign-conversion -Wno-global-constructors -Wno-exit-time-destructors
205-207: Consider documenting address sanitizer integration.The function
add_asan_to_targetis called but not defined in this file. Consider adding a comment to indicate where this function is defined, or ensure it's properly documented elsewhere for anyone reading this file.# Address sanitizer (PRIVATE) if(ADDRESS_SANITIZER) + # add_asan_to_target is defined in cmake/AddressSanitizer.cmake add_asan_to_target(${target_name}) endif()
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
cmake/compiler_flags.cmake(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
- GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
- GitHub Check: build-and-test (macos-13, xcode, 14.2)
- GitHub Check: build-and-test (windows-2022, cl.exe, default)
- GitHub Check: cppcheck-test
🔇 Additional comments (7)
cmake/compiler_flags.cmake (7)
35-42: Well-structured organization enhances maintainability.The addition of clear section headers and comments significantly improves the organization and readability of this file, making it easier to navigate and understand.
90-192: Good implementation of modular compiler flag application with PUBLIC/PRIVATE distinction.The new
openms_add_compiler_flagsfunction properly distinguishes between PUBLIC flags (that should propagate to dependent targets) and PRIVATE flags (that should not). This addresses the concerns raised in previous reviews about flag visibility and propagation.Key strengths of this implementation:
- Clear separation between PUBLIC and PRIVATE flags
- Properly propagating SIMD flags (essential for binary compatibility)
- Applying position-independent code flag correctly
- Comprehensive handling of compiler-specific options
This approach aligns well with modern CMake best practices by using target-specific properties rather than global settings.
211-221: Consider whether executable-specific flags are needed.The
openms_add_executable_compiler_flagsfunction currently doesn't add any specific flags beyond what's already in the base function. If there are no executable-specific flags needed, this is fine, but it might be worth adding a comment explaining that this function exists for future extensibility or consistency with the library function.This aligns with the past review comment where jpfeuffer asked about different flags for executables vs. libraries, and timosachsenberg confirmed that the
-Wno-non-virtual-dtorflag is the only difference.# Function to add executable-specific compiler flags function(openms_add_executable_compiler_flags target_name) # Add common flags first (both PUBLIC and PRIVATE) openms_add_compiler_flags(${target_name}) - # Executable-specific PRIVATE flags can be added here + # Executable-specific PRIVATE flags can be added here + # Currently, there are no executable-specific flags needed beyond what's in the base function. + # This function exists for consistency with the library function and potential future extensions. # Address sanitizer (PRIVATE) if(ADDRESS_SANITIZER) add_asan_to_target(${target_name}) endif() endfunction()
188-191:Details
❓ Verification inconclusive
Consider sanitizing MY_CXX_FLAGS for better security.
While the implementation to handle custom flags is good, there might be security implications if users can inject malicious flags. Consider adding a validation step to sanitize the input or document the potential security implications of this feature.
🏁 Script executed:
#!/bin/bash # Description: Check if MY_CXX_FLAGS is used in any CI/CD workflows or automated scripts echo "Checking for uses of MY_CXX_FLAGS in CI/CD configurations..." rg "MY_CXX_FLAGS" .github/ .ci/ .gitlab-ci.yml echo "Checking for validation of MY_CXX_FLAGS in CMake files..." rg "MY_CXX_FLAGS.*validate|validate.*MY_CXX_FLAGS" cmake/Length of output: 462
Security: Validate and Document MY_CXX_FLAGS Input
- In
cmake/compiler_flags.cmake(lines 188–191), the custom flags fromMY_CXX_FLAGSare split and passed directly totarget_compile_optionswithout any sanitization.- No evidence was found—via automated searches—of any existing validation for these flags.
- Please consider either adding a validation step to sanitize
MY_CXX_FLAGS(to prevent potential injection or misuse of compiler options) or, at minimum, document the potential security implications of accepting arbitrary flag inputs.
96-98:Details
❓ Verification inconclusive
Verify C++20 standard compatibility with all supported platforms and compilers.
Setting C++20 as a required feature might cause issues on platforms with older compilers. Ensure that all supported platforms have compilers capable of C++20 support.
🏁 Script executed:
#!/bin/bash # Description: Check minimum compiler versions required for C++20 support and compare with documentation echo "Checking for minimum compiler version requirements in documentation..." rg -i "compiler.*version|version.*compiler" doc/ README.md echo "Commonly required compiler versions for C++20 support:" echo "GCC: 10.0 or later" echo "Clang: 10.0 or later" echo "MSVC: Visual Studio 2019 16.11 or later" echo "Checking for compiler version checks in CMake files..." rg "CMAKE_CXX_COMPILER_VERSION" cmake/Length of output: 3463
Action: Confirm C++20 Compatibility Across All Platforms
The current flag
target_compile_features(${target_name} PUBLIC cxx_std_20)enforces C++20 features but does not perform explicit checks to ensure that all supported platforms use compilers with proper C++20 support. Based on our documentation and common requirements (GCC 10.0+, Clang 10.0+, MSVC Visual Studio 2019 16.11+), please:
- Verify that every target platform uses a compiler meeting these minimum versions.
- Consider adding or expanding explicit compiler version checks (similar to the check in
cmake/add_library_macros.cmake) to guard against using outdated compilers.- If the requirements are met by existing constraints or documented elsewhere, add inline comments to clarify how C++20 compatibility is guaranteed.
195-208:Details
❓ Verification inconclusive
Verify if the
-Wno-non-virtual-dtorflag should be PUBLIC.The current implementation marks
-Wno-non-virtual-dtoras PRIVATE, which means it won't be propagated to dependent targets. If this warning suppression is necessary for downstream consumers of the library (i.e., if they might encounter warnings when using OpenMS classes with non-virtual destructors), consider making it PUBLIC.
🏁 Script executed:
#!/bin/bash # Check if there are non-virtual destructors in public headers that might affect downstream consumers # Search for class declarations in header files that might have non-virtual destructors echo "Searching for potential classes with non-virtual destructors in public headers..." rg -l "class.*\s+\{" --type cpp --type hpp include/ | xargs rg -l "~\w+\(\)" --type cpp --type hpp | xargs rg -L "virtual\s+~" --type cpp --type hpp echo "Checking if any of these classes are exported..." rg -l "class.*\s+\{" --type cpp --type hpp include/ | xargs rg -l "~\w+\(\)" --type cpp --type hpp | xargs rg -L "virtual\s+~" --type cpp --type hpp | xargs rg -l "OPENMS_DLLAPI" --type cpp --type hppLength of output: 827
Manual Verification Required: Evaluate Visibility for Non-Virtual Destructor Warning Suppression
The initial automated search was inconclusive because the file type “hpp” wasn’t recognized. Please manually verify whether any exported OpenMS classes (especially those marked with
OPENMS_DLLAPI) in public headers have non-virtual destructors that might trigger warnings downstream. If such cases exist, the-Wno-non-virtual-dtorflag should be made PUBLIC to propagate the warning suppression. Otherwise, leaving it as PRIVATE might be acceptable.
- Action Items:
- Inspect the public header files in the
include/directory for classes with non-virtual destructors.- Verify if these classes are exported (look for
OPENMS_DLLAPIor similar markers).- Confirm whether downstream consumers could receive warnings due to non-virtual destructors.
- Consider changing the flag’s scope to PUBLIC if the warning suppression is deemed necessary for consumers.
112-116:Details
❓ Verification inconclusive
Verify the SIMD extensions configuration is comprehensive.
The SIMD configuration correctly marks these flags as PUBLIC (essential for binary compatibility), but you should verify:
- Whether
-mssse3is sufficient for all required SIMD operations- Whether additional processor-specific optimizations should be conditionally applied
- If there are any ARM-specific optimizations that could be beneficial despite the comment about SIMDe handling ARM automatically
This is especially important since these flags directly affect performance and binary compatibility.
🏁 Script executed:
#!/bin/bash # Description: Look for SIMD usage in the codebase echo "Searching for SIMD-related includes in the codebase..." rg -l "#include.*<(xmmintrin|emmintrin|pmmintrin|tmmintrin|smmintrin|nmmintrin|immintrin|arm_neon|simde)" --type cpp --type hpp echo "Checking for SIMDe-related includes..." rg -l "#include.*simde" --type cpp --type hpp echo "Looking for explicit SIMD-related functions or macros..." rg "_mm[_a-z0-9]*" --type cpp --type hppLength of output: 633
Below is a revised plan for further verification. The original review comment remains largely valid, but our initial script ran into issues with the use of the "hpp" file type. We need to re-run the SIMD search queries using glob filters rather than file type arguments. This will help us determine whether additional SIMD includes or usages exist in the codebase that might affect the decisions made in the compiler flags.
Next Steps – Please Run the Following Script for Manual Verification:
Action Items:
- Please run the above script and check if any SIMD-related includes or macros are present.
- Verify if the
-mssse3flag is indeed sufficient or if more processor-specific optimizations are required.- Consider if there are relevant ARM-specific optimizations (even though SIMDe is cited as handling ARM automatically).
Once you’ve confirmed these details from the output, you can determine if any further changes are needed.
🏁 Script executed:
#!/bin/bash # Re-run SIMD-related searches with explicit glob patterns for .cpp and .hpp files echo "Searching for SIMD-related includes (.cpp and .hpp files)..." rg -l -g "*.cpp" -g "*.hpp" '#include.*<(xmmintrin|emmintrin|pmmintrin|tmmintrin|smmintrin|nmmintrin|immintrin|arm_neon|simde)' echo "Searching for SIMDe-related includes (.cpp and .hpp files)..." rg -l -g "*.cpp" -g "*.hpp" '#include.*simde' echo "Searching for explicit SIMD functions/macros (.cpp and .hpp files)..." rg -l -g "*.cpp" -g "*.hpp" '_mm[_a-z0-9]*'Length of output: 1226
SIMD extension configuration: Verify optimization sufficiency
The current configuration correctly marks the SIMD flags as PUBLIC. However, please verify the following:
- Non-MSVC builds: Confirm that using
-mssse3on x64 is sufficient for all SIMD operations used across the codebase (e.g., see usage insrc/openms/source/SYSTEM/BuildInfo.cppand other files where SIMD macros appear). Consider whether supporting newer extensions like AVX2 might be beneficial.- MSVC builds: Ensure that
/arch:AVXaligns with the SIMD requirements observed in the source, and that it provides consistent performance and compatibility.- ARM optimizations: Although SIMDe is employed (as evidenced by its inclusion in BuildInfo.cpp), double-check if there are any opportunities for ARM-specific optimizations that could boost performance even further.
|
how about now? |
|
tested TestExternalCode and worked |
* switch to target compile flags * cleanup * add to tests * split into private and public flags * attempt to remove some outdated compile flags
* remove old mascot adapter * remove test files * update tests * fix doc * add some docs to internal classes (#7916) add some citation information * refactor: cmake use target_compile_flags (#7857) * switch to target compile flags * cleanup * add to tests * split into private and public flags * attempt to remove some outdated compile flags --------- Co-authored-by: Chris Bielow <[email protected]>
Description
Checklist
How can I get additional information on failed tests during CI
Click to expand
If your PR is failing you can check outIf you click in the column that lists the failed tests you will get detailed error messages.
Advanced commands (admins / reviewer only)
Click to expand
/reformat(experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.rebuild jenkinswill retrigger Jenkins-based CI buildsSummary by CodeRabbit
New Features
Refactor
Chores