How can I apply the target compile options only to the code I’ve written and not to dependencies?
I depend on a large project (tensorflow) and its code doesn’t compile with options such -Wall -Werror. I want the code I’ve written, however, to compile only without any warnings. How can I do that?
The relevant CmakeLists.txt file is:
I’ve wondered a few times how I can not enforce the compile options for my target to any dependencies, but in effect only resolved that by lowering the settings for my code.
Don’t apply settings via global variables, but via commands that apply only to your target.
That means not setting variables like CMAKE_CXX_FLAGS, etc., and it also means not calling functions that apply settings globally to all targets like add_compile_definitions (use target_compile_definitions), etc.
If you have a bunch of targets that should receive the same settings, write a function that applies those settings to a target and call the function for each such target to avoid duplication.
Additionally: vcpkg manages dependencies and keeps them completely separate from anything you do in your project by building the dependencies at the time add_project is called, if you use toolchain integration. Due to the way FetchContent works, it builds the fetched dependencies as if they were part of your code so there is coupling of compilation options between the two.
Thanks, @LegalizeAdulthood! I’m not sure you answers fully addresses my question. My question might have been too vague.
Currently, the dependency tensorflow-lite fails to compile, because the compilation applies the Werror option. I am suprised by this. I expected Werror only to apply to main.cpp (test_app) and not apply to the linked libraries. Globally, I only set the O2 option.
What can I do to set the Werror option for the code I have written, but not apply to tensorflow-lite?
I believe your last point “Additionally…” implies that I would need vcpkg to have a clean separation of the settings?
If you don’t mind: would you be willing to explain the meaning of “SYSTEM” to me? I read the docs of FetchContent_Declare and the SYSTEM keyword, (see SYSTEM) but I cannot wrap my head around its meaning.
The most important aspect here is that the include path to the headers of tensorflow-lite will be treated as system includes - meaning they’ll produce no warnings, thus -Werror will have no effect on them.
I use SYSTEM quite often on third-party libraries, because many of them are a bit more lenient in regard to warning/error settings, than my code.