Windows: Add sccache support.
authorRay Molenkamp <github@lazydodo.com>
Mon, 20 Apr 2020 18:51:43 +0000 (12:51 -0600)
committerRay Molenkamp <github@lazydodo.com>
Mon, 20 Apr 2020 18:51:43 +0000 (12:51 -0600)
sccache [1] is one of the few ccache like solutions that will
work on windows.

sccache support can be enabled with the `WITH_WINDOWS_SCCACHE`
cmake option however it will only will work with ninja as the
build system, msbuild is not supported currently.

Advanced option, developes are expected to obtain and configure
sccache on their own.

```
Full build no cache 1428.90s (100.00%)
Full build cached    434.34s ( 30.40%)
```

[1] https://github.com/mozilla/sccache

Reviewed By: nicholas_rishel, Brecht

Differential Revision: https://developer.blender.org/D7466

CMakeLists.txt
build_files/cmake/platform/platform_win32.cmake
build_files/windows/configure_msbuild.cmd
build_files/windows/configure_ninja.cmd
build_files/windows/parse_arguments.cmd
build_files/windows/reset_variables.cmd

index 8b70b4252fa121b7e7b5b5639e244d45fe49ef1c..b6b271c80853a1e3a621a1aea8d037e7f268a75f 100644 (file)
@@ -536,6 +536,9 @@ if(WIN32)
   option(WITH_WINDOWS_BUNDLE_CRT "Bundle the C runtime for install free distribution." ON)
   mark_as_advanced(WITH_WINDOWS_BUNDLE_CRT)
 
+  option(WITH_WINDOWS_SCCACHE "Use sccache to speed up builds (Ninja builder only)" OFF)
+  mark_as_advanced(WITH_WINDOWS_SCCACHE)
+
 endif()
 
 # The following only works with the Ninja generator in CMake >= 3.0.
index 1ecde8635c882bbd11c66d1387cfe9a632c9105c..f882ff6238bb06846626e5398639f8219934ad67 100644 (file)
@@ -134,7 +134,7 @@ add_definitions(-D_ALLOW_KEYWORD_MACROS)
 # We want to support Windows 7 level ABI
 add_definitions(-D_WIN32_WINNT=0x601)
 include(build_files/cmake/platform/platform_win32_bundle_crt.cmake)
-remove_cc_flag("/MDd" "/MD")
+remove_cc_flag("/MDd" "/MD" "/Zi")
 
 if(MSVC_CLANG) # Clangs version of cl doesn't support all flags
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_WARN_FLAGS} /nologo /J /Gd /EHsc -Wno-unused-command-line-argument -Wno-microsoft-enum-forward-reference ")
@@ -151,16 +151,30 @@ if(MSVC_VERSION GREATER 1911 AND NOT MSVC_CLANG)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:twoPhase-")
 endif()
 
+if(WITH_WINDOWS_SCCACHE AND CMAKE_VS_MSBUILD_COMMAND)
+    message(WARNING "Disabling sccache, sccache is not supported with msbuild")
+    set(WITH_WINDOWS_SCCACHE Off)
+endif()
 
-set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /ZI")
-set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MDd /ZI")
+if(WITH_WINDOWS_SCCACHE)
+    set(CMAKE_C_COMPILER_LAUNCHER sccache)
+    set(CMAKE_CXX_COMPILER_LAUNCHER sccache)
+    set(SYMBOL_FORMAT /Z7)
+else()
+    unset(CMAKE_C_COMPILER_LAUNCHER)
+    unset(CMAKE_CXX_COMPILER_LAUNCHER)
+    set(SYMBOL_FORMAT /ZI)
+endif()
+
+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd ${SYMBOL_FORMAT}")
+set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MDd ${SYMBOL_FORMAT}")
 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MD")
 set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MD")
 set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /MD")
 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MD")
 set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MD")
-
+unset(SYMBOL_FORMAT)
 # JMC is available on msvc 15.8 (1915) and up
 if(MSVC_VERSION GREATER 1914 AND NOT MSVC_CLANG)
   set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /JMC")
@@ -209,7 +223,7 @@ endif()
 
 # Mark libdir as system headers with a lower warn level, to resolve some warnings
 # that we have very little control over
-if(MSVC_VERSION GREATER_EQUAL 1914 AND NOT MSVC_CLANG)
+if(MSVC_VERSION GREATER_EQUAL 1914 AND NOT MSVC_CLANG AND NOT WITH_WINDOWS_SCCACHE)
   add_compile_options(/experimental:external /external:templates- /external:I "${LIBDIR}" /external:W0)
 endif()
 
index 3c1194011cd09c8b3c8dba6b0301692a26a7eab9..4956f1e3ea1c91107620aceb7dedc2f86d44d4fe 100644 (file)
@@ -2,6 +2,11 @@ set BUILD_GENERATOR_POST=
 set BUILD_PLATFORM_SELECT=
 set MSBUILD_PLATFORM=x64
 
+if "%BUILD_WITH_SCCACHE%"=="1" (
+               echo sccache is only supported with ninja as the build system. 
+               exit /b 1 
+)
+
 if "%WITH_CLANG%"=="1" (
        set CLANG_CMAKE_ARGS=-T"llvm"
        if "%WITH_ASAN%"=="1" (
index 1650e43cda9ff4ac0405b91f0ecb1021fb4c0fe1..20692847bef7bc4413b1e1ac2a18978b1d13e08a 100644 (file)
@@ -6,6 +6,13 @@ if %ERRORLEVEL% NEQ 0 (
 
 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% -G "Ninja" %TESTS_CMAKE_ARGS% -DCMAKE_BUILD_TYPE=%BUILD_TYPE%
 
+if "%BUILD_WITH_SCCACHE%"=="1" (
+       set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% -DWITH_WINDOWS_SCCACHE=On
+       if NOT "%verbose%" == "" (
+               echo Enabling sccache
+       )
+)
+
 if "%WITH_CLANG%" == "1" (
 set LLVM_DIR=
        for /F "usebackq skip=2 tokens=1-2*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\LLVM\LLVM" /ve 2^>nul`) DO set LLVM_DIR=%%C
index 4ee05bfde7d8bd3d3d2215730735be2ca61b3750..54dc41ece87943ce52213e30bb70adbc6b7700c2 100644 (file)
@@ -86,6 +86,8 @@ if NOT "%1" == "" (
                set BUILD_UPDATE_ARGS="--no-libraries"
        ) else if "%1" == "ninja" (
                SET BUILD_WITH_NINJA=1
+       ) else if "%1" == "sccache" (
+               SET BUILD_WITH_SCCACHE=1
        ) else if "%1" == "clean" (
                set MUST_CLEAN=1
        ) else if "%1" == "verbose" (
index 48a61aff44ae9fd8cbdece7e4541cfbbee84e0b1..262874713ebe96184b575b8f059576768ab68c68 100644 (file)
@@ -30,3 +30,4 @@ set WITH_PYDEBUG=
 set PYDEBUG_CMAKE_ARGS=
 set FORMAT=
 set TEST=
+set BUILD_WITH_SCCACHE=