From 920364ca878b10caeaafb64c5a4a73b23d3b4a93 Mon Sep 17 00:00:00 2001 From: Caleb Xu Date: Wed, 15 May 2024 19:53:26 -0400 Subject: [PATCH] formula: trap CMake FetchContent usage instead of using FETCHCONTENT_FULLY_DISCONNECTED --- .../cmake/trap_fetchcontent_provider.cmake | 16 ++++++++++++++++ Library/Homebrew/formula.rb | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Library/Homebrew/cmake/trap_fetchcontent_provider.cmake diff --git a/Library/Homebrew/cmake/trap_fetchcontent_provider.cmake b/Library/Homebrew/cmake/trap_fetchcontent_provider.cmake new file mode 100644 index 0000000000000..522a5d4a27632 --- /dev/null +++ b/Library/Homebrew/cmake/trap_fetchcontent_provider.cmake @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.24) # Dependency providers introduced in CMake 3.24 + +option(HOMEBREW_ALLOW_FETCHCONTENT "Allow FetchContent to be used in Homebrew builds" OFF) + +if (HOMEBREW_ALLOW_FETCHCONTENT) + return() +endif() + +macro(trap_fetchcontent_provider method depName) + message(FATAL_ERROR "Refusing to populate dependency '${depName}' with FetchContent while building in Homebrew, please use a formula dependency or add a resource to the formula.") +endmacro() + +cmake_language( + SET_DEPENDENCY_PROVIDER trap_fetchcontent_provider + SUPPORTED_METHODS FETCHCONTENT_MAKEAVAILABLE_SERIAL +) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index f5dc392fd1544..9a884e963fd99 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1808,7 +1808,7 @@ def std_cmake_args(install_prefix: prefix, install_libdir: "lib", find_framework -DCMAKE_BUILD_TYPE=Release -DCMAKE_FIND_FRAMEWORK=#{find_framework} -DCMAKE_VERBOSE_MAKEFILE=ON - -DFETCHCONTENT_FULLY_DISCONNECTED=ON + -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=#{HOMEBREW_LIBRARY_PATH}/cmake/trap_fetchcontent_provider.cmake -Wno-dev -DBUILD_TESTING=OFF ]