check-cmake.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env bash
  2. set -o errexit
  3. set -o pipefail
  4. if [ ${#} -eq 1 -a "${1}" = "VERBOSE" ]; then
  5. VERBOSITY="-l debug"
  6. else
  7. VERBOSITY=""
  8. fi
  9. if [ "${CI}" ]; then
  10. MODE="--check"
  11. else
  12. MODE="-i"
  13. fi
  14. # Runs the formatter in parallel on the code base.
  15. # Return codes:
  16. # - 1 there are files to be formatted
  17. # - 0 everything looks fine
  18. # Get CPU count
  19. OS=$(uname)
  20. NPROC=1
  21. if [[ ${OS} = "Linux" ]] ; then
  22. NPROC=$(nproc)
  23. elif [[ ${OS} = "Darwin" ]] ; then
  24. NPROC=$(sysctl -n hw.physicalcpu)
  25. fi
  26. # Discover clang-format
  27. if ! type cmake-format 2> /dev/null ; then
  28. echo "Required cmake-format not found"
  29. exit 1
  30. fi
  31. find . -type d \( \
  32. -path ./\*build\* -o \
  33. -path ./release -o \
  34. -path ./deps/jansson -o \
  35. -path ./plugins/decklink/\*/decklink-sdk -o \
  36. -path ./plugins/enc-amf -o \
  37. -path ./plugins/mac-syphon/syphon-framework -o \
  38. -path ./plugins/obs-outputs/ftl-sdk -o \
  39. -path ./plugins/obs-vst -o \
  40. -path ./plugins/obs-browser -o \
  41. -path ./plugins/win-dshow/libdshowcapture -o \
  42. -path ./plugins/obs-websocket/deps \
  43. \) -prune -false -type f -o \
  44. -name 'CMakeLists.txt' -or \
  45. -name '*.cmake' \
  46. | xargs -L10 -P ${NPROC} cmake-format ${MODE} ${VERBOSITY}