catchorg / Catch2

A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch)
https://discord.gg/4CWS9zD
Boost Software License 1.0
18.65k stars 3.05k forks source link

Compile Time Improvements #2894

Open WillisMedwell opened 3 months ago

WillisMedwell commented 3 months ago

Description Sort the sources in the src/CmakeLists.txt by compile times. When doing parallel builds in conjunction with unity builds it makes sense to have the biggest sources first.

Additional context When building the lib, msvc generated projects should specify c++17. This is because, for c++20 msvc does a prepass search for module dependencies but this can double the compile times and it doesn't need to do this.

If we were really serious about improving compile times... Instead of just compiling all files individually or using cmake's unity build generated files, I would create 4 source files that included the actual sources. This would allow maintainers to distribute the sources so that each custom source file would compile in roughly the same time. And the reason to use 4 source files is coz most people have at least 4 threads.

WillisMedwell commented 3 months ago

Im on a 8 thread system and these few lines improved compile times from 1minute & 10 secs to 10secs.

if(MSVC)
    target_compile_options(Catch2 PUBLIC /MP)
endif()

target_compile_features(Catch2 PRIVATE cxx_std_17)
set_target_properties(Catch2
PROPERTIES
    UNITY_BUILD ON
    UNITY_BUILD_BATCH_SIZE 25
)

But I think with a little bit of effort it could easily get down to 5 secs for most systems