First step for rulechecker -- not working yet
[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
8cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
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
15set(IRST_INSTALLDIR $ENV{IRST_INSTALLDIR})
16if(NOT IRST_INSTALLDIR)
17 if(ALICE)
c2a2c0b8 18 message(STATUS "Setting IRST_INSTALLDIR to ${ALICE}/local/ALICENewRuleChecker")
20febe5e 19 set(IRST_INSTALLDIR ${ALICE_ROOT}/cmakelocal/ALICENewRuleChecker)
6db31708 20 endif(ALICE)
21endif(NOT IRST_INSTALLDIR)
22
23if(IRST_INSTALLDIR)
20febe5e 24 find_file(RULECHECKER_JAR NAMES NewRuleChecker.jar PATHS ${IRST_INSTALLDIR}/NewRuleChecker ${ALICE_ROOT}/cmake/RuleChecker)
25 find_file(RULECHECKER_RULES NAMES CodingConventions.xml PATHS ${IRST_INSTALLDIR}/NewRuleChecker/config ${ALICE_ROOT}/cmake/RuleChecker)
26 find_file(FACTEXTRACTOR_JAR NAME FactExtractor.jar PATHS ${IRST_INSTALLDIR}/FactExtractor ${ALICE_ROOT}/cmake/RuleChecker)
6db31708 27 if(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME)
28 set(RULECHECKER_FOUND TRUE)
20febe5e 29 message(STATUS "RuleChecker jar : ${RULECHECKER_JAR}")
30 message(STATUS "RuleChecker rules : ${RULECHECKER_RULES}")
31 message(STATUS "RuleChecker factextractor : ${FACTEXTRACTOR_JAR}")
6db31708 32 message(STATUS "RuleChecker found on the system")
62e74968 33
34 set(FACTFILE ${CMAKE_BINARY_DIR}/factFile.xml)
35 set(_factfile_deps)
36
37 file(GLOB_RECURSE _root_headers ${ROOTSYS}/include/*.h)
38 foreach(_root_header ${_root_headers})
39 string (REGEX REPLACE "${ROOTSYS}/include/" "" _rel_root_header ${_root_header})
40 string (REGEX REPLACE "h$" "h.xml" _rel_root_hxml ${_rel_root_header})
41 get_filename_component(_rel_root_header_path ${_rel_root_hxml} PATH)
42 set(_root_hxml roothxml/${_rel_root_hxml})
43 if(NOT EXISTS roothxml/${_rel_root_header_path})
44 file(MAKE_DIRECTORY roothxml/${_rel_root_header_path})
45 endif(NOT EXISTS roothxml/${_rel_root_header_path})
46 list(APPEND _factfile_deps ${_root_hxml})
47 add_custom_command(OUTPUT ${_root_hxml}
48 COMMAND ${RULECHECKER_SRCML} ${_root_header} ${_root_hxml}
49 DEPENDS ${_root_header})
50 endforeach(_root_header ${_root_headers})
6db31708 51 else()
52 message(STATUS "RuleChecker not found on this system")
53 endif(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME)
54else()
55 message(STATUS "RuleChecker not found on this system")
56endif(IRST_INSTALLDIR)
57
c2a2c0b8 58macro(ALICE_CheckModule)
59 if(RULECHECKER_FOUND)
811ffdcc 60 set(CHECKDIR ${CMAKE_BINARY_DIR}/${MODULE}/check)
c2a2c0b8 61 set(violFiles)
8948a174 62
c2a2c0b8 63 foreach(_srcfile ${SRCS})
64 string (REGEX REPLACE "cxx$" "h" _header ${_srcfile})
65 get_filename_component(_srcname ${_srcfile} NAME)
66 string (REGEX REPLACE "cxx$" "viol" _viol ${_srcname})
67 string (REGEX REPLACE "cxx$" "cxx.xml" _srcxml ${_srcname})
68 string (REGEX REPLACE "cxx$" "h.xml" _hxml ${_srcname})
811ffdcc 69 string (REGEX REPLACE ".cxx$" "" _class ${_srcname})
62e74968 70 set(_depends ${_srcfile})
8948a174 71
c2a2c0b8 72 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_header})
62e74968 73 list(APPEND _depends ${_header})
74 list(APPEND _factfile_deps ${_hxml})
c2a2c0b8 75 add_custom_command( OUTPUT ${_viol}
c2a2c0b8 76 COMMAND ${RULECHECKER_SRCML} ${_srcfile} ${CHECKDIR}/${_srcxml}
77 COMMAND ${RULECHECKER_SRCML} ${_header} ${CHECKDIR}/${_hxml}
62e74968 78 COMMAND ${JAVA_RUNTIME} -jar ${RULECHECKER_JAR} ${CHECKDIR}/${_srcxml} ${CHECKDIR}/${_hxml} ${FACTFILE} ${RULECHECKER_RULES} > ${CHECKDIR}/viols/${_viol}
c2a2c0b8 79 DEPENDS ${_depends}
80 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
81 list(APPEND violFiles ${_viol})
82 else()
83 add_custom_command( OUTPUT ${_viol}
c2a2c0b8 84 COMMAND ${RULECHECKER_SRCML} ${_srcfile} ${CHECKDIR}/${_srcxml}
62e74968 85 COMMAND ${JAVA_RUNTIME} -jar ${RULECHECKER_JAR} ${CHECKDIR}/${_srcxml} ${CHECKDIR}/${_hxml} ${FACTFILE} ${RULECHECKER_RULES} > ${CHECKDIR}/viols/${_viol}
c2a2c0b8 86 DEPENDS ${_depends}
87 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
88 list(APPEND violFiles ${_viol})
89 endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_header})
8948a174 90 if(CLASSCHECK STREQUAL "YES")
91 add_custom_target(${MODULE}-${_class}-check DEPENDS ${_viol})
92 endif(CLASSCHECK STREQUAL "YES")
811ffdcc 93 endforeach(_srcfile ${SRCS})
c2a2c0b8 94 if(violFiles)
62e74968 95 add_custom_target(${PACKAGE}-check DEPENDS ${FACTFILE} ${violFiles})
96# add_dependencies(${PACKAGE}-check ${FACTFILE} ${violFiles})
c2a2c0b8 97 add_dependencies(${MODULE}-check-all ${PACKAGE}-check)
98 endif(violFiles)
99 add_custom_command(TARGET clean
100 COMMAND ${CMAKE_COMMAND} -E remove_directory ${CHECKDIR})
101
102 endif(RULECHECKER_FOUND)
103endmacro(ALICE_CheckModule)
104