-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This creates one target to reformat code automatically and one target to check the codes formatting. Adapted from: https://github.com/ttroy50/cmake-examples/tree/master/04-static-analysis/clang-format
- Loading branch information
1 parent
1069c44
commit 3141fdb
Showing
24 changed files
with
794 additions
and
712 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Find Clang format | ||
# The module defines the following variables | ||
# | ||
# ``ClangFormat_FOUND`` True if clang-format executable was found. | ||
# ``ClangFormat_EXECUTABLE`` Path to clang-format executable. | ||
# | ||
# The behaviour of this module is influenced by the following variables | ||
# | ||
# ``CLANG_FORMAT_EXE_NAME`` Name of executable to find (default clang-format). | ||
# ``CLANG_FORMAT_ROOT_DIR`` Path to search for executable name in. | ||
# | ||
if (NOT CLANG_FORMAT_EXE_NAME) | ||
set(CLANG_FORMAT_EXE_NAME clang-format) | ||
endif () | ||
|
||
# if custom path check there first | ||
if (CLANG_FORMAT_ROOT_DIR) | ||
find_program(ClangFormat_EXECUTABLE | ||
NAMES | ||
${CLANG_FORMAT_EXE_NAME} | ||
PATHS | ||
"${CLANG_FORMAT_ROOT_DIR}" | ||
NO_DEFAULT_PATH) | ||
else () | ||
find_program(ClangFormat_EXECUTABLE NAMES ${CLANG_FORMAT_EXE_NAME}) | ||
endif () | ||
|
||
# Print an error message when the executable was not found | ||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args( | ||
ClangFormat | ||
DEFAULT_MSG | ||
ClangFormat_EXECUTABLE) | ||
|
||
mark_as_advanced(ClangFormat_EXECUTABLE) | ||
|
||
if (ClangFormat_FOUND) | ||
# A CMake script to find all source files and setup clang-format targets for them | ||
include(clang-format) | ||
else () | ||
message(STATUS "clang-format not found. Not setting up format targets") | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# A CMake script to find all source files and setup clang-format targets for them | ||
|
||
# Find all source files | ||
set(CLANG_FORMAT_CXX_FILE_EXTENSIONS ${CLANG_FORMAT_CXX_FILE_EXTENSIONS} *.cpp *.h *.cxx *.hxx *.hpp *.cc *.ipp) | ||
file(GLOB_RECURSE ALL_SOURCE_FILES ${CLANG_FORMAT_CXX_FILE_EXTENSIONS}) | ||
|
||
# Don't include some common build folders | ||
set(CLANG_FORMAT_EXCLUDE_PATTERNS ${CLANG_FORMAT_EXCLUDE_PATTERNS} "/CMakeFiles/" "cmake") | ||
|
||
# get all project files file | ||
foreach (SOURCE_FILE ${ALL_SOURCE_FILES}) | ||
foreach (EXCLUDE_PATTERN ${CLANG_FORMAT_EXCLUDE_PATTERNS}) | ||
string(FIND ${SOURCE_FILE} ${EXCLUDE_PATTERN} EXCLUDE_FOUND) | ||
if (NOT ${EXCLUDE_FOUND} EQUAL -1) | ||
list(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE}) | ||
endif () | ||
endforeach () | ||
endforeach () | ||
|
||
add_custom_target(clang-format | ||
COMMENT "Running clang-format to change files" | ||
COMMAND ${ClangFormat_EXECUTABLE} | ||
--style=file | ||
-i | ||
${ALL_SOURCE_FILES} | ||
) | ||
|
||
add_custom_target(clang-format-check | ||
COMMENT "Checking clang-format changes" | ||
COMMAND ${ClangFormat_EXECUTABLE} | ||
--style=file | ||
--dry-run | ||
--Werror | ||
${ALL_SOURCE_FILES} | ||
) | ||
|
||
# Get the path to this file | ||
get_filename_component(_clangcheckpath clang-format.cmake PATH) | ||
# have at least one here by default | ||
set(CHANGED_FILE_EXTENSIONS ".cpp") | ||
foreach (EXTENSION ${CLANG_FORMAT_CXX_FILE_EXTENSIONS}) | ||
set(CHANGED_FILE_EXTENSIONS "${CHANGED_FILE_EXTENSIONS},${EXTENSION}") | ||
endforeach () | ||
|
||
set(EXCLUDE_PATTERN_ARGS) | ||
foreach (EXCLUDE_PATTERN ${CLANG_FORMAT_EXCLUDE_PATTERNS}) | ||
list(APPEND EXCLUDE_PATTERN_ARGS "--exclude=${EXCLUDE_PATTERN}") | ||
endforeach () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ class Emulator; | |
*/ | ||
class AddressBus { | ||
Emulator* m_emulator; | ||
|
||
public: | ||
AddressBus(Emulator* emulator); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.