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

Support sanitizer for C++ projects #1190

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Support sanitizer for C++ projects #1190

wants to merge 3 commits into from

Conversation

sfod
Copy link
Contributor

@sfod sfod commented Feb 21, 2025

Issue #, and/or reason for changes (REQUIRED):

aws_check_sanitizer checks for the sanitizer flags using check_c_compiler_flag. However, C language might be disabled for C++ projects, which leads to the following error:

CMake Error at /usr/share/cmake3/Modules/CheckCSourceCompiles.cmake:109 (try_compile):
  Unknown extension ".c" for file
    aws-iot-device-sdk-cpp-v2/samples/mqtt5/mqtt5_pubsub/cmake-build-tsan/CMakeFiles/CMakeTmp/src.c
  try_compile() works only for enabled languages.  Currently these are:
    CXX
  See project() command to enable other languages.

Description of changes:

Add check for C++ compiler.
Check compiler flags only if corresponding language is enabled.

If both C and C++ compilers are not loaded, no check_*_compiler_flag function will be called and sanitizer won't be enabled. In a way, it's similar to current logic: when C compiler doesn't support a specified sanitizer check, cmake simply doesn't add corresponding compiler flags.

CMAKE_CXX_COMPILER_LOADED and CMAKE_C_COMPILER_LOADED are available since at least CMake 3.0.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-commenter
Copy link

codecov-commenter commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.21%. Comparing base (9fd58f9) to head (a44818e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1190   +/-   ##
=======================================
  Coverage   84.21%   84.21%           
=======================================
  Files          57       57           
  Lines        5973     5973           
=======================================
  Hits         5030     5030           
  Misses        943      943           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Successfully merging this pull request may close these issues.

3 participants