CMAKE_SHARED_LINKER_FLAGS and "-Wl,..." in CMake 4.0.0

I have recently tried CMake 4.0.0 on my source code. We have a setting like this:

set(CMAKE_SHARED_LINKER_FLAGS
      "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath=\\\$ORIGIN,-rpath=\\\$ORIGIN/../../common/bin")

With CMake 3.31.6 this will give me the correct RUNPATH in the shared library, but not with 4.0.0:

  RUNPATH              $ORIGIN:$ORIGIN/../../common/bin      # with cmake 3.31.6
  RUNPATH              :/../../common/bin             # with cmake 4.0.0

I have also noticed that any ot the following changes makes using the cmake 4.0.0 case work again:

  • if I use “cmake_minimum_required(VERSION 4.0)” instead of the current value of 3.31
  • if I use the Makefile generator instead of Ninja

Should this be considered a bug in 4.0.0 ?

For my project, I will change to using the variables CMAKE_INSTALL_RPATH and CMAKE_BUILD_WITH_INSTALL_RPATH. Then I can avoid the problems described here altogether.

I just wanted to mention the change in behaviour in case you consider it a bug in 4.0.0. I guess it would be good if using cmake 4.0.0 on a project with cmake_minimum_required(VERSION 3.31) continued to work as before.

@marc.chevrier Any chance this is related to the work for CMP0181? That seems very likely, given that it relates to handling of escaping in the linker flags variables.

I am able to reproduce it. I think @craig.scott is right: it seems linked to the change of behavior controlled by policy CMP0181.

@johan556 Can you create an issue including the same text? Thanks.

Done now as https://gitlab.kitware.com/cmake/cmake/-/issues/26857