CMake: Make "require out-of-source builds" valid (#4876)

This commit is contained in:
SY Wang 2026-02-24 19:06:05 +08:00 committed by GitHub
parent d54fdbb405
commit 52b94d0137
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 11 deletions

View file

@ -10,16 +10,6 @@ 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 "${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()
# =================================================================================================
# PROJECT AND VERSION
include(CMakeDependentOption)
@ -41,6 +31,15 @@ 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

View file

@ -72,7 +72,7 @@ run_test mypy --strict ./tools/vibronic_spec/
# /workspace/artifacts/dashboard/
# done
run_test cmake -DCP2K_ENABLE_CONSISTENCY_CHECKS=ON .
run_test cmake -S . -B build -DCP2K_ENABLE_CONSISTENCY_CHECKS=ON
echo ""
echo "Summary: Miscellaneous tests passed"