Using the new rules checker (Stefan)
[u/mrichter/AliRoot.git] / cmake / modules / FindRuleChecker.cmake
CommitLineData
e969a926 1# -*- mode: cmake -*-
2
3# - Find IRST Code Analysis Tool (RuleChecker)
4# Finds if the RuleChecker is installed and sets the following variables:
5#
6# RULE_CHECKER_FOUND = Boolean defining if Rule Checker is available
3314debd 7# RULE_CHECKER_SRCML = PATH TO src2srcml executable
8# RULE_CHECKER_JAVA = PATH TO java executable
9# RULE_CHECKER_JAR = PATH TO NewRuleChecker.jar
10# RULE_CHECKER_RULES = Rules (defaults to ALICE rules!)
e969a926 11
12# We suppose that perl and java are present and working
3314debd 13Find_Program(RULE_CHECKER_SRCML src2srcml $ENV{PATH})
14Find_Program(RULE_CHECKER_JAVA java $ENV{PATH})
15#Message(STATUS "${RULE_CHECKER_SRCML} ${RULE_CHECKER_JAVA}")
16Set(RULE_CHECKER_FOUND NO)
17If(RULE_CHECKER_SRCML AND RULE_CHECKER_JAVA)
18 Find_File(RULE_CHECKER_JAR NAMES NewRuleChecker.jar PATHS $ENV{ALICE}/local/ALICENewRuleChecker/NewRuleChecker)
19 Find_File(RULE_CHECKER_RULES AliceCodingConventions.xml $ENV{ALICE}/local/ALICENewRuleChecker/NewRuleChecker/config)
20 #Message(STATUS "${RULE_CHECKER_JAR} ${RULE_CHECKER_RULES}")
21 If(RULE_CHECKER_JAR AND RULE_CHECKER_RULES)
22 Set(RULE_CHECKER_FOUND YES)
23 Message(STATUS "RuleChecker installed on this system")
24 EndIf(RULE_CHECKER_JAR AND RULE_CHECKER_RULES)
25EndIf(RULE_CHECKER_SRCML AND RULE_CHECKER_JAVA)
26If(NOT RULE_CHECKER_FOUND)
e969a926 27 Message(STATUS "RuleChecker not installed on this system")
3314debd 28EndIf(NOT RULE_CHECKER_FOUND)
e969a926 29
3314debd 30#______________________________________________________________________________________________________________
e969a926 31Function(CheckViols LIB SRCS)
32
84641bd5 33 If(RULE_CHECKER_FOUND)
34 Set(_FactExt $ENV{ALICE}/local/ALICENewRuleChecker/FactExtractor/FactExtractor.jar)
3314debd 35 Set(_RuleCheck ${RULE_CHECKER_JAR})
84641bd5 36
37 String(REGEX MATCHALL "[^ ]*.cxx" CXXSRCS "${SRCS}")
3314debd 38
84641bd5 39 Set(_checkDir "${CMAKE_CURRENT_BINARY_DIR}/check_new")
40
41 If(NOT EXISTS ${_checkDir})
42 File(MAKE_DIRECTORY ${_checkDir})
43 EndIf(NOT EXISTS ${_checkDir})
44
45 Set(_inc_dirs)
46 Foreach(_dir ${INCLUDE_DIRECTORIES})
47 Set(_inc_dirs ${_inc_dirs} -I${_dir})
48 EndForeach(_dir ${INCLUDE_DIRECTORIES})
49
50 Set(VIOLS)
51 Foreach(_checkFile ${CXXSRCS})
52 Get_Filename_Component(_checkFilePath ${_checkFile} PATH)
53 If(NOT EXISTS ${_checkDir}/${_checkFilePath})
54 File(MAKE_DIRECTORY ${_checkDir}/${_checkFilePath})
55 EndIf(NOT EXISTS ${_checkDir}/${_checkFilePath})
56 String(REGEX REPLACE "([^;]*).cxx" "${_checkDir}/\\1.cxx.xml" _srcxml "${_checkFile}")
57 String(REGEX REPLACE "([^;]*).cxx" "${_checkDir}/\\1.h.xml" _hdrxml "${_checkFile}")
3314debd 58 String(REGEX REPLACE "([^;]*).cxx" "${_checkDir}/\\1.viol" _violFile "${_checkFile}")
84641bd5 59 String(REGEX REPLACE "([^;]*).cxx" "\\1.h" _checkHead "${_checkFile}")
60 Add_Custom_Command(
61 OUTPUT ${_violFile}
62 COMMAND src2srcml
63 ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${_checkFile} ${_srcxml}
64 COMMAND src2srcml
65 ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${_checkHead} ${_hdrxml}
3314debd 66 COMMAND java -jar
67 ARGS ${_FactExt} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
68 COMMAND java -Xmx500m -jar ${RULE_CHECKER_JAR}
69 ARGS ${_srcxml} ${_hdrxml} ${CMAKE_CURRENT_SOURCE_DIR}/factFile.xml ${RULE_CHECKER_RULES} > ${_violFile}
84641bd5 70 DEPENDS ${_checkFile}
71 WORKING_DIRECTORY ${_checkDir})
72 Set(VIOLS ${VIOLS} ${_violFile})
73 EndForeach(_checkFile ${CXXSRCS})
74
75 Add_Custom_Target(check-${LIB} DEPENDS ${VIOLS})
76 Add_Dependencies(check-all check-${LIB})
77
78 EndIf(RULE_CHECKER_FOUND)
79
3314debd 80EndFunction (CheckViols)
84641bd5 81