Introduce smell generator plus some small fixes
[u/mrichter/AliRoot.git] / cmake / FindRuleChecker.cmake
CommitLineData
62e74968 1# -*- mode: cmake -*-
2
6db31708 3# AliRoot Build System Module to find and configure IRST ALICE Coding Coventions RuleChecker
4#
5# Author: Johny Jose (johny.jose@cern.ch)
6# Port of previous Makefile build to cmake
7
8cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
9
10find_program(RULECHECKER_SRCML NAMES src2srcml)
11message(STATUS "Check for src2srcml: ${RULECHECKER_SRCML}")
12find_package(Java)
13message(STATUS "Check for Java: ${JAVA_RUNTIME}")
14
15set(IRST_INSTALLDIR $ENV{IRST_INSTALLDIR})
16if(NOT IRST_INSTALLDIR)
17 if(ALICE)
c2a2c0b8 18 message(STATUS "Setting IRST_INSTALLDIR to ${ALICE}/local/ALICENewRuleChecker")
e93f6949 19 set(IRST_INSTALLDIR ${ALICE}/local/ALICENewRuleChecker)
6db31708 20 endif(ALICE)
21endif(NOT IRST_INSTALLDIR)
22
23if(IRST_INSTALLDIR)
e93f6949 24 find_file(RULECHECKER_JAR NAMES NewRuleChecker.jar PATHS ${IRST_INSTALLDIR}/NewRuleChecker NO_DEFAULT_PATH)
25 find_file(RULECHECKER_RULES NAMES CodingConventions.xml PATHS ${IRST_INSTALLDIR}/NewRuleChecker/config NO_DEFAULT_PATH)
26 find_file(FACTEXTRACTOR_JAR NAMES FactExtractor.jar PATHS ${IRST_INSTALLDIR}/FactExtractor NO_DEFAULT_PATH)
ae388d3b 27 find_file(SMELLDETECTOR_JAR NAMES SmellDetector.jar PATHS ${IRST_INSTALLDIR} NO_DEFAULT_PATH)
28 if(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME AND SMELLDETECTOR_JAR)
6db31708 29 set(RULECHECKER_FOUND TRUE)
ae388d3b 30 message(STATUS "RuleChecker jar : ${RULECHECKER_JAR}")
31 message(STATUS "RuleChecker rules : ${RULECHECKER_RULES}")
20febe5e 32 message(STATUS "RuleChecker factextractor : ${FACTEXTRACTOR_JAR}")
ae388d3b 33 message(STATUS "RuleChecker smelldetector : ${SMELLDETECTOR_JAR}")
6db31708 34 message(STATUS "RuleChecker found on the system")
62e74968 35
e93f6949 36 if(NOT EXISTS ${CMAKE_BINARY_DIR}/check-hxml-touchfile)
37 file(WRITE ${CMAKE_BINARY_DIR}/check-hxml-touchfile "Dummy dependency for factfile")
38 endif(NOT EXISTS ${CMAKE_BINARY_DIR}/check-hxml-touchfile)
62e74968 39 set(FACTFILE ${CMAKE_BINARY_DIR}/factFile.xml)
40 set(_factfile_deps)
41
42 file(GLOB_RECURSE _root_headers ${ROOTSYS}/include/*.h)
43 foreach(_root_header ${_root_headers})
e93f6949 44 if(NOT _root_header MATCHES ".*G__ci.h")
45 string (REGEX REPLACE "${ROOTSYS}/include/" "" _rel_root_header ${_root_header})
46 string (REGEX REPLACE "h$" "h.xml" _rel_root_hxml ${_rel_root_header})
47 get_filename_component(_rel_root_header_path ${_rel_root_hxml} PATH)
48 set(_root_hxml ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_hxml})
49 if(NOT EXISTS ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_header_path})
50 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_header_path})
51 endif(NOT EXISTS ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_header_path})
52 list(APPEND _factfile_deps ${_root_hxml})
53 add_custom_command(OUTPUT ${_root_hxml}
54 COMMAND ${RULECHECKER_SRCML} ${_root_header} ${_root_hxml}
55 DEPENDS ${_root_header})
56 endif(NOT _root_header MATCHES ".*G__ci.h")
62e74968 57 endforeach(_root_header ${_root_headers})
6db31708 58 else()
59 message(STATUS "RuleChecker not found on this system")
ae388d3b 60 endif(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME AND SMELLDETECTOR_JAR)
6db31708 61else()
62 message(STATUS "RuleChecker not found on this system")
63endif(IRST_INSTALLDIR)
64
c2a2c0b8 65macro(ALICE_CheckModule)
66 if(RULECHECKER_FOUND)
811ffdcc 67 set(CHECKDIR ${CMAKE_BINARY_DIR}/${MODULE}/check)
e93f6949 68
69 file(GLOB_RECURSE _headers ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
70 file(GLOB_RECURSE _sources_tmp ${CMAKE_CURRENT_SOURCE_DIR}/*.cxx)
71 list(APPEND _sources_tmp ${_headers})
72 foreach(_srcfile ${_sources_tmp})
73 string(REPLACE ".h" "" _srcfile_tmp ${_srcfile})
74 string(REPLACE ".cxx" "" _srcfile ${_srcfile_tmp})
75 list(APPEND _sources ${_srcfile})
76 endforeach(_srcfile ${_sources_tmp})
77 list(REMOVE_DUPLICATES _sources)
78 list(SORT _sources)
79
80 set(_violfiles)
ae388d3b 81 set(_smellfiles)
e93f6949 82 set(_module_factfile_deps)
83 foreach(_srcfile ${_sources})
84 if(NOT _srcfile MATCHES "^.*LinkDef$" AND NOT _srcfile MATCHES ".*PYTHIA8/pythia8.*")
85 set(_violdeps)
86 string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" _srcfile_short ${_srcfile})
87 set(_viol ${CHECKDIR}/${_srcfile_short}.viol)
ae388d3b 88 set(_smell ${CHECKDIR}/${_srcfile_short}.smell)
e93f6949 89 get_filename_component(_viol_path ${_viol} PATH)
90 list(APPEND _violfiles ${_viol})
ae388d3b 91 list(APPEND _smellfiles ${_smell})
e93f6949 92 if(EXISTS ${_srcfile}.h)
93 add_custom_command(OUTPUT ${CHECKDIR}/${_srcfile_short}.h.xml
94 COMMAND ${CMAKE_COMMAND} -E make_directory ${_viol_path}
95 COMMAND ${RULECHECKER_SRCML} ${_srcfile}.h ${CHECKDIR}/${_srcfile_short}.h.xml
96 COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/check-hxml-touchfile
97 DEPENDS ${_srcfile}.h)
98 list(APPEND _violdeps ${CHECKDIR}/${_srcfile_short}.h.xml)
99 list(APPEND _module_factfile_deps ${CHECKDIR}/${_srcfile_short}.h.xml)
100 endif(EXISTS ${_srcfile}.h)
101 if(EXISTS ${_srcfile}.cxx)
102 add_custom_command(OUTPUT ${CHECKDIR}/${_srcfile_short}.cxx.xml
103 COMMAND ${CMAKE_COMMAND} -E make_directory ${_viol_path}
104 COMMAND ${RULECHECKER_SRCML} ${_srcfile}.cxx ${CHECKDIR}/${_srcfile_short}.cxx.xml
105 DEPENDS ${_srcfile}.cxx)
106 list(APPEND _violdeps ${CHECKDIR}/${_srcfile_short}.cxx.xml)
107 endif(EXISTS ${_srcfile}.cxx)
108 add_custom_command( OUTPUT ${_viol}
109 COMMAND ${JAVA_RUNTIME} -Xmx1024M -jar ${RULECHECKER_JAR} ${CHECKDIR}/${_srcfile_short}.cxx.xml ${CHECKDIR}/${_srcfile_short}.h.xml ${FACTFILE} ${RULECHECKER_RULES} > ${_viol}
110 DEPENDS ${_violdeps}
111 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
ae388d3b 112 add_custom_command( OUTPUT ${_smell}
113 COMMAND ${JAVA_RUNTIME} -Xmx1024M -jar ${SMELLDETECTOR_JAR} ${CHECKDIR}/${_srcfile_short}.cxx.xml ${CHECKDIR}/${_srcfile_short}.h.xml > ${_smell}
114 DEPENDS ${_violdeps}
115 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
e93f6949 116 endif(NOT _srcfile MATCHES "^.*LinkDef$" AND NOT _srcfile MATCHES ".*PYTHIA8/pythia8.*")
117 endforeach(_srcfile ${_sources})
118
e93f6949 119 if(_violfiles)
120 add_custom_target(${MODULE}-check DEPENDS ${_violfiles})
121 add_dependencies(${MODULE}-check factfile)
122 add_dependencies(check-all ${MODULE}-check)
123
ae388d3b 124 add_custom_target(${MODULE}-smell DEPENDS ${_smellfiles})
125 add_dependencies(smell-all ${MODULE}-smell)
126
e93f6949 127 if(_module_factfile_deps)
128 add_custom_target(${MODULE}-hxml DEPENDS ${_module_factfile_deps})
129 add_dependencies(check-hxml ${MODULE}-hxml)
130 endif(_module_factfile_deps)
131 endif(_violfiles)
132
c2a2c0b8 133
134 endif(RULECHECKER_FOUND)
135endmacro(ALICE_CheckModule)
136