ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
July 17th, 2024 | 10:00am-11:55am SGT (UTC+8) | Online

Wireshark-dev: Re: [Wireshark-dev] Mac Build Error

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Tue, 26 Jan 2016 00:33:29 -0800
On Jan 25, 2016, at 4:39 PM, David Morsberger <dave@xxxxxxxxxxxxxx> wrote:

> After a detailed analysis of cmake, I believe this is the solution and not just fixing the symptom. 
> 
> cmake uses /usr/bin/xcodebuild when using -G Xcode. The internal behavior of cmake is significantly different when using xcodebuild in contrast to generating Unix makefiles. Specifically, try_run used by CHECK_C_SOURCE_RUNS and try_compile used by CHECK_C_SOURCE_COMPILES do not use the environment variables in the same way when using the Xcode Generator.

To which environment variables are you referring?  When I was looking at this, I wasn't setting *any* environment variables; are you saying that CMake passes some flags to the build tools by setting environment variables rather than by passing them on the command line? (CMAKE_REQUIRED_FLAGS is a CMake variable, not an environment variable; that, or something constructed from that such as the COMPILE_DEFINITIONS parameter, appears to be what's being handled differently by different generators. It *is* handled correctly by try_compile, and by the compile stage of try_run - i.e., the flags are passed to the compiler driver in that stage - but not by the link stage of try_run for Xcode, although it is passed to the compiler driver by the link stage of try_run for Unix makefiles.)

> Guy, the normal behavior of CHECK_C_SOURCE_RUNS for Unix makefiles will check linker flags because it does attempt to link and run the resulting executable.

The normal behavior of CHECK_C_SOURCE_RUNS for *all* generators attempts to link and run the resulting executable (except when cross-compiling, obviously); that's not a difference between Unix makefiles and Xcode.  That's why the name ends with "_RUNS".

The problem is that the flags specified by CMAKE_REQUIRED_FLAGS aren't being passed to the compiler driver in the link stage with the Xcode generator, so they're not *getting* tested by the link-and-run stage.

> This is why ‘—-as-needed' fails when using basic make.

The underlying problem is

	https://public.kitware.com/Bug/view.php?id=15934

I have not yet looked deeply enough into the CMake source to see why setting CMAKE_REQUIRED_FLAGS affects the link stage with the Unix makefile generator but not with the Xcode generator.  I've given up on waiting for anybody from Kitware or anybody else to answer the email I sent to the list, so I filed the bug in question and will wait for somebody to answer the bug (hopefully with something more useful than "you're holding it wrong").

For now, I've removed all the code that attempts to find out whether a given linker flag works, as there doesn't appear to be a generator-independent way of testing linker flags (i.e., there doesn't appear to be a way to do it in a fashion that works in the use case of CMake - if all you have to support is Unix makefiles, there's already a fine set of tools for that:

	http://www.gnu.org/software/autoconf/manual/autoconf.html

	https://www.gnu.org/software/automake/manual/automake.html

What makes CMake interesting is its ability to handle *other* build systems, such as nmake, Xcode, Visual Studio, etc.).