diff --git a/CMakeLists.txt b/CMakeLists.txt index 9156171..20a1f10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,18 @@ cmake_minimum_required(VERSION 3.25) +# Use ccache as the compiler launcher when it is installed — automatic for +# local dev builds, a no-op where absent. Must be set before project()/ +# enable_language. `NOT DEFINED` respects an explicit -DCMAKE_CXX_COMPILER_LAUNCHER +# passed by CI, so this only fills the gap for developers. +if(NOT DEFINED CMAKE_CXX_COMPILER_LAUNCHER) + find_program(CCACHE_PROGRAM ccache) + if(CCACHE_PROGRAM) + set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") + set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") + message(STATUS "lci: using ccache compiler launcher (${CCACHE_PROGRAM})") + endif() +endif() + project(lci VERSION 0.6.0 DESCRIPTION "Lightning Code Index - fast semantic code search" @@ -67,6 +80,23 @@ if(LCI_WARNINGS_AS_ERRORS) endif() endif() +# Prefer a fast linker (mold > lld) when installed — the link of `lci` and the +# monolithic `lci_tests` (links all deps + ~1700 tests) is a real slice of +# build time, more so with debug info. Linux/ELF only: mold targets ELF (no +# Mach-O), and Apple's default ld64 is fine, so don't override the linker on +# macOS. No-op if neither is present. +if(NOT MSVC AND NOT APPLE) + find_program(MOLD_LINKER mold) + find_program(LLD_LINKER ld.lld) + if(MOLD_LINKER) + add_link_options(-fuse-ld=mold) + message(STATUS "lci: using mold linker (${MOLD_LINKER})") + elseif(LLD_LINKER) + add_link_options(-fuse-ld=lld) + message(STATUS "lci: using lld linker") + endif() +endif() + # Version header generation configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.h.in" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b21b197..94e026c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -184,3 +184,19 @@ target_link_libraries(lci PRIVATE # Project warning flags (target-scoped, do not leak into FetchContent libs). target_compile_options(lci_lib PRIVATE ${LCI_WARNING_FLAGS}) target_compile_options(lci PRIVATE ${LCI_WARNING_FLAGS}) + +# Precompiled headers. The heaviest, most widely-included headers — nlohmann/json +# (~25k lines, in 26 TUs) and absl flat_hash_map (39 TUs) — are parsed once into +# the PCH instead of per translation unit. Largest clean-build compile-time win +# for the library. Both deps are linked PUBLIC above, so their include dirs are +# already on lci_lib's compile line; the std headers are ubiquitous ( in +# 134 TUs, in 100). +target_precompile_headers(lci_lib PRIVATE + + + + + + + +)