From 5c3856d44fd339ba23194b0686f420f7a863942c Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Wed, 2 Apr 2025 10:12:36 +0200 Subject: [PATCH] CMakeLists.txt: ignore out-of-source build folder Create a .gitignore file inside a build folder. This way this folder will be ignored by git and hence, no entry in the root .gitignore is required. For more information see this post: https://www.scivision.dev/cmake-auto-gitignore-build-dir/ --- .gitignore | 1 - CMakeLists.txt | 5 +++++ 2 files changed, 5 insertions(+), 1 deletions(-) diff --git a/.gitignore b/.gitignore index b652e9f..34f3852 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,6 @@ .deps/ .libs/ .kdev4/ -build/ # kdevelop *.kdevelop.pcs diff --git a/CMakeLists.txt b/CMakeLists.txt index c5dbc74..3d1b774 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,11 @@ set(CMAKE_COLOR_MAKEFILE ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +if(NOT PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) + # Auto-create a .gitignore in the out-of-source build directory. + file(GENERATE OUTPUT .gitignore CONTENT "*") +endif() + add_definitions(-Wall) include(CMakeOptions.txt) -- 1.7.1