This bit of CMake is based off of code from Michael Hirsch (aka @scivision)
# https://www.scivision.dev/cmake-auto-gitignore-build-dir/
# --- auto-ignore build directory
if(NOT EXISTS ${PROJECT_BINARY_DIR}/.gitignore)
file(WRITE ${PROJECT_BINARY_DIR}/.gitignore "*")
endif()
# Piggyback that file into install
install(
FILES ${PROJECT_BINARY_DIR}/.gitignore
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
I might ping @scivision here and ask his opinion on the second step. I shamelessly "borrowed" his cool trick for automatically ignoring build directories, but I usually install parallel to build inside the git repo I'm building. Thus, I'd like to ignore that directory no matter the name. The above second step works...but it just seems so inelegant.
Thus, I climb the mountain and ask the guru @scivision if he has a more elegant way to do this...