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

Targets using only target_sources don't get sanitizer flags #25

Open
GHF opened this issue Feb 4, 2019 · 1 comment
Open

Targets using only target_sources don't get sanitizer flags #25

GHF opened this issue Feb 4, 2019 · 1 comment

Comments

@GHF
Copy link

GHF commented Feb 4, 2019

With CMake 3.13, I've been writing a bunch of targets like this, where the SOURCES property of a target can be added by subdirectories and its evaluation is deferred to "generation time."

add_executable(myexecutable)
target_sources(myexecutable PRIVATE main.cc)

Unfortunately, this makes these targets incompatible with add_sanitizers(...) because the scripts are not able to find any source files in the target:

CMake Warning at third_party/sanitizers-cmake/cmake/FindSanitizers.cmake:82 (message):
  Sanitizers for target myexecutable may not be usable, because it uses no or an
  unknown compiler.  This is a false warning for targets using only object
  lib(s) as input.
Call Stack (most recent call first):
  CMakeLists.txt:35 (add_sanitizers)

I'm pretty new to "modern" CMake and I don't know how to get around this. Maybe the compiler flags added by sanitizer_add_flags need to be generator expressions that get evaluated at generation time?

@saxbophone
Copy link

saxbophone commented Mar 12, 2023

Hmmm, interesting —I wonder if this same issue might be why I can't seem to get the sanitisers provided by this package to fail my CI builds? saxbophone/arby#153

I am also using target_sources(), although IIRC I'm not getting a build warning or error, and when compiling it does appear to be using libasan/ubsan, but I can't seem to deliberately fail the build by introducing undefined behaviour into my code:

int k = 0x7fffffff;
k += 1; // cause integer overflow

which makes this pretty useless for actually detecting any UB...

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