Skip to content

Instantly share code, notes, and snippets.

@mathomp4
Last active February 24, 2021 21:55
Show Gist options
  • Save mathomp4/e7a4082f1b0b31ba187693a4b6563592 to your computer and use it in GitHub Desktop.
Save mathomp4/e7a4082f1b0b31ba187693a4b6563592 to your computer and use it in GitHub Desktop.
Automatically ignore CMake build and install directories

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}
   )
@scivision
Copy link

presets aren't a cure-all, but they can help avoid the need to use scripts to drive CMake, or excessively long command lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment