Updated RuleChecker to V-2,0 and update CMake pkgs for EMCAL
[u/mrichter/AliRoot.git] / cmake / FindRuleChecker.cmake
1 # AliRoot Build System Module to find and configure IRST ALICE Coding Coventions RuleChecker
2 #
3 # Author: Johny Jose (johny.jose@cern.ch)
4 #         Port of previous Makefile build to cmake
5
6 cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
7
8 find_program(RULECHECKER_SRCML NAMES src2srcml)
9 message(STATUS "Check for src2srcml: ${RULECHECKER_SRCML}")
10 find_package(Java)
11 message(STATUS "Check for Java: ${JAVA_RUNTIME}")
12
13 set(IRST_INSTALLDIR $ENV{IRST_INSTALLDIR})
14 if(NOT IRST_INSTALLDIR)
15   if(ALICE)
16     message(STATUS "Setting IRST_INSTALLDIR to ${ALICE}/local/ALICENewRuleChecker")
17     set(IRST_INSTALLDIR ${ALICE}/local/ALICENewRuleChecker)
18   endif(ALICE)
19 endif(NOT IRST_INSTALLDIR)
20
21 if(IRST_INSTALLDIR)
22   find_file(RULECHECKER_JAR NAMES NewRuleChecker.jar PATHS ${IRST_INSTALLDIR}/NewRuleChecker)
23   find_file(RULECHECKER_RULES NAMES CodingConventions.xml PATHS ${IRST_INSTALLDIR}/NewRuleChecker/config)
24   find_file(FACTEXTRACTOR_JAR NAME FactExtractor.jar PATHS ${IRST_INSTALLDIR}/FactExtractor)
25   if(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME)
26     set(RULECHECKER_FOUND TRUE)
27     message(STATUS "RuleChecker found on the system")
28   else()
29     message(STATUS "RuleChecker not found on this system")
30   endif(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME)
31 else()
32   message(STATUS "RuleChecker not found on this system")
33 endif(IRST_INSTALLDIR)
34
35 macro(ALICE_CheckModule)
36   if(RULECHECKER_FOUND)
37     set(CHECKDIR ${ALICE_ROOT}/${MODULE}/check)
38     set(violFiles)
39     foreach(_srcfile ${SRCS})
40       string (REGEX REPLACE "cxx$" "h" _header ${_srcfile})
41       get_filename_component(_srcname ${_srcfile} NAME)
42       string (REGEX REPLACE "cxx$" "viol" _viol ${_srcname})
43       string (REGEX REPLACE "cxx$" "cxx.xml" _srcxml ${_srcname})
44       string (REGEX REPLACE "cxx$" "h.xml" _hxml ${_srcname})
45       set(depends)
46       if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_header})
47         list(APPEND depends ${_header})
48         add_custom_command( OUTPUT ${_viol}
49                           COMMAND ${CMAKE_COMMAND} -E make_directory ${CHECKDIR}
50                           COMMAND ${CMAKE_COMMAND} -E make_directory ${CHECKDIR}/viols
51                           COMMAND ${RULECHECKER_SRCML} ${_srcfile} ${CHECKDIR}/${_srcxml}
52                           COMMAND ${RULECHECKER_SRCML} ${_header} ${CHECKDIR}/${_hxml}
53                           COMMAND ${Java_JAVA_EXECUTABLE} -jar ${FACTEXTRACTOR_JAR} ${CHECKDIR} ${CHECKDIR}
54                           COMMAND ${Java_JAVA_EXECUTABLE} -jar ${RULECHECKER_JAR} ${CHECKDIR}/${_srcxml} ${CHECKDIR}/${_hxml} ${CHECKDIR}/factFile.xml ${RULECHECKER_RULES} > ${CHECKDIR}/viols/${_viol}
55                           DEPENDS ${_depends}
56                           WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
57         list(APPEND violFiles ${_viol})
58       else()
59         add_custom_command( OUTPUT ${_viol}
60                           COMMAND ${CMAKE_COMMAND} -E make_directory ${CHECKDIR}
61                           COMMAND ${CMAKE_COMMAND} -E make_directory ${CHECKDIR}/viols
62                           COMMAND ${RULECHECKER_SRCML} ${_srcfile} ${CHECKDIR}/${_srcxml}
63                           COMMAND ${Java_JAVA_EXECUTABLE} -jar ${FACTEXTRACTOR_JAR} ${CHECKDIR} ${CHECKDIR}
64                           COMMAND ${Java_JAVA_EXECUTABLE} -jar ${RULECHECKER_JAR} ${CHECKDIR}/${_srcxml} ${CHECKDIR}/${_hxml} ${CHECKDIR}/factFile.xml ${RULECHECKER_RULES} > ${CHECKDIR}/viols/${_viol}
65                           DEPENDS ${_depends}
66                           WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
67         list(APPEND violFiles ${_viol})
68       endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_header})
69       endforeach(_srcfile ${SRCS})
70     if(violFiles)
71       add_custom_target(${PACKAGE}-check DEPENDS ${violFiles})
72       add_dependencies(${PACKAGE}-check ${violFiles})
73       add_dependencies(${MODULE}-check-all ${PACKAGE}-check)
74     endif(violFiles)
75     add_custom_command(TARGET clean
76                        COMMAND ${CMAKE_COMMAND} -E remove_directory ${CHECKDIR})
77
78   endif(RULECHECKER_FOUND)
79 endmacro(ALICE_CheckModule)
80