ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
April 17th, 2024 | 14:30-16:00 SGT (UTC+8) | Online

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

From: David Morsberger <dave@xxxxxxxxxxxxxx>
Date: Mon, 25 Jan 2016 19:39:56 -0500

On Jan 20, 2016, at 12:02 PM, Stig Bjørlykke <stig@xxxxxxxxxxxxx> wrote:

On Wed, Jan 20, 2016 at 3:48 PM, David Morsberger <dave@xxxxxxxxxxxxxx> wrote:
My current workaround is the following change to CMakeLists.txt :
-if(NOT CMAKE_C_COMPILER_ID MATCHES "MSVC")
+if(NOT (CMAKE_C_COMPILER_ID MATCHES "MSVC" OR XCODE))
 	set(WIRESHARK_LD_FLAGS
 		-Wl,--as-needed

This is more like fixing the symptom, right?
The real issue here is that CMake finds support for the flags while building with Xcode does not.


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.

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. This is why ‘—-as-needed' fails when using basic cmake. 

I hope I never have to reverse engineer cmake in the future.

David