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

Wireshark-dev: [Wireshark-dev] cmake, linker flags, whitespace, cmp0004

From: Martin Kaiser <lists@xxxxxxxxx>
Date: Sun, 17 Apr 2016 15:14:32 +0200
Hi,

I'm getting strange cmake errors on Debian Wheezy (cmake 2.8.9).

-- Performing Test WS_LD_FLAG_VALID0
CMake Error at CMakeLists.txt:11 (ADD_EXECUTABLE):
  Target "cmTryCompileExec701976172" links to item " -Wl,--as-needed" which
  has leading or trailing whitespace.  This is now an error according to
  policy CMP0004.


CMake Error: Internal CMake error, TryCompile generation of cmake failed
-- Performing Test WS_LD_FLAG_VALID0 - Failed
statuscheck linker flag - test linker flags: -pie
-- Performing Test WS_LD_FLAG_VALID1
CMake Error at CMakeLists.txt:11 (ADD_EXECUTABLE):
  Target "cmTryCompileExec2930916065" links to item " -pie" which has leading
  or trailing whitespace.  This is now an error according to policy
CMP0004.

CMake Error: Internal CMake error, TryCompile generation of cmake failed



Apparently, cmake doesn't like leading whitespace in linker options. I
tried setting the CMP0004 policy to the old behaviour which is not
ignore the whitespace.

cmake_policy(SET CMP0004 OLD)

This doesn't fix things. Google results show that this is in fact a bug
in cmake's parsing.

KDE discovered the bug in their build
http://comments.gmane.org/gmane.comp.kde.devel.buildsystem/7858

Cmake fixed it here
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e65ef08b


I tried to work around this by removing whitespace from the linker flags
or applying a regexp replace on the final list of linker flags.
None of this produced a clean and readable solution.

Does anyone more familiar with cmake have a recommendation how to fix
this properly?

Thanks,
Martin