From 17c484d6502a2547e4807b9a5b888497175e5424 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 13 Oct 2026 11:46:01 +0000 Subject: build: share local-first dependency lookup across tools and libraries Co-Authored-By: Claude Fable 5.1 --- cmake/BuildTools.cmake | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 cmake/BuildTools.cmake (limited to 'cmake/BuildTools.cmake') diff --git a/cmake/BuildTools.cmake b/cmake/BuildTools.cmake new file mode 100644 index 0000000..d6928bb --- /dev/null +++ b/cmake/BuildTools.cmake @@ -0,0 +1,43 @@ +# Resolve tools before project() performs its compiler and generator checks. +if(CMAKE_GENERATOR MATCHES "Makefiles|Ninja") + foreach(language C CXX) + if(language STREQUAL "C") + set(names clang cc gcc) + else() + set(names clang++ c++ g++) + endif() + if(CMAKE_${language}_COMPILER) + get_filename_component(requested "${CMAKE_${language}_COMPILER}" NAME) + list(INSERT names 0 "${requested}") + endif() + cpsc_find_dependency(PROGRAM CMAKE_${language}_COMPILER NAMES ${names} REQUIRED) + # project() would otherwise restore the previous path from this file. + set(compiler_info "${CMAKE_BINARY_DIR}/CMakeFiles/${CMAKE_VERSION}/CMake${language}Compiler.cmake") + if(EXISTS "${compiler_info}") + file(STRINGS "${compiler_info}" previous + REGEX "^set\\(CMAKE_${language}_COMPILER \"") + string(REGEX REPLACE "^set\\(CMAKE_${language}_COMPILER \"([^\"]*)\"\\)$" + "\\1" previous "${previous}") + if(NOT previous STREQUAL CMAKE_${language}_COMPILER) + file(REMOVE "${compiler_info}") + endif() + endif() + endforeach() +endif() + +if(CMAKE_GENERATOR MATCHES "Ninja") + set(names ninja ninja-build) +elseif(CMAKE_GENERATOR STREQUAL "MinGW Makefiles") + set(names mingw32-make) +elseif(CMAKE_GENERATOR MATCHES "NMake") + set(names nmake) +elseif(CMAKE_GENERATOR STREQUAL "MSYS Makefiles") + set(names make) +elseif(CMAKE_GENERATOR STREQUAL "Unix Makefiles") + set(names gmake make) +else() + set(names) +endif() +if(names) + cpsc_find_dependency(PROGRAM CMAKE_MAKE_PROGRAM NAMES ${names} REQUIRED) +endif() -- cgit v1.3.1-4-g156e