From df8ab74de53a29cd0b976b722f2646c49edee6ff Mon Sep 17 00:00:00 2001 From: SY Wang Date: Fri, 17 Jul 2026 19:05:07 +0800 Subject: [PATCH] CMake: Move out-of-source builds requirement more ahead (#5585) --- CMakeLists.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 075f91973c..23ce2b7a74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,15 @@ cmake_minimum_required(VERSION 3.24) # include our cmake snippets set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +# Require out-of-source builds +file(TO_CMAKE_PATH "${CMAKE_BINARY_DIR}/CMakeLists.txt" LOC_PATH) +if(EXISTS "${LOC_PATH}") + message( + FATAL_ERROR + "You cannot build in a source directory (or any directory with a CMakeLists.txt file). " + "Please make a build subdirectory.") +endif() + # ================================================================================================= # PROJECT AND VERSION include(CMakeDependentOption) @@ -31,15 +40,6 @@ project( list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules") -# Require out-of-source builds -file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH) -if(EXISTS "${LOC_PATH}") - message( - FATAL_ERROR - "You cannot build in a source directory (or any directory with a CMakeLists.txt file). Please make a build subdirectory." - ) -endif() - # set language and standard. # # cmake does not provide any mechanism to set the fortran standard. Adding the