[CMake] Where do all the extra clang flags come from in Xcode?

Andreas Pakulat apaku at gmx.de
Mon May 18 11:09:15 EDT 2015


Hi Paul,

On Mon, May 18, 2015 at 3:20 PM, Paul Smith <paul at mad-scientist.net> wrote:

> On Mon, 2015-05-18 at 12:32 +0200, Ruslan Baratov via CMake wrote:
> > This table tells you what attribute you need to set to disable/enable
> > specific warning.
>
> I see, so these are CMake attributes?  That wasn't clear to me.  I
> thought they were attributes of Xcode.
>
> I guess my basic question is, why are all these extra flags to disable
> and enable various warnings set in the Xcode generator?  I expected it
> would work like the makefile generator, where if you don't set any flags
> in CMakeLists.txt then you don't get any warnings enabled (or explicitly
> disabled).  It surprises me that when I take the same CMakeLists.txt
> file and use a Makefile generator and an Xcode generator, I get very
> different compile lines.
>

If you look at the foo.xcodeproj contents of a very simple CMake project
(hello-world style) you'll notice just 1 file and there are not a lot of -W
words inside that file either. I see 3 warnings being added by CMake when
generating this file.

That suggests anything else is added by Xcode itself because thats what its
default settings are. Xcode (and xcodebuild) has a lot more logics builtin
that make. Make is essentially just a dependency-tracking and execution
tool and thus cannot make any assumptions about what is being executed when
a target is to be 'made'. It cannot add any compile flags that the
make-developers deem useful, since the action executed for a target may not
be a compile run at all. Xcode on the other hand with its more structured
project file has a very clear idea of what is a compile action and what is
not and apparently the Apple devs think a certain set of flags are useful
for everybody and hence are added to all compiler invocations.

You'll also notice this when creating a new project inside xcode and then
examine and run it outside, i.e. grep for -W flags in the generated files.
There are  literally none, but still xcodebuild shows tons of -W flags
added to the compiler invocation.


> And secondarily, is there any way to get the Xcode generator to work
> like the Makefile generator, where only the warning flags I explicitly
> defined in my CMakeLists.txt file are added to the compile/link lines
> and no others?
> <http://cmake.org/cmake/help/consulting.html>
>

Given the above, your only options are: propose a patch to cmake (or find
someone to do this for you) that enhances the xcode generator to disable
all flags that are not explicitly enabled so its closer to the makefile
generator. This is however quite a lot of effort upfront and in maintenance
since each new xcode version (even just bugfix versions) may need changes
to the list.

The alternative to that is that you blacklist via the mentioned attributes
the warnings you don't want to have enabled, each and every one of them
individually.

Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150518/99b19724/attachment-0001.html>


More information about the CMake mailing list