Update: removed request of 4 points in ITS (Renu)
[u/mrichter/AliRoot.git] / cmake / modules / FindRuleChecker.cmake.ori
1 # -*- mode: cmake -*-
2
3 # - Find IRST Code Analysis Tool (RuleChecker)
4 # This module finds if the RuleChecker is installed
5 #   
6 # This code sets the following variables:
7 #
8 # RULE_CHECKER_FOUND = Boolean defining if Rule Checker is available
9 # RULE_CHECKER_PATH  = Path to the java class containing the CBM Rule Checker
10 # RULE_CHECKER       = Java class to executed
11 # RULE_CHECKER_PERL  = Perl script to be executed to patch preprocessor files
12
13
14 # Check if Java and Perl are available. Both are nedded for the Rule
15 # checker.
16
17 MESSAGE(STATUS "Looking for Java...")
18 find_package(Java)
19 IF(JAVA_RUNTIME)
20   MESSAGE(STATUS "Looking for Java... - found ${JAVA_RUNTIME} ")
21 ELSE(JAVA_RUNTIME)
22   MESSAGE(STATUS "Looking for Java... - not found")
23 ENDIF(JAVA_RUNTIME)
24
25 MESSAGE(STATUS "Looking for Perl...")
26 find_package(Perl)
27 IF(PERL_FOUND)
28   MESSAGE(STATUS "Looking for Perl... - found ${PERL_EXECUTABLE} ")
29 ELSE(PERL_FOUND)
30   MESSAGE(STATUS "Looking for Perl... - not found")
31 ENDIF(PERL_FOUND)
32
33 if (JAVA_RUNTIME AND PERL_FOUND)
34
35   MESSAGE(STATUS "Looking for Rule Checker...")
36   
37   SET(PATH1)
38   IF($ENV{CLASSPATH})
39     STRING(REGEX MATCHALL "[^:]+" PATH1 $ENV{CLASSPATH})
40   ENDIF($ENV{CLASSPATH})
41   SET(CHECK_DIRECTORIES ${SIMPATH}/tools/RuleChecker "${PATH1}")
42   
43   IF(CBMROOT_SOURCE_DIR)
44     SET(RULE_CHECKER_LIBRARY_DIRECTORIES)
45     FOREACH(dir ${CHECK_DIRECTORIES})
46       SET(RULE_CHECKER_LIBRARY_DIRECTORIES
47         ${RULE_CHECKER_LIBRARY_DIRECTORIES}
48         ${dir}/rules/CBM
49         )
50     ENDFOREACH(dir)
51     FIND_PATH(RULE_CHECKER_PATH CBMRuleChecker.class PATHS
52        ${RULE_CHECKER_LIBRARY_DIRECTORIES}
53     )
54     SET(RULE_CHECKER rules.CBM.CBMRuleChecker)
55   ELSE(CBMROOT_SOURCE_DIR)
56     IF(PANDAROOT_SOURCE_DIR)
57       MESSAGE("HIER")
58       SET(RULE_CHECKER_LIBRARY_DIRECTORIES)
59       FOREACH(dir ${CHECK_DIRECTORIES})
60         SET(RULE_CHECKER_LIBRARY_DIRECTORIES
61           ${RULE_CHECKER_LIBRARY_DIRECTORIES}
62           ${dir}/rules/PANDA
63         )
64       ENDFOREACH(dir)
65       FIND_PATH(RULE_CHECKER_PATH PANDARuleChecker.class PATHS
66          ${RULE_CHECKER_LIBRARY_DIRECTORIES}
67       )
68       SET(RULE_CHECKER rules.PANDA.PANDARuleChecker)
69     ELSE(PANDAROOT_SOURCE_DIR)
70       MESSAGE(STATUS "Looking for Rule Checker... - No Rules found")
71     ENDIF(PANDAROOT_SOURCE_DIR)
72   ENDIF(CBMROOT_SOURCE_DIR)
73   
74   SET(RULE_CHECKER_PERL_DIRECTORIES)
75   FOREACH(dir ${CHECK_DIRECTORIES})
76     SET(RULE_CHECKER_PERL_DIRECTORIES
77       ${RULE_CHECKER_PERL_DIRECTORIES}
78       ${dir}/patch
79       )
80   ENDFOREACH(dir)
81     
82   FIND_PATH(RULE_CHECKER_PERL_PATH patch4alice.prl PATHS
83       ${RULE_CHECKER_PERL_DIRECTORIES}
84   )
85
86  
87   IF (NOT RULE_CHECKER_PATH)
88     MESSAGE("Looking for Rule Checker... - Not found ")
89     SET(RULE_CHECKER_FOUND "NO")
90   ELSE (NOT RULE_CHECKER_PATH)
91     MESSAGE(STATUS "Looking for Rule Checker... - found ${RULE_CHECKER_PATH}") 
92     SET(RULE_CHECKER_FOUND "YES")
93     SET(RULE_CHECKER_PERL ${RULE_CHECKER_PERL_PATH}/patch4alice.prl)
94     FIND_PATH(RULE_CHECKER_PATH1 rules  PATHS
95         ${CHECK_DIRECTORIES}
96     )
97     SET(RULE_CHECKER_SCRIPT_PATH ${RULE_CHECKER_PATH1}/scripts)
98     IF(CBMROOT_SOURCE_DIR)
99       SET(RULE_CHECKER_SCRIPT ${RULE_CHECKER_SCRIPT_PATH}/createCbmViolationTable.sh)
100       SET(RULE_CHECKER_SCRIPT1 ${RULE_CHECKER_SCRIPT_PATH}/createCbmViolationTable_html.sh)
101     ELSE(CBMROOT_SOURCE_DIR)
102       IF(PANDAROOT_SOURCE_DIR)
103         SET(RULE_CHECKER_SCRIPT ${RULE_CHECKER_SCRIPT_PATH}/createPandaViolationTable.sh)
104         SET(RULE_CHECKER_SCRIPT1 ${RULE_CHECKER_SCRIPT_PATH}/createPandaViolationTable_html.sh)
105       ELSE(PANDAROOT_SOURCE_DIR)
106       ENDIF(PANDAROOT_SOURCE_DIR)
107     ENDIF(CBMROOT_SOURCE_DIR)
108
109     SET(NEW_CLASSPATH "${PATH1}" ${RULE_CHECKER_PATH1})
110     UNIQUE(BLA "${NEW_CLASSPATH}")
111     SET(ENV{NEW_CLASSPATH} ${BLA})
112   ENDIF (NOT RULE_CHECKER_PATH)
113
114   SET(ENV{ALL_RULES} "")
115 endif (JAVA_RUNTIME AND PERL_FOUND)
116
117
118 ###########################################################################
119
120 MACRO(CHECK_RULES INFILES INCLUDE_DIRS_IN RULE_NAME) # _special_inc_dir)
121
122   SET(_special_inc_dir "${ARGV3}")
123 #  IF(${ARGC} EQUAL "4")
124 #    MESSAGE("Arguments: ${ARGC}")
125 #    MESSAGE("SPECIAL: ${_special_inc_dir}")
126 #  ENDIF(${ARGC} EQUAL "4")
127
128   SET(BLA $ENV{ALL_RULES})
129   SET(BLA ${BLA} ${RULE_NAME})
130   SET(ENV{ALL_RULES} "${BLA}")
131
132 #  MESSAGE("Create Rule Checker for ${RULE_NAME}")
133
134   set(_INCLUDE_DIRS)
135   set(_all_files)
136
137   foreach (_current_FILE ${INCLUDE_DIRS_IN})
138     set(_INCLUDE_DIRS ${_INCLUDE_DIRS} -I${_current_FILE})   
139   endforeach (_current_FILE ${INCLUDE_DIRS_IN})
140
141 #  MESSAGE("RULE_CHECKER: ${RULE_CHECKER}")  
142
143   foreach (_current_FILE ${INFILES})
144
145     STRING(REGEX REPLACE "^(.*)\\.(.*)$" "\\1.i" OUTFILE "${_current_FILE}")
146     STRING(REGEX REPLACE "^(.*)\\.(.*)$" "\\1.ii" OUTFILE1 "${_current_FILE}")
147     STRING(REGEX REPLACE "^(.*)\\.(.*)$" "\\1.h" HFILE "${_current_FILE}")
148     STRING(REGEX REPLACE "^(.*)\\.(.*)$" "\\1.viol" VIOLFILE "${_current_FILE}")
149     STRING(REGEX REPLACE "^(.*)\\/(.*)$" "\\1" RELPATH "${_current_FILE}")
150  
151     IF(NOT ${RELPATH} STREQUAL ${_current_FILE})
152 #      MESSAGE("RELPATH: ${RELPATH}")
153       SET(HEADERDIR ${CMAKE_CURRENT_SOURCE_DIR}/${RELPATH})
154       STRING(REGEX REPLACE "^(.*)\\/(.*)$" "\\2" HFILE2 "${HFILE}")
155 #      SET(HFILE ${HFILE2})
156       STRING(REGEX REPLACE "^(.*)\\/(.*)$" "\\2" OUTFILE2 "${OUTFILE}")
157       SET(OUTFILE ${OUTFILE2})
158       STRING(REGEX REPLACE "^(.*)\\/(.*)$" "\\2" OUTFILE2 "${OUTFILE1}")
159       SET(OUTFILE1 ${OUTFILE2})
160       STRING(REGEX REPLACE "^(.*)\\/(.*)$" "\\2" VIOLFILE2 "${VIOLFILE}")
161       SET(VIOLFILE ${VIOLFILE2})
162       IF(${ARGC} EQUAL "4")
163         SET(HEADERDIR ${CMAKE_CURRENT_SOURCE_DIR}/${RELPATH}/${_special_inc_dir})
164         SET(HFILE ${CMAKE_CURRENT_SOURCE_DIR}/${RELPATH}/${_special_inc_dir}/${HFILE2})
165 #        MESSAGE(HEADERDIR: ${HEADERDIR})
166       ENDIF(${ARGC} EQUAL "4")
167     ELSE(NOT ${RELPATH} STREQUAL ${_current_FILE})
168       SET(HEADERDIR ${CMAKE_CURRENT_SOURCE_DIR})
169     ENDIF(NOT ${RELPATH} STREQUAL ${_current_FILE})
170
171     SET(_current_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${_current_FILE}")
172
173     ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${OUTFILE} ${CMAKE_CURRENT_BINARY_DIR}/${OUTFILE1} ${CMAKE_CURRENT_BINARY_DIR}/${VIOLFILE} 
174      COMMAND g++ -E ${_INCLUDE_DIRS}  -o  ${OUTFILE} ${_current_FILE}
175      COMMAND ${RULE_CHECKER_PERL} ${OUTFILE}
176      COMMAND ${JAVA_RUNTIME} ${RULE_CHECKER} ${OUTFILE} ${HEADERDIR} > ${VIOLFILE}
177      DEPENDS  ${_current_FILE}  ${HFILE})
178  
179     set(_all_files ${_all_files}  ${CMAKE_CURRENT_BINARY_DIR}/${VIOLFILE})
180
181   endforeach (_current_FILE ${INFILES})
182
183   ADD_CUSTOM_TARGET(${RULE_NAME} 
184      COMMAND touch ${CMAKE_BINARY_DIR}/${RULE_NAME}
185      DEPENDS ${_all_files})
186
187 ENDMACRO(CHECK_RULES)