From f563bea192989fdcd9518528aa3fdc16736a3be0 Mon Sep 17 00:00:00 2001 From: ThorstenB <brehmt@gmail.com> Date: Tue, 17 Jul 2012 19:19:17 +0200 Subject: [PATCH] Add warning for in-source-directory builds. --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3549c89ea..150c3931d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,14 @@ else(${CMAKE_VERSION} VERSION_GREATER 2.8.4) include(OldGNUInstallDirs) endif(${CMAKE_VERSION} VERSION_GREATER 2.8.4) +# Warning when build is not an out-of-source build. +string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" InSourceBuild) +if(InSourceBuild) + message(WARNING "Avoid building inside the source tree!") + message(WARNING "Create a separate build directory instead (i.e. 'fgbuild') and call CMake from there: ") + message(WARNING " mkdir ../fgbuild && cd ../fgbuild && cmake ${CMAKE_SOURCE_DIR}") +endif(InSourceBuild) + set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually d on windows") set(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows") set(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")