From c3e22a2f6cec880c29fa6527382d6bc3ba36fc8e Mon Sep 17 00:00:00 2001 From: James Rowe Date: Sat, 20 Jan 2018 00:31:44 -0700 Subject: CMake: Add a custom clang format target Checks to see if clang-format can be found, and if it is, sets up a custom target that will run against the src dir and auto formats all files. In MSVC, this is a project, and in Makefiles, its a make target --- CMakeLists.txt | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'CMakeLists.txt') 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 # =================== -- cgit v1.2.3 From 1e662e6e9a8d004aea1495a98af1118c87405223 Mon Sep 17 00:00:00 2001 From: James Rowe Date: Sat, 20 Jan 2018 00:46:04 -0700 Subject: CMake: Conditionally turn on bundled libs for MSVC Removes the annoying step when generating sln for MSVC where you have to click an extra checkbox after the first generate fails by using a conditional option. The USE_BUNDLED options will be off by default, but if the enable_lib option is enabled and the toolset is msvc, they are turned ON. --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 992cab995..5dee41abc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,14 +3,17 @@ cmake_minimum_required(VERSION 3.6) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/cmake-modules") include(DownloadExternals) +include(CMakeDependentOption) project(yuzu) +# Set bundled sdl2/qt as dependent options. +# OFF by default, but if ENABLE_SDL2 and MSVC are true then ON option(ENABLE_SDL2 "Enable the SDL2 frontend" ON) -option(YUZU_USE_BUNDLED_SDL2 "Download bundled SDL2 binaries" OFF) +CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_SDL2 "Download bundled SDL2 binaries" ON "ENABLE_SDL2;MSVC" OFF) option(ENABLE_QT "Enable the Qt frontend" ON) -option(YUZU_USE_BUNDLED_QT "Download bundled Qt binaries" OFF) +CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_QT "Download bundled Qt binaries" ON "ENABLE_SDL2;MSVC" OFF) if(NOT EXISTS ${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit) message(STATUS "Copying pre-commit hook") -- cgit v1.2.3