-
Notifications
You must be signed in to change notification settings - Fork 31
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
Replace CMAKE_CXX_FLAGS with better option (warning config) #4
Comments
@Quincunx271, could you please provide or point me to something explaining why this is a bad habit even when compiler flags are needed? Will clients somehow be affected when #3 is done? And what better option did you envisage? |
First off, I am not really that experienced with CMake, but I do have an idea of what the best practices are. It's totally possible that there are better practices / reasons than what I know. If you want the library to be consumable via You could use function(scope_guard_compile_options TARGET)
target_compile_options(${TARGET}
# options go here
)
endfunction() For setting up warnings, I usually do this: target_compile_options(my-target
PRIVATE
$<$<CXX_COMPILER_ID:Gnu>:
# g++ warning flags
>
$<$<CXX_COMPILER_ID:Clang>:
# clang warning flags
>
$<$<CXX_COMPILER_ID:MSVC>:
# MSVC warning flags
>
) |
For 'best practices' from the big cmake dev's themselves see: https://cgold.readthedocs.io/en/latest/ |
@OvermindDL1: thanks again for the pointer. I did not find anything relevant to this issue there though.
Pretty much the same here. I share the impression that CMake abstractions are better than direct compiler flags in general, but I don't see an alternative here. And I looked at the time... Perhaps
Hmm, well it was not really meant for that – it is a top-level CMakeLists.txt which would require other changes anyway to be used like that. BTW, I intend to configure warnings only in the BUILD_TESTING case when #3 is done.
Again, I agree in general, but because there are usually better cmake abstractions. Perhaps
Come to think of it, |
Honestly, as long as the library is accessible via something like Hunter (or any of the other cmake dependency systems, though hunter is the only one that only requires cmake and nothing else) then it becomes trivial to use. For that I think all it needs is to be able to 'install' properly with all necessary header files and config files and such available. |
@OvermindDL1 point taken |
(issue corresponding to review suggestion here)
CMAKE_CXX_FLAGS
is used to configure compiler warnings in cmake as part of the testing procedure, (following the this advice). I am not aware of a warning API in cmake and I know of no option that does not involve passing explicit flags to the compiler. So, AFAIU, better options to configure compiler warnings would still require explicit flags.With that in mind, I see 2 contending alternatives to the current approach:
target_compile_options
on each targetadd_compile_options
onceTo be discussed. Suggestions of better options are welcome.
The text was updated successfully, but these errors were encountered: