1# 2# Copyright (C) 2018 by George Cave - gcave@stablecoder.ca 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); you may not 5# use this file except in compliance with the License. You may obtain a copy of 6# the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13# License for the specific language governing permissions and limitations under 14# the License. 15 16option(CLANG_TIDY "Turns on clang-tidy processing if it is found." OFF) 17option(IWYU "Turns on include-what-you-use processing if it is found." OFF) 18option(CPPCHECK "Turns on cppcheck processing if it is found." OFF) 19 20# Adds clang-tidy checks to the compilation, with the given arguments being used 21# as the options set. 22macro(clang_tidy) 23 if(CLANG_TIDY AND CLANG_TIDY_EXE) 24 set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXE} ${ARGN}) 25 endif() 26endmacro() 27 28# Adds include_what_you_use to the compilation, with the given arguments being 29# used as the options set. 30macro(include_what_you_use) 31 if(IWYU AND IWYU_EXE) 32 set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU_EXE};${IWYU_STRING}") 33 endif() 34endmacro() 35 36# Adds cppcheck to the compilation, with the given arguments being used as the 37# options set. 38macro(cppcheck) 39 if(CPPCHECK AND CPPCHECK_EXE) 40 set(CMAKE_CXX_CPPCHECK "${CPPCHECK_EXE};${CPPCHECK_STRING}") 41 endif() 42endmacro() 43 44find_program(CLANG_TIDY_EXE NAMES "clang-tidy") 45if(CLANG_TIDY_EXE) 46 message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}") 47 if(NOT CLANG_TIDY) 48 message(STATUS "clang-tidy NOT ENABLED via 'CLANG_TIDY' variable!") 49 set(CMAKE_CXX_CLANG_TIDY 50 "" 51 CACHE STRING "" FORCE) # delete it 52 endif() 53elseif(CLANG_TIDY) 54 message(SEND_ERROR "Cannot enable clang-tidy, as executable not found!") 55 set(CMAKE_CXX_CLANG_TIDY 56 "" 57 CACHE STRING "" FORCE) # delete it 58else() 59 message(STATUS "clang-tidy not found!") 60 set(CMAKE_CXX_CLANG_TIDY 61 "" 62 CACHE STRING "" FORCE) # delete it 63endif() 64 65find_program(IWYU_EXE NAMES "include-what-you-use") 66if(IWYU_EXE) 67 message(STATUS "include-what-you-use found: ${IWYU_EXE}") 68 if(NOT IWYU) 69 message(STATUS "include-what-you-use NOT ENABLED via 'IWYU' variable!") 70 set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE 71 "" 72 CACHE STRING "" FORCE) # delete it 73 endif() 74elseif(IWYU) 75 message( 76 SEND_ERROR "Cannot enable include-what-you-use, as executable not found!") 77 set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE 78 "" 79 CACHE STRING "" FORCE) # delete it 80else() 81 message(STATUS "include-what-you-use not found!") 82 set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE 83 "" 84 CACHE STRING "" FORCE) # delete it 85endif() 86 87find_program(CPPCHECK_EXE NAMES "cppcheck") 88if(CPPCHECK_EXE) 89 message(STATUS "cppcheck found: ${CPPCHECK_EXE}") 90 if(CPPECHECK) 91 set(CMAKE_CXX_CPPCHECK 92 "${CPPCHECK_EXE};--enable=warning,performance,portability,missingInclude;--template=\"[{severity}][{id}] {message} {callstack} \(On {file}:{line}\)\";--suppress=missingIncludeSystem;--quiet;--verbose;--force" 93 ) 94 endif() 95 if(NOT CPPCHECK) 96 message(STATUS "cppcheck NOT ENABLED via 'CPPCHECK' variable!") 97 set(CMAKE_CXX_CPPCHECK 98 "" 99 CACHE STRING "" FORCE) # delete it 100 endif() 101elseif(CPPCHECK) 102 message(SEND_ERROR "Cannot enable cppcheck, as executable not found!") 103 set(CMAKE_CXX_CPPCHECK 104 "" 105 CACHE STRING "" FORCE) # delete it 106else() 107 message(STATUS "cppcheck not found!") 108 set(CMAKE_CXX_CPPCHECK 109 "" 110 CACHE STRING "" FORCE) # delete it 111endif() 112