CMakeLists.txt: ignore out-of-source build folder
authorYegor Yefremov <yegorslists@googlemail.com>
Wed, 2 Apr 2025 08:12:36 +0000 (10:12 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Fri, 4 Apr 2025 16:01:15 +0000 (18:01 +0200)
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
CMakeLists.txt

index b652e9f..34f3852 100644 (file)
@@ -9,7 +9,6 @@
 .deps/
 .libs/
 .kdev4/
-build/
 
 # kdevelop
 *.kdevelop.pcs
index c5dbc74..3d1b774 100644 (file)
@@ -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)