mozilla / sccache

Sccache is a ccache-like tool. It is used as a compiler wrapper and avoids compilation when possible. Sccache has the capability to utilize caching in remote storage environments, including various cloud storage options, or alternatively, in local storage.
Apache License 2.0
5.85k stars 552 forks source link

CMAKE_MSVC_DEBUG_INFORMATION_FORMAT=Embedded CMAKE_POLICY_CMP0141=NEW doesn't seem to work #2244

Closed hjyamauchi closed 3 months ago

hjyamauchi commented 3 months ago

I'm trying to use sccache with cmake 3.29.3 on Windows and despite what the usage doc says, neither

set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT Embedded)
cmake_policy(SET CMP0141 NEW)

or

cmake -DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=Embedded -DCMAKE_POLICY_CMP0141=NEW

seem to actually do the /Zi -> /Z7 conversion and the build still fails for me.

But adding

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
  string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
  string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
  string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
  string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
  string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
endif()

to the top-level CMakeLists.txt, it seems to work.

Am I using it wrong?

AJIOB commented 3 months ago

Hi @hjyamauchi,

Do you have some hardcoded MSVC flags in your code, such as /Zi? If yes, remove it, please.

hjyamauchi commented 3 months ago

Hi @AJIOB,

Possible. The code I'm building is LLVM. I'm not very clear on what's going on but this line seems to add /Zi. But as this seems to happen with CMAKE_BUILD_TYPE=RelWithDebInfo, too, I am not sure why.

My interpretation of the above doc was that passing -DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=Embedded -DCMAKE_POLICY_CMP0141=NEW is equivalent to adding the above cmake code that replaces /Zi with /Z7, but perhaps that's my misunderstanding?

AJIOB commented 3 months ago

Hi @hjyamauchi,

Yes, you're not fully correct.

CMake itself generates some flags for compiler & linker. CMAKE_MSVC_DEBUG_INFORMATION_FORMAT=Embedded and CMAKE_POLICY_CMP0141=NEW arguments configures that.

But you still may add this flag manually (or via toolchain configuration scripts). In this way, you need to use an old-style variant with just hard replacing.

hjyamauchi commented 3 months ago

@AJIOB Thanks for clarification! CC @compnerd