check-cmake.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 ./deps/jansson -o \
  34. -path ./plugins/decklink/\*/decklink-sdk -o \
  35. -path ./plugins/enc-amf -o \
  36. -path ./plugins/mac-syphon/syphon-framework -o \
  37. -path ./plugins/obs-outputs/ftl-sdk -o \
  38. -path ./plugins/obs-vst -o \
  39. -path ./plugins/obs-browser -o \
  40. -path ./plugins/win-dshow/libdshowcapture \
  41. \) -prune -false -type f -o \
  42. -name 'CMakeLists.txt' -or \
  43. -name '*.cmake' \
  44. | xargs -L10 -P ${NPROC} cmake-format ${MODE} ${VERBOSITY}