diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c7e4bffca1acd75f40120717fe8117013f97993..62110ecf0d910600c3c1c748e174fa6ead7f8246 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,13 @@ cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) +set(CMAKE_MODULE_PATH + ${CMAKE_SOURCE_DIR}/cmake/generic/modules + ${CMAKE_SOURCE_DIR}/cmake/bornagain/modules) +set(TEMPLATE_DIR ${CMAKE_SOURCE_DIR}/cmake/bornagain/scripts) + +include(PreventInSourceBuilds) + project(BornAgain) include(CTest) # equivalent to "enable_testing() ??? @@ -34,11 +41,6 @@ if(AUTOGENERATE) endif() #--- Include CMake macros and functions --- -set(CMAKE_MODULE_PATH - ${CMAKE_SOURCE_DIR}/cmake/generic/modules - ${CMAKE_SOURCE_DIR}/cmake/bornagain/modules) -set(TEMPLATE_DIR ${CMAKE_SOURCE_DIR}/cmake/bornagain/scripts) - include(GetFilenameComponent) # overwrite CMake command include(SearchInstalledSoftware) include(CheckCompiler) diff --git a/cmake/generic/modules/PreventInSourceBuilds.cmake b/cmake/generic/modules/PreventInSourceBuilds.cmake index 3d73192fb58f4d37fbc72f3b9c71b778a2c44de9..48ff010bf57549a147f4f51c2142d20d87f6878a 100644 --- a/cmake/generic/modules/PreventInSourceBuilds.cmake +++ b/cmake/generic/modules/PreventInSourceBuilds.cmake @@ -1,26 +1,20 @@ -# This function will prevent in-source builds +# - Prevent in-source builds. -function(AssureOutOfSourceBuilds) +function(prevent_in_source_builds) # make sure the user doesn't play dirty with symlinks get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH) get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH) # disallow in-source builds if("${srcdir}" STREQUAL "${bindir}") - message("###########################################################################") - message("We do not allow cmake to be run in the source directory.") - message("You must run cmake in a build directory.") - message("For example:") - message(" cd <source directory>") - message(" mkdir build") - message(" cd build") - message(" cmake .. # or ccmake, or cmake-gui") - message("") - message("To clean up after this aborted in-place compilation:") - message(" rm -r CMakeCache.txt CMakeFiles/") - message("###########################################################################") - message(FATAL_ERROR "Quitting configuration") + message(FATAL_ERROR "\ + +CMake must not to be run in the source directory. \ +Rather create a dedicated build directory and run CMake there. \ +To clean up after this aborted in-place compilation: + rm -r CMakeCache.txt CMakeFiles +") endif() endfunction() -AssureOutOfSourceBuilds() +prevent_in_source_builds()