diff --git a/CMakeLists.txt b/CMakeLists.txt index 78dd2586da..5620875d4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,6 +110,7 @@ option(SLIC3R_WARNINGS "Emit compiler warnings for OrcaSlicer sources" option(SLIC3R_BUNDLED_WARNINGS "Emit compiler warnings for bundled third-party sources" 0) option(SLIC3R_MSVC_COMPILE_PARALLEL "Compile on Visual Studio in parallel" 1) option(SLIC3R_MSVC_PDB "Generate PDB files on MSVC in Release mode" 1) +option(SLIC3R_RELATIVE_DEBUG_PATHS "Record a relative compilation directory in debug info (clang-cl)" 0) option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0) # Python stubgen module @@ -352,11 +353,14 @@ if (MSVC) add_compile_options(/Zc:lambda) endif () # /bigobj (Increase Number of Sections in .Obj file) + add_compile_options(-bigobj) # error C3859: virtual memory range for PCH exceeded; please recompile with a command line option of '-Zm90' or greater # Generate symbols at every build target, even for the release. # -Zm520 fixes error C3859 but forces the compiler to pre-allocate that memory for every translation unit regardless # combining /Zi with /FS frees up a significant amount of memory pressure across all parallel compile jobs and makes /MP faster overall. - add_compile_options(-bigobj /Zi /FS) + if (SLIC3R_MSVC_PDB) + add_compile_options(/Zi /FS) + endif () # Disable STL4007: Many result_type typedefs and all argument_type, first_argument_type, and second_argument_type typedefs are deprecated in C++17. #FIXME Remove this line after eigen library adapts to the new C++17 adaptor rules. add_compile_options(-D_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING) @@ -374,6 +378,16 @@ if (MSVC) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /LTCG") endif () +# Without this every object names its build directory and two worktrees never +# share cache entries. The linker still writes absolute paths into the PDB. +if (SLIC3R_RELATIVE_DEBUG_PATHS) + if (IS_CLANG_CL) + add_compile_options(-ffile-compilation-dir=.) + else () + message(WARNING "SLIC3R_RELATIVE_DEBUG_PATHS is only implemented for clang-cl") + endif () +endif () + if (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang" AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER 15) add_compile_definitions(BOOST_NO_CXX98_FUNCTION_BASE _HAS_AUTO_PTR_ETC=0) endif() diff --git a/build_win.bat b/build_win.bat index 840279e4f3..dfb30e313b 100644 --- a/build_win.bat +++ b/build_win.bat @@ -699,7 +699,8 @@ if "%build_slicer%" == "ON" ( ) if not "!cache_args!" == "" ( - set "slicer_args=!slicer_args! !cache_args!" + REM Relative debug paths as well, so another tree can reuse the objects. + set "slicer_args=!slicer_args! !cache_args! -DSLIC3R_RELATIVE_DEBUG_PATHS=ON" ) REM Configuring against a tree that was never built fails deep inside diff --git a/scripts/test_build_win.ps1 b/scripts/test_build_win.ps1 index 34f64117af..a8abfbc7bf 100644 --- a/scripts/test_build_win.ps1 +++ b/scripts/test_build_win.ps1 @@ -360,6 +360,12 @@ $cases = @( @{ Name = '--cache turns the precompiled header off'; Args = @('-s', '-l', '-x', '--cache', 'ccache') Env = @{ PATH = $ccacheOnPath } Contains = @('-DSLIC3R_PCH=OFF', 'COMPILER_LAUNCHER') } + # Without it the objects name the build directory and only that tree can use them. + @{ Name = '--cache asks for relative debug paths'; Args = @('-s', '-l', '-x', '--cache', 'ccache') + Env = @{ PATH = $ccacheOnPath } + Contains = @('-DSLIC3R_RELATIVE_DEBUG_PATHS=ON') } + @{ Name = 'no --cache leaves the debug paths alone'; Args = @('-s', '-l', '-x') + NotContains = @('SLIC3R_RELATIVE_DEBUG_PATHS') } # The resolved path, not the bare name, so PATH cannot change it later. @{ Name = '--cache names the resolved path in the banner'; Args = @('-s', '-l', '-x', '--cache', 'ccache') Env = @{ PATH = $ccacheOnPath }