diff --git a/CMakeLists.txt b/CMakeLists.txt index e31d8cc40..6dcc269f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,17 @@ # Set the minimum version of CMake that's required cmake_minimum_required(VERSION 3.12) +# make sure the source and binary directories are different +# this is here to prevent so-called "in-source" builds where the root directory of the source +# is also the root directory of the build +get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH) +get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH) +if ("${srcdir}" STREQUAL "${bindir}") + message(FATAL_ERROR "ldmx-sw does not support in-source builds. + Call 'ldmx cmake ..' from within a 'build/' subdirectory or + Tell cmake to use a different build directory with 'ldmx cmake -B build -S .'") +endif() + # Set the project name project(LDMX_SW VERSION 3.1.1 DESCRIPTION "The Light Dark Matter eXperiment simulation and reconstruction framework."