-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclang-tools.cmake
36 lines (32 loc) · 1.02 KB
/
clang-tools.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Add targets for clang-format and clang-tidy ############
# Find all source files
execute_process(
COMMAND
sh -c
"git ls-tree -r HEAD --name-only | grep -E '(\\.cpp$)|(\\.h$)' | tr '\n' ' '"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE ALL_CXX_SOURCE_FILES)
# ########### clang-format ############
# Try to find clang-format and add target if successful
find_program(CLANG_FORMAT "clang-format")
if(CLANG_FORMAT)
add_custom_target(
clang-format
COMMAND bash -c "/usr/bin/clang-format -i ${ALL_CXX_SOURCE_FILES}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
else()
message(STATUS "clang-format was not found")
endif()
# ########### clang-tidy ############
# Try to find clang-tidy and add target if successful
find_program(CLANG_TIDY "clang-tidy")
if(CLANG_TIDY)
add_custom_target(
clang-tidy
COMMAND
sh -c
"/usr/bin/clang-tidy amici/src/*.cpp -- -std=c++11 ${CMAKE_INCLUDE_PATH}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
else()
message(STATUS "clang-tidy was not found")
endif()