From a53ae124aefdbbc1c9321c74484cf9cf79ec053a Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 13 Jul 2023 12:58:57 +0100 Subject: [PATCH 1/4] [FIXUP] Use Multi-ToolTask in MSVC builds by default It allows to build as simple as `cmake --build . -j`. --- CMakeLists.txt | 3 +++ cmake/optional.cmake | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 827ea7c24543c..8731f56579772 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,6 +102,9 @@ if(WIN32) if(MSVC) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") add_compile_options(/utf-8 /Zc:__cplusplus) + # Improve parallelism in MSBuild. + # See: https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/. + list(APPEND CMAKE_VS_GLOBALS "UseMultiToolTask=true") endif() if(MINGW) diff --git a/cmake/optional.cmake b/cmake/optional.cmake index e018a47f73725..c654aa3f65b7b 100644 --- a/cmake/optional.cmake +++ b/cmake/optional.cmake @@ -13,11 +13,10 @@ if(CCACHE) set(MSVC_CCACHE_WRAPPER_CONTENT "\"${CCACHE_EXECUTABLE}\" \"${CMAKE_CXX_COMPILER}\"") set(MSVC_CCACHE_WRAPPER_FILENAME wrapped-cl.bat) file(WRITE ${CMAKE_BINARY_DIR}/${MSVC_CCACHE_WRAPPER_FILENAME} "${MSVC_CCACHE_WRAPPER_CONTENT} %*") - set(CMAKE_VS_GLOBALS + list(APPEND CMAKE_VS_GLOBALS "CLToolExe=${MSVC_CCACHE_WRAPPER_FILENAME}" "CLToolPath=${CMAKE_BINARY_DIR}" "TrackFileAccess=false" - "UseMultiToolTask=true" "DebugInformationFormat=OldStyle" ) else() From 2fd67c7aca1ab6717a1e9b3f893b69a52d54dc7c Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 13 Jul 2023 13:00:35 +0100 Subject: [PATCH 2/4] [FIXUP] Do not disable `TrackFileAccess` in MSVC builds --- cmake/optional.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/optional.cmake b/cmake/optional.cmake index c654aa3f65b7b..594cecaa1a181 100644 --- a/cmake/optional.cmake +++ b/cmake/optional.cmake @@ -16,7 +16,6 @@ if(CCACHE) list(APPEND CMAKE_VS_GLOBALS "CLToolExe=${MSVC_CCACHE_WRAPPER_FILENAME}" "CLToolPath=${CMAKE_BINARY_DIR}" - "TrackFileAccess=false" "DebugInformationFormat=OldStyle" ) else() From 0476509f4b5df808fdae10463a79bb862e7eb1db Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 13 Jul 2023 13:27:46 +0100 Subject: [PATCH 3/4] [FIXUP] Learn to work with recent ccache in MSVC builds --- cmake/optional.cmake | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/cmake/optional.cmake b/cmake/optional.cmake index 594cecaa1a181..496307b2fb3c1 100644 --- a/cmake/optional.cmake +++ b/cmake/optional.cmake @@ -7,18 +7,29 @@ if(CCACHE) find_program(CCACHE_EXECUTABLE ccache) if(CCACHE_EXECUTABLE) - set(CCACHE ON) if(MSVC) - # See https://github.com/ccache/ccache/wiki/MS-Visual-Studio - set(MSVC_CCACHE_WRAPPER_CONTENT "\"${CCACHE_EXECUTABLE}\" \"${CMAKE_CXX_COMPILER}\"") - set(MSVC_CCACHE_WRAPPER_FILENAME wrapped-cl.bat) - file(WRITE ${CMAKE_BINARY_DIR}/${MSVC_CCACHE_WRAPPER_FILENAME} "${MSVC_CCACHE_WRAPPER_CONTENT} %*") - list(APPEND CMAKE_VS_GLOBALS - "CLToolExe=${MSVC_CCACHE_WRAPPER_FILENAME}" - "CLToolPath=${CMAKE_BINARY_DIR}" - "DebugInformationFormat=OldStyle" - ) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) + # ccache >= 4.8 requires compile batching turned off that is available since CMake 3.24. + # See https://github.com/ccache/ccache/wiki/MS-Visual-Studio + set(CCACHE ON) + set(MSVC_CCACHE_WRAPPER_CONTENT "\"${CCACHE_EXECUTABLE}\" \"${CMAKE_CXX_COMPILER}\"") + set(MSVC_CCACHE_WRAPPER_FILENAME wrapped-cl.bat) + file(WRITE ${CMAKE_BINARY_DIR}/${MSVC_CCACHE_WRAPPER_FILENAME} "${MSVC_CCACHE_WRAPPER_CONTENT} %*") + list(APPEND CMAKE_VS_GLOBALS + "CLToolExe=${MSVC_CCACHE_WRAPPER_FILENAME}" + "CLToolPath=${CMAKE_BINARY_DIR}" + "DebugInformationFormat=OldStyle" + ) + set(CMAKE_VS_NO_COMPILE_BATCHING ON) + elseif(CCACHE STREQUAL "AUTO") + message(WARNING "ccache requested and found, but CMake >= 3.24 is required to use it properly. Disabling.\n" + "To skip ccache check, use \"-DCCACHE=OFF\".\n") + set(CCACHE OFF) + else() + message(FATAL_ERROR "ccache requested and found, but CMake >= 3.24 is required to use it properly.") + endif() else() + set(CCACHE ON) list(APPEND CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE}) list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE}) endif() From ac7bc5b3c8aad028646644d0e00e34d36c9fa98c Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 13 Jul 2023 13:31:17 +0100 Subject: [PATCH 4/4] [FIXUP] Rename CCACHE_EXECUTABLE --> CCACHE_COMMAND for consistency Other cases: - CMAKE_COMMAND - PYTHON_COMMAND - BREW_COMMAND --- cmake/optional.cmake | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmake/optional.cmake b/cmake/optional.cmake index 496307b2fb3c1..af91f609758f1 100644 --- a/cmake/optional.cmake +++ b/cmake/optional.cmake @@ -5,14 +5,14 @@ # Optional features and packages. if(CCACHE) - find_program(CCACHE_EXECUTABLE ccache) - if(CCACHE_EXECUTABLE) + find_program(CCACHE_COMMAND ccache) + if(CCACHE_COMMAND) if(MSVC) if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) # ccache >= 4.8 requires compile batching turned off that is available since CMake 3.24. # See https://github.com/ccache/ccache/wiki/MS-Visual-Studio set(CCACHE ON) - set(MSVC_CCACHE_WRAPPER_CONTENT "\"${CCACHE_EXECUTABLE}\" \"${CMAKE_CXX_COMPILER}\"") + set(MSVC_CCACHE_WRAPPER_CONTENT "\"${CCACHE_COMMAND}\" \"${CMAKE_CXX_COMPILER}\"") set(MSVC_CCACHE_WRAPPER_FILENAME wrapped-cl.bat) file(WRITE ${CMAKE_BINARY_DIR}/${MSVC_CCACHE_WRAPPER_FILENAME} "${MSVC_CCACHE_WRAPPER_CONTENT} %*") list(APPEND CMAKE_VS_GLOBALS @@ -30,15 +30,15 @@ if(CCACHE) endif() else() set(CCACHE ON) - list(APPEND CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE}) - list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE}) + list(APPEND CMAKE_C_COMPILER_LAUNCHER ${CCACHE_COMMAND}) + list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_COMMAND}) endif() elseif(CCACHE STREQUAL "AUTO") set(CCACHE OFF) else() message(FATAL_ERROR "ccache requested, but not found.") endif() - mark_as_advanced(CCACHE_EXECUTABLE) + mark_as_advanced(CCACHE_COMMAND) endif() if(WITH_NATPMP)