From da97ba29147afb8b54edb9e1931f6abbbde1028d Mon Sep 17 00:00:00 2001 From: crueter Date: Wed, 10 Sep 2025 14:01:25 -0400 Subject: [PATCH] [cmake] fix MASTER_PROJECT heuristic; only enable install if master project (#4536) SOURCE vs CURRENT_SOURCE is unreliable. `DEFINED PROJECT_NAME` is a much more portable way of determination. Also, installation shouldn't default to on if it is a subproject. --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ef6c2ca..3c055132 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,9 @@ endif () # or if it is the master project. if (NOT DEFINED FMT_MASTER_PROJECT) set(FMT_MASTER_PROJECT OFF) - if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + # NOTE: source vs current_source detection is unreliable + # this heuristic is more generally applicable esp w.r.t FetchContent + if (NOT DEFINED PROJECT_NAME) set(FMT_MASTER_PROJECT ON) message(STATUS "CMake version: ${CMAKE_VERSION}") endif () @@ -161,7 +163,7 @@ option(FMT_WERROR "Halt the compilation with an error on compiler warnings." # Options that control generation of various targets. option(FMT_DOC "Generate the doc target." ${FMT_MASTER_PROJECT}) -option(FMT_INSTALL "Generate the install target." ON) +option(FMT_INSTALL "Generate the install target." ${FMT_MASTER_PROJECT}) option(FMT_TEST "Generate the test target." ${FMT_MASTER_PROJECT}) option(FMT_FUZZ "Generate the fuzz target." OFF) option(FMT_CUDA_TEST "Generate the cuda-test target." OFF)