Added RuleChecker jars in trunk and updated CMake .pkg files
[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_ROOT}/cmakelocal/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 ${ALICE_ROOT}/cmake/RuleChecker)
23   find_file(RULECHECKER_RULES NAMES CodingConventions.xml PATHS ${IRST_INSTALLDIR}/NewRuleChecker/config ${ALICE_ROOT}/cmake/RuleChecker)
24   find_file(FACTEXTRACTOR_JAR NAME FactExtractor.jar PATHS ${IRST_INSTALLDIR}/FactExtractor ${ALICE_ROOT}/cmake/RuleChecker)
25   if(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME)
26     set(RULECHECKER_FOUND TRUE)
27     message(STATUS "RuleChecker jar : ${RULECHECKER_JAR}")
28     message(STATUS "RuleChecker rules : ${RULECHECKER_RULES}")
29     message(STATUS "RuleChecker factextractor : ${FACTEXTRACTOR_JAR}")
30     message(STATUS "RuleChecker found on the system")
31   else()
32     message(STATUS "RuleChecker not found on this system")
33   endif(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME)
34 else()
35   message(STATUS "RuleChecker not found on this system")
36 endif(IRST_INSTALLDIR)
37
38 macro(ALICE_CheckModule)
39   if(RULECHECKER_FOUND)
40     set(CHECKDIR ${CMAKE_BINARY_DIR}/${MODULE}/check)
41     set(violFiles)
42     add_custom_command( OUTPUT ${MODULE}-${PACKAGE}-factFile
43                         COMMAND ${CMAKE_COMMAND} -E make_directory ${CHECKDIR}
44                         COMMAND ${CMAKE_COMMAND} -E make_directory ${CHECKDIR}/viols
45                         COMMAND ${JAVA_RUNTIME} -jar ${FACTEXTRACTOR_JAR} ${CHECKDIR} ${CHECKDIR} 
46                         WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
47
48     foreach(_srcfile ${SRCS})
49       string (REGEX REPLACE "cxx$" "h" _header ${_srcfile})
50       get_filename_component(_srcname ${_srcfile} NAME)
51       string (REGEX REPLACE "cxx$" "viol" _viol ${_srcname})
52       string (REGEX REPLACE "cxx$" "cxx.xml" _srcxml ${_srcname})
53       string (REGEX REPLACE "cxx$" "h.xml" _hxml ${_srcname})
54       string (REGEX REPLACE ".cxx$" "" _class ${_srcname})
55       set(_depends ${_srcfile} ${MODULE}-${PACKAGE}-factFile)
56
57       if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_header})
58         list(APPEND depends ${_header})
59         add_custom_command( OUTPUT ${_viol}
60                           COMMAND ${RULECHECKER_SRCML} ${_srcfile} ${CHECKDIR}/${_srcxml}
61                           COMMAND ${RULECHECKER_SRCML} ${_header} ${CHECKDIR}/${_hxml}
62                           COMMAND ${JAVA_RUNTIME} -jar ${RULECHECKER_JAR} ${CHECKDIR}/${_srcxml} ${CHECKDIR}/${_hxml} ${CHECKDIR}/factFile.xml ${RULECHECKER_RULES} > ${CHECKDIR}/viols/${_viol}
63                           DEPENDS ${_depends}
64                           WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
65         list(APPEND violFiles ${_viol})
66       else()
67         add_custom_command( OUTPUT ${_viol}
68                           COMMAND ${RULECHECKER_SRCML} ${_srcfile} ${CHECKDIR}/${_srcxml}
69                           COMMAND ${JAVA_RUNTIME} -jar ${RULECHECKER_JAR} ${CHECKDIR}/${_srcxml} ${CHECKDIR}/${_hxml} ${CHECKDIR}/factFile.xml ${RULECHECKER_RULES} > ${CHECKDIR}/viols/${_viol}
70                           DEPENDS ${_depends}
71                           WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
72         list(APPEND violFiles ${_viol})
73       endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_header})
74       if(CLASSCHECK STREQUAL "YES")
75         add_custom_target(${MODULE}-${_class}-check DEPENDS ${_viol})
76       endif(CLASSCHECK STREQUAL "YES")
77     endforeach(_srcfile ${SRCS})
78     if(violFiles)
79       add_custom_target(${PACKAGE}-check DEPENDS ${violFiles})
80       add_dependencies(${PACKAGE}-check ${violFiles})
81       add_dependencies(${MODULE}-check-all ${PACKAGE}-check)
82     endif(violFiles)
83     add_custom_command(TARGET clean
84                        COMMAND ${CMAKE_COMMAND} -E remove_directory ${CHECKDIR})
85
86   endif(RULECHECKER_FOUND)
87 endmacro(ALICE_CheckModule)
88