Wireshark-dev: Re: [Wireshark-dev] Mac Build Error
From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Thu, 21 Jan 2016 16:40:48 -0800
On Jan 21, 2016, at 2:53 PM, David Morsberger <dave@xxxxxxxxxxxxxx> wrote:

>> On Jan 21, 2016, at 3:28 PM, Guy Harris <guy@xxxxxxxxxxxx> wrote:
>> 
>>> On Jan 21, 2016, at 12:10 PM, David Morsberger <dave@xxxxxxxxxxxxxx> wrote:
>>> 
>>> I think this is a bug in cmake because:
>>> 
>>> 1. the 'and run' in "CheckCSourceRuns: Check if the given C source code compiles and runs" should imply linking and executing the software.
>> 
>> Yes, and it *does* imply that.
>> 
>> The problem is that it doesn't let you cleanly specify which linker flags to use when doing the linking.
> 
> Unless cmake behaves differently based on flags and variables set, the -c option only compiles and assembles; doesn't link.

Yes - as I said, it's doing separate "compile to an object file" and "linking object files into an executable" steps; UN*X compiler drivers do both by default and need a -c flag to tell them only to do the first part (and need not to be passed any source files to tell them to only do the second part).

CHECK_C_SOURCE_RUNS(), with both Makefile and Xcode generators (and probably with other generators, especially on platforms where you can't use the same command to compile and link), do separate compile and link steps.

With the Makefile generator, both are done by running the C compiler driver, and, for both of them, the flags specified in CMAKE_REQUIRED_FLAGS are passed to the C compiler driver, so they're tested in both the compile and link stages.

With the Xcode generator, the flags specified in CMAKE_REQUIRED_FLAGS are *not* passed to whatever program is run to do the linking, whether the linking is done by running the C compiler driver without -c or by directly running the linker with all the appropriate arguments for linking object files generated by the C compiler into an executable image.

So, if we're going to be testing linker flags, we need to ensure that, with *all* generators, the flag we're testing gets passed to the linker - and probably ensure it doesn't get passed to the compiler or compiler driver in the compile stage.

This means we can't use CMAKE_REQUIRED_FLAGS, and have to find some *other* way to specify the flag to be tested.