aboutsummaryrefslogtreecommitdiff
path: root/cmake/BuildTools.cmake
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-13 11:46:01 +0000
committer_ov4 <ov4@ov4.org>2026-10-13 11:46:01 +0000
commit17c484d6502a2547e4807b9a5b888497175e5424 (patch)
tree06fdb47edf1935b214ce06e3821dbdb4b954b2b4 /cmake/BuildTools.cmake
parentec0ae47dd798e48e2409cbc544e17e2b13f550eb (diff)
build: share local-first dependency lookup across tools and libraries
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'cmake/BuildTools.cmake')
-rw-r--r--cmake/BuildTools.cmake43
1 files changed, 43 insertions, 0 deletions
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()