Added RuleChecker jars in trunk and updated CMake .pkg files
[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")
20febe5e 17 set(IRST_INSTALLDIR ${ALICE_ROOT}/cmakelocal/ALICENewRuleChecker)
6db31708 18 endif(ALICE)
19endif(NOT IRST_INSTALLDIR)
20
21if(IRST_INSTALLDIR)
20febe5e 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)
6db31708 25 if(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME)
26 set(RULECHECKER_FOUND TRUE)
20febe5e 27 message(STATUS "RuleChecker jar : ${RULECHECKER_JAR}")
28 message(STATUS "RuleChecker rules : ${RULECHECKER_RULES}")
29 message(STATUS "RuleChecker factextractor : ${FACTEXTRACTOR_JAR}")
6db31708 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)
34else()
35 message(STATUS "RuleChecker not found on this system")
36endif(IRST_INSTALLDIR)
37
c2a2c0b8 38macro(ALICE_CheckModule)
39 if(RULECHECKER_FOUND)
811ffdcc 40 set(CHECKDIR ${CMAKE_BINARY_DIR}/${MODULE}/check)
c2a2c0b8 41 set(violFiles)
8948a174 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
c2a2c0b8 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})
811ffdcc 54 string (REGEX REPLACE ".cxx$" "" _class ${_srcname})
8948a174 55 set(_depends ${_srcfile} ${MODULE}-${PACKAGE}-factFile)
56
c2a2c0b8 57 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_header})
58 list(APPEND depends ${_header})
59 add_custom_command( OUTPUT ${_viol}
c2a2c0b8 60 COMMAND ${RULECHECKER_SRCML} ${_srcfile} ${CHECKDIR}/${_srcxml}
61 COMMAND ${RULECHECKER_SRCML} ${_header} ${CHECKDIR}/${_hxml}
811ffdcc 62 COMMAND ${JAVA_RUNTIME} -jar ${RULECHECKER_JAR} ${CHECKDIR}/${_srcxml} ${CHECKDIR}/${_hxml} ${CHECKDIR}/factFile.xml ${RULECHECKER_RULES} > ${CHECKDIR}/viols/${_viol}
c2a2c0b8 63 DEPENDS ${_depends}
64 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
65 list(APPEND violFiles ${_viol})
66 else()
67 add_custom_command( OUTPUT ${_viol}
c2a2c0b8 68 COMMAND ${RULECHECKER_SRCML} ${_srcfile} ${CHECKDIR}/${_srcxml}
811ffdcc 69 COMMAND ${JAVA_RUNTIME} -jar ${RULECHECKER_JAR} ${CHECKDIR}/${_srcxml} ${CHECKDIR}/${_hxml} ${CHECKDIR}/factFile.xml ${RULECHECKER_RULES} > ${CHECKDIR}/viols/${_viol}
c2a2c0b8 70 DEPENDS ${_depends}
71 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
72 list(APPEND violFiles ${_viol})
73 endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_header})
8948a174 74 if(CLASSCHECK STREQUAL "YES")
75 add_custom_target(${MODULE}-${_class}-check DEPENDS ${_viol})
76 endif(CLASSCHECK STREQUAL "YES")
811ffdcc 77 endforeach(_srcfile ${SRCS})
c2a2c0b8 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)
87endmacro(ALICE_CheckModule)
88