Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<string> in
# 134 TUs, <vector> in 100).
target_precompile_headers(lci_lib PRIVATE
<string>
<string_view>
<vector>
<memory>
<unordered_map>
<nlohmann/json.hpp>
<absl/container/flat_hash_map.h>
)
Loading