fine tuning of TOF tail (developing task)
[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
6b06712c 8cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
6db31708 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
e3d9d369 15find_file(RULECHECKER_JAR NAMES NewRuleChecker.jar PATHS ${CMAKE_SOURCE_DIR}/RuleChecker NO_DEFAULT_PATH)
16find_file(RULECHECKER_RULES NAMES CodingConventions.xml PATHS ${CMAKE_SOURCE_DIR}/RuleChecker NO_DEFAULT_PATH)
17find_file(FACTEXTRACTOR_JAR NAMES FactExtractor.jar PATHS ${CMAKE_SOURCE_DIR}/RuleChecker NO_DEFAULT_PATH)
18find_file(SMELLDETECTOR_JAR NAMES SmellDetector.jar PATHS ${CMAKE_SOURCE_DIR}/RuleChecker NO_DEFAULT_PATH)
19if(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME AND SMELLDETECTOR_JAR)
20 set(RULECHECKER_FOUND TRUE)
21 message(STATUS "RuleChecker jar : ${RULECHECKER_JAR}")
22 message(STATUS "RuleChecker rules : ${RULECHECKER_RULES}")
23 message(STATUS "RuleChecker factextractor : ${FACTEXTRACTOR_JAR}")
24 message(STATUS "RuleChecker smelldetector : ${SMELLDETECTOR_JAR}")
25 message(STATUS "RuleChecker found on the system")
26
27 if(NOT EXISTS ${CMAKE_BINARY_DIR}/check-hxml-touchfile)
28 file(WRITE ${CMAKE_BINARY_DIR}/check-hxml-touchfile "Dummy dependency for factfile")
29 endif(NOT EXISTS ${CMAKE_BINARY_DIR}/check-hxml-touchfile)
30 set(FACTFILE ${CMAKE_BINARY_DIR}/factFile.xml)
31 set(_factfile_deps)
32
33 file(GLOB_RECURSE _root_headers ${ROOTSYS}/include/*.h)
34 foreach(_root_header ${_root_headers})
35 if(NOT _root_header MATCHES ".*G__ci.h")
36 string (REGEX REPLACE "${ROOTSYS}/include/" "" _rel_root_header ${_root_header})
37 string (REGEX REPLACE "h$" "h.xml" _rel_root_hxml ${_rel_root_header})
38 get_filename_component(_rel_root_header_path ${_rel_root_hxml} PATH)
39 set(_root_hxml ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_hxml})
40 if(NOT EXISTS ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_header_path})
41 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_header_path})
42 endif(NOT EXISTS ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_header_path})
43 list(APPEND _factfile_deps ${_root_hxml})
44 add_custom_command(OUTPUT ${_root_hxml}
58a019bc 45 COMMAND ${RULECHECKER_SRCML} ${_root_header} -o ${_root_hxml}
e3d9d369 46 DEPENDS ${_root_header})
47 endif(NOT _root_header MATCHES ".*G__ci.h")
48 endforeach(_root_header ${_root_headers})
6db31708 49else()
50 message(STATUS "RuleChecker not found on this system")
e3d9d369 51endif(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME AND SMELLDETECTOR_JAR)
6db31708 52
c2a2c0b8 53macro(ALICE_CheckModule)
54 if(RULECHECKER_FOUND)
811ffdcc 55 set(CHECKDIR ${CMAKE_BINARY_DIR}/${MODULE}/check)
e93f6949 56
57 file(GLOB_RECURSE _headers ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
58 file(GLOB_RECURSE _sources_tmp ${CMAKE_CURRENT_SOURCE_DIR}/*.cxx)
59 list(APPEND _sources_tmp ${_headers})
60 foreach(_srcfile ${_sources_tmp})
61 string(REPLACE ".h" "" _srcfile_tmp ${_srcfile})
62 string(REPLACE ".cxx" "" _srcfile ${_srcfile_tmp})
63 list(APPEND _sources ${_srcfile})
64 endforeach(_srcfile ${_sources_tmp})
65 list(REMOVE_DUPLICATES _sources)
66 list(SORT _sources)
67
68 set(_violfiles)
ae388d3b 69 set(_smellfiles)
e93f6949 70 set(_module_factfile_deps)
71 foreach(_srcfile ${_sources})
58a019bc 72 if(NOT _srcfile MATCHES "^.*LinkDef$" AND NOT _srcfile MATCHES ".*PYTHIA8/pythia8.*" AND NOT _srcfile MATCHES "#.*" AND NOT _srcfile MATCHES ".*~")
e93f6949 73 set(_violdeps)
74 string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" _srcfile_short ${_srcfile})
75 set(_viol ${CHECKDIR}/${_srcfile_short}.viol)
ae388d3b 76 set(_smell ${CHECKDIR}/${_srcfile_short}.smell)
e93f6949 77 get_filename_component(_viol_path ${_viol} PATH)
78 list(APPEND _violfiles ${_viol})
ae388d3b 79 list(APPEND _smellfiles ${_smell})
e93f6949 80 if(EXISTS ${_srcfile}.h)
81 add_custom_command(OUTPUT ${CHECKDIR}/${_srcfile_short}.h.xml
82 COMMAND ${CMAKE_COMMAND} -E make_directory ${_viol_path}
58a019bc 83 COMMAND ${RULECHECKER_SRCML} ${_srcfile}.h -o ${CHECKDIR}/${_srcfile_short}.h.xml
e93f6949 84 COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/check-hxml-touchfile
85 DEPENDS ${_srcfile}.h)
86 list(APPEND _violdeps ${CHECKDIR}/${_srcfile_short}.h.xml)
87 list(APPEND _module_factfile_deps ${CHECKDIR}/${_srcfile_short}.h.xml)
88 endif(EXISTS ${_srcfile}.h)
89 if(EXISTS ${_srcfile}.cxx)
90 add_custom_command(OUTPUT ${CHECKDIR}/${_srcfile_short}.cxx.xml
91 COMMAND ${CMAKE_COMMAND} -E make_directory ${_viol_path}
58a019bc 92 COMMAND ${RULECHECKER_SRCML} ${_srcfile}.cxx -o ${CHECKDIR}/${_srcfile_short}.cxx.xml
e93f6949 93 DEPENDS ${_srcfile}.cxx)
94 list(APPEND _violdeps ${CHECKDIR}/${_srcfile_short}.cxx.xml)
95 endif(EXISTS ${_srcfile}.cxx)
58a019bc 96 # message("Violations are ${_viol}")
e93f6949 97 add_custom_command( OUTPUT ${_viol}
98 COMMAND ${JAVA_RUNTIME} -Xmx1024M -jar ${RULECHECKER_JAR} ${CHECKDIR}/${_srcfile_short}.cxx.xml ${CHECKDIR}/${_srcfile_short}.h.xml ${FACTFILE} ${RULECHECKER_RULES} > ${_viol}
99 DEPENDS ${_violdeps}
100 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
ae388d3b 101 add_custom_command( OUTPUT ${_smell}
102 COMMAND ${JAVA_RUNTIME} -Xmx1024M -jar ${SMELLDETECTOR_JAR} ${CHECKDIR}/${_srcfile_short}.cxx.xml ${CHECKDIR}/${_srcfile_short}.h.xml > ${_smell}
103 DEPENDS ${_violdeps}
104 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
58a019bc 105 endif(NOT _srcfile MATCHES "^.*LinkDef$" AND NOT _srcfile MATCHES ".*PYTHIA8/pythia8.*" AND NOT _srcfile MATCHES "#.*" AND NOT _srcfile MATCHES ".*~")
e93f6949 106 endforeach(_srcfile ${_sources})
107
e93f6949 108 if(_violfiles)
f334159f 109 #
110 if(TARGET ${MODULE}-check)
111 message("Target ${MODULE}-check already exist, apparently created in nested CMakeLists. Skipping")
112 else()
113 add_custom_target(${MODULE}-check DEPENDS ${_violfiles})
114 add_dependencies(${MODULE}-check factfile)
115 add_dependencies(check-all ${MODULE}-check)
116 endif(TARGET ${MODULE}-check)
117 #
118 if(TARGET ${MODULE}-smell)
119 message("Target ${MODULE}-smell already exist, apparently created in nested CMakeLists. Skipping")
120 else()
121 add_custom_target(${MODULE}-smell DEPENDS ${_smellfiles})
122 add_dependencies(smell-all ${MODULE}-smell)
123 endif(TARGET ${MODULE}-smell)
124 #
e93f6949 125 if(_module_factfile_deps)
f334159f 126 #
127 if(TARGET ${MODULE}-hxml)
128 message("Target ${MODULE}-hxml already exist, apparently created in nested CMakeLists. Skipping")
129 else()
130 add_custom_target(${MODULE}-hxml DEPENDS ${_module_factfile_deps})
131 add_dependencies(check-hxml ${MODULE}-hxml)
132 endif(TARGET ${MODULE}-hxml)
133 #
e93f6949 134 endif(_module_factfile_deps)
135 endif(_violfiles)
f334159f 136
c2a2c0b8 137
138 endif(RULECHECKER_FOUND)
139endmacro(ALICE_CheckModule)
140