diff options
author | James Rowe <jroweboy@gmail.com> | 2018-01-20 08:31:44 +0100 |
---|---|---|
committer | James Rowe <jroweboy@gmail.com> | 2018-01-20 23:45:59 +0100 |
commit | c3e22a2f6cec880c29fa6527382d6bc3ba36fc8e (patch) | |
tree | b91cc713013319017764ca56a836338cec5b3dab /CMakeLists.txt | |
parent | Port citra #3352 to yuzu (#103) (diff) | |
download | yuzu-c3e22a2f6cec880c29fa6527382d6bc3ba36fc8e.tar yuzu-c3e22a2f6cec880c29fa6527382d6bc3ba36fc8e.tar.gz yuzu-c3e22a2f6cec880c29fa6527382d6bc3ba36fc8e.tar.bz2 yuzu-c3e22a2f6cec880c29fa6527382d6bc3ba36fc8e.tar.lz yuzu-c3e22a2f6cec880c29fa6527382d6bc3ba36fc8e.tar.xz yuzu-c3e22a2f6cec880c29fa6527382d6bc3ba36fc8e.tar.zst yuzu-c3e22a2f6cec880c29fa6527382d6bc3ba36fc8e.zip |
Diffstat (limited to 'CMakeLists.txt')
-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) endif() endif() +# Setup a custom clang-format target (if clang-format can be found) that will run +# against all the src files. This should be used before making a pull request. +# ======================================================================= + +set(CLANG_FORMAT_POSTFIX "-6.0") +find_program(CLANG_FORMAT + NAMES clang-format${CLANG_FORMAT_POSTFIX} + clang-format + PATHS ${CMAKE_BINARY_DIR}/externals) +# if find_program doesn't find it, try to download from externals +if (NOT CLANG_FORMAT) + if (WIN32) + message(STATUS "Clang format not found! Downloading...") + set(CLANG_FORMAT "${CMAKE_BINARY_DIR}/externals/clang-format${CLANG_FORMAT_POSTFIX}.exe") + file(DOWNLOAD + https://github.com/yuzu-emu/ext-windows-bin/raw/master/clang-format${CLANG_FORMAT_POSTFIX}.exe + "${CLANG_FORMAT}" SHOW_PROGRESS + STATUS DOWNLOAD_SUCCESS) + if (NOT DOWNLOAD_SUCCESS EQUAL 0) + message(WARNING "Could not download clang format! Disabling the clang format target") + file(REMOVE ${CLANG_FORMAT}) + unset(CLANG_FORMAT) + endif() + else() + message(WARNING "Clang format not found! Disabling the clang format target") + endif() +endif() + +if (CLANG_FORMAT) + set(SRCS ${CMAKE_SOURCE_DIR}/src) + set(CCOMMENT "Running clang format against all the .h and .cpp files in src/") + if (WIN32) + add_custom_target(clang-format + COMMAND powershell.exe -Command "${CLANG_FORMAT} -i @(Get-ChildItem -Recurse ${SRCS}/* -Include \'*.h\', \'*.cpp\')" + COMMENT ${CCOMMENT}) + elseif(MINGW) + add_custom_target(clang-format + COMMAND find `cygpath -u ${SRCS}` -iname *.h -o -iname *.cpp | xargs `cygpath -u ${CLANG_FORMAT}` -i + COMMENT ${CCOMMENT}) + else() + add_custom_target(clang-format + COMMAND find ${SRCS} -iname *.h -o -iname *.cpp | xargs ${CLANG_FORMAT} -i + COMMENT ${CCOMMENT}) + endif() + unset(SRCS) + unset(CCOMMENT) +endif() # Include source code # =================== |