diff options
Diffstat (limited to '')
| -rw-r--r-- | CMakeLists.txt | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b27e0c5b..992cab995 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
| @@ -319,6 +319,53 @@ if (UNIX OR MINGW) | |||
| 319 | endif() | 319 | endif() |
| 320 | endif() | 320 | endif() |
| 321 | 321 | ||
| 322 | # Setup a custom clang-format target (if clang-format can be found) that will run | ||
| 323 | # against all the src files. This should be used before making a pull request. | ||
| 324 | # ======================================================================= | ||
| 325 | |||
| 326 | set(CLANG_FORMAT_POSTFIX "-6.0") | ||
| 327 | find_program(CLANG_FORMAT | ||
| 328 | NAMES clang-format${CLANG_FORMAT_POSTFIX} | ||
| 329 | clang-format | ||
| 330 | PATHS ${CMAKE_BINARY_DIR}/externals) | ||
| 331 | # if find_program doesn't find it, try to download from externals | ||
| 332 | if (NOT CLANG_FORMAT) | ||
| 333 | if (WIN32) | ||
| 334 | message(STATUS "Clang format not found! Downloading...") | ||
| 335 | set(CLANG_FORMAT "${CMAKE_BINARY_DIR}/externals/clang-format${CLANG_FORMAT_POSTFIX}.exe") | ||
| 336 | file(DOWNLOAD | ||
| 337 | https://github.com/yuzu-emu/ext-windows-bin/raw/master/clang-format${CLANG_FORMAT_POSTFIX}.exe | ||
| 338 | "${CLANG_FORMAT}" SHOW_PROGRESS | ||
| 339 | STATUS DOWNLOAD_SUCCESS) | ||
| 340 | if (NOT DOWNLOAD_SUCCESS EQUAL 0) | ||
| 341 | message(WARNING "Could not download clang format! Disabling the clang format target") | ||
| 342 | file(REMOVE ${CLANG_FORMAT}) | ||
| 343 | unset(CLANG_FORMAT) | ||
| 344 | endif() | ||
| 345 | else() | ||
| 346 | message(WARNING "Clang format not found! Disabling the clang format target") | ||
| 347 | endif() | ||
| 348 | endif() | ||
| 349 | |||
| 350 | if (CLANG_FORMAT) | ||
| 351 | set(SRCS ${CMAKE_SOURCE_DIR}/src) | ||
| 352 | set(CCOMMENT "Running clang format against all the .h and .cpp files in src/") | ||
| 353 | if (WIN32) | ||
| 354 | add_custom_target(clang-format | ||
| 355 | COMMAND powershell.exe -Command "${CLANG_FORMAT} -i @(Get-ChildItem -Recurse ${SRCS}/* -Include \'*.h\', \'*.cpp\')" | ||
| 356 | COMMENT ${CCOMMENT}) | ||
| 357 | elseif(MINGW) | ||
| 358 | add_custom_target(clang-format | ||
| 359 | COMMAND find `cygpath -u ${SRCS}` -iname *.h -o -iname *.cpp | xargs `cygpath -u ${CLANG_FORMAT}` -i | ||
| 360 | COMMENT ${CCOMMENT}) | ||
| 361 | else() | ||
| 362 | add_custom_target(clang-format | ||
| 363 | COMMAND find ${SRCS} -iname *.h -o -iname *.cpp | xargs ${CLANG_FORMAT} -i | ||
| 364 | COMMENT ${CCOMMENT}) | ||
| 365 | endif() | ||
| 366 | unset(SRCS) | ||
| 367 | unset(CCOMMENT) | ||
| 368 | endif() | ||
| 322 | 369 | ||
| 323 | # Include source code | 370 | # Include source code |
| 324 | # =================== | 371 | # =================== |