From 0703956e78d1d0352e69273295a0301586f86ca8 Mon Sep 17 00:00:00 2001 From: Andy Clayton Date: Tue, 31 Mar 2020 19:41:50 -0500 Subject: use built-in cmake precompiled header support when available Ledger supports precompiling headers as a build speed optimization. This is provided via a custom add_pch_rule macro. Similar functionality is now built-in to CMake starting with the 3.16 release in November 2019. Let's use this when available to fix #1774 and start towards not needing to maintain our own implementation. I originally considered removing the macro fallback but in my tests it saves enough build time that I think it is worth keeping for now. Fixes #1774 --- src/CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/CMakeLists.txt') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5eddd5ac..167f5515 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -265,7 +265,8 @@ else() endmacro(ADD_PCH_RULE _header_filename _src_list _other_srcs) endif() -if(PRECOMPILE_SYSTEM_HH) +if(PRECOMPILE_SYSTEM_HH AND NOT (COMMAND target_precompile_headers)) + # enable fallback for CMake versions older than 3.16 without target_precompile_headers add_pch_rule(${PROJECT_BINARY_DIR}/system.hh LEDGER_SOURCES LEDGER_CLI_SOURCES) endif() @@ -294,6 +295,15 @@ else() add_ledger_library_dependencies(ledger) endif() +if (PRECOMPILE_SYSTEM_HH AND (COMMAND target_precompile_headers) AND (CMAKE_BUILD_TYPE STREQUAL "Debug")) + if (BUILD_LIBRARY) + target_precompile_headers(libledger PRIVATE ${PROJECT_BINARY_DIR}/system.hh) + target_precompile_headers(ledger REUSE_FROM libledger) + else() + target_precompile_headers(ledger PRIVATE ${PROJECT_BINARY_DIR}/system.hh) + endif() +endif() + if (USE_PYTHON) if (Python_SITEARCH) if (WIN32 AND NOT CYGWIN) -- cgit v1.2.3