Closed romintomasetti closed 5 months ago
If you build benchmark
as a cmake sub-project (see https://github.com/google/benchmark/blob/e990563876ef92990e873dc5b479d3b79cda2547/cmake/GoogleTest.cmake + https://github.com/google/benchmark/blob/e990563876ef92990e873dc5b479d3b79cda2547/CMakeLists.txt#L344),
you should just do
add_subdirectory(${GOOGLETEST_SOURCE_DIR}
${GOOGLETEST_BINARY_DIR}
EXCLUDE_FROM_ALL) # !!!
to only build what is actually transitively needed by your code.
If you build it as a normal package, does it really measurably affect the compile time?
The fact that benchmark.h
isn't IWYU-clean has much much worse impact
on compile-time than said benchmark_main
.
Indeed, the EXCLUDE_FROM_ALL
just worked! I didn't know about this option. Thanks a lot!
Is your feature request related to a problem? Please describe.
To my knowledge, the
CMake
targetbenchmark::benchmark_main
mainly bundlesbenchmark_main.cc
, and links it tobenchmark::benchmark
. Then, it can be used by the user that does not need a customint main()
and is happy with the one inbenchmark_main.cc
.In our case, we need a custom
int main()
(MPI initialization, GPU backends, and so on). Therefore, we never usebenchmark::benchmark_main
.But it is always compiled... This is a waste of resources.
Describe the solution you'd like
Add a
CMake
option like:By default, it would be
ON
to avoid downstream project failures.If you agree, I'll be glad to make a PR for this! Thanks.
(Tagging @maartenarnst)