Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

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

From: Roland Knall <rknall@xxxxxxxxx>
Date: Fri, 22 Jan 2016 06:36:51 +0100


On Fri, Jan 22, 2016 at 1:40 AM, Guy Harris <guy@xxxxxxxxxxxx> wrote:

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

FYI, the only sure-fire way in CMAKE to set specific only linker flags is using the target properties. The following code modifies target properties for a specific target, but first collects existing flags, to not overwrite those:

    GET_TARGET_PROPERTY(TARGET_COMPILE_FLAGS <TargetExeName> COMPILE_FLAGS )
    GET_TARGET_PROPERTY(TARGET_LINK_FLAGS <TargetExeName> LINK_FLAGS )

    SET( TARGET_COMPILE_FLAGS "${TARGET_COMPILE_FLAGS} -D<something> " )
    SET( TARGET_LINK_FLAGS "${TARGET_LINK_FLAGS} -W<something> " )

    SET_TARGET_PROPERTIES(<TargetExeName> PROPERTIES COMPILE_FLAGS ${TARGET_COMPILE_FLAGS} LINK_FLAGS ${TARGET_LINK_FLAGS} )

<TargetExeName> is the same name, that get's passed to ADD_EXECUTABLE or ADD_LIBRARY for linkage, so in case of wsutil or wireshark it would be exactly that (without any lib... or .dylib stuff).

This works in 9 out of 10 cases on all 3 major plattforms. In my experience it depends on what is called, and when, and most likely fails with MSVC.

regards
Roland