Updated RuleChecker to V-2,0 and update CMake pkgs for EMCAL
[u/mrichter/AliRoot.git] / cmake / FindRuleChecker.cmake
CommitLineData
6db31708 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
6cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
7
8find_program(RULECHECKER_SRCML NAMES src2srcml)
9message(STATUS "Check for src2srcml: ${RULECHECKER_SRCML}")
10find_package(Java)
11message(STATUS "Check for Java: ${JAVA_RUNTIME}")
12
13set(IRST_INSTALLDIR $ENV{IRST_INSTALLDIR})
14if(NOT IRST_INSTALLDIR)
15 if(ALICE)
c2a2c0b8 16 message(STATUS "Setting IRST_INSTALLDIR to ${ALICE}/local/ALICENewRuleChecker")
6db31708 17 set(IRST_INSTALLDIR ${ALICE}/local/ALICENewRuleChecker)
18 endif(ALICE)
19endif(NOT IRST_INSTALLDIR)
20
21if(IRST_INSTALLDIR)
c2a2c0b8 22 find_file(RULECHECKER_JAR NAMES NewRuleChecker.jar PATHS ${IRST_INSTALLDIR}/NewRuleChecker)
7eaa67f4 23 find_file(RULECHECKER_RULES NAMES CodingConventions.xml PATHS ${IRST_INSTALLDIR}/NewRuleChecker/config)
c2a2c0b8 24 find_file(FACTEXTRACTOR_JAR NAME FactExtractor.jar PATHS ${IRST_INSTALLDIR}/FactExtractor)
6db31708 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)
31else()
32 message(STATUS "RuleChecker not found on this system")
33endif(IRST_INSTALLDIR)
34
c2a2c0b8 35macro(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)
79endmacro(ALICE_CheckModule)
80