3 # AliRoot Build System Module to find and configure IRST ALICE Coding Coventions RuleChecker
5 # Author: Johny Jose (johny.jose@cern.ch)
6 # Port of previous Makefile build to cmake
8 cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
10 find_program(RULECHECKER_SRCML NAMES src2srcml)
11 message(STATUS "Check for src2srcml: ${RULECHECKER_SRCML}")
13 message(STATUS "Check for Java: ${JAVA_RUNTIME}")
15 set(IRST_INSTALLDIR $ENV{IRST_INSTALLDIR})
16 if(NOT IRST_INSTALLDIR)
18 message(STATUS "Setting IRST_INSTALLDIR to ${ALICE}/local/ALICENewRuleChecker")
19 set(IRST_INSTALLDIR ${ALICE}/local/ALICENewRuleChecker)
21 endif(NOT IRST_INSTALLDIR)
24 find_file(RULECHECKER_JAR NAMES NewRuleChecker.jar PATHS ${IRST_INSTALLDIR}/NewRuleChecker NO_DEFAULT_PATH)
25 find_file(RULECHECKER_RULES NAMES CodingConventions.xml PATHS ${IRST_INSTALLDIR}/NewRuleChecker/config NO_DEFAULT_PATH)
26 find_file(FACTEXTRACTOR_JAR NAMES FactExtractor.jar PATHS ${IRST_INSTALLDIR}/FactExtractor NO_DEFAULT_PATH)
27 if(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME)
28 set(RULECHECKER_FOUND TRUE)
29 message(STATUS "RuleChecker jar : ${RULECHECKER_JAR}")
30 message(STATUS "RuleChecker rules : ${RULECHECKER_RULES}")
31 message(STATUS "RuleChecker factextractor : ${FACTEXTRACTOR_JAR}")
32 message(STATUS "RuleChecker found on the system")
34 if(NOT EXISTS ${CMAKE_BINARY_DIR}/check-hxml-touchfile)
35 file(WRITE ${CMAKE_BINARY_DIR}/check-hxml-touchfile "Dummy dependency for factfile")
36 endif(NOT EXISTS ${CMAKE_BINARY_DIR}/check-hxml-touchfile)
37 set(FACTFILE ${CMAKE_BINARY_DIR}/factFile.xml)
40 file(GLOB_RECURSE _root_headers ${ROOTSYS}/include/*.h)
41 foreach(_root_header ${_root_headers})
42 if(NOT _root_header MATCHES ".*G__ci.h")
43 string (REGEX REPLACE "${ROOTSYS}/include/" "" _rel_root_header ${_root_header})
44 string (REGEX REPLACE "h$" "h.xml" _rel_root_hxml ${_rel_root_header})
45 get_filename_component(_rel_root_header_path ${_rel_root_hxml} PATH)
46 set(_root_hxml ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_hxml})
47 if(NOT EXISTS ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_header_path})
48 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_header_path})
49 endif(NOT EXISTS ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_header_path})
50 list(APPEND _factfile_deps ${_root_hxml})
51 add_custom_command(OUTPUT ${_root_hxml}
52 COMMAND ${RULECHECKER_SRCML} ${_root_header} ${_root_hxml}
53 DEPENDS ${_root_header})
54 endif(NOT _root_header MATCHES ".*G__ci.h")
55 endforeach(_root_header ${_root_headers})
57 message(STATUS "RuleChecker not found on this system")
58 endif(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME)
60 message(STATUS "RuleChecker not found on this system")
61 endif(IRST_INSTALLDIR)
63 macro(ALICE_CheckModule)
65 set(CHECKDIR ${CMAKE_BINARY_DIR}/${MODULE}/check)
67 file(GLOB_RECURSE _headers ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
68 file(GLOB_RECURSE _sources_tmp ${CMAKE_CURRENT_SOURCE_DIR}/*.cxx)
69 list(APPEND _sources_tmp ${_headers})
70 foreach(_srcfile ${_sources_tmp})
71 string(REPLACE ".h" "" _srcfile_tmp ${_srcfile})
72 string(REPLACE ".cxx" "" _srcfile ${_srcfile_tmp})
73 list(APPEND _sources ${_srcfile})
74 endforeach(_srcfile ${_sources_tmp})
75 list(REMOVE_DUPLICATES _sources)
79 set(_module_factfile_deps)
80 foreach(_srcfile ${_sources})
81 if(NOT _srcfile MATCHES "^.*LinkDef$" AND NOT _srcfile MATCHES ".*PYTHIA8/pythia8.*")
83 string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" _srcfile_short ${_srcfile})
84 set(_viol ${CHECKDIR}/${_srcfile_short}.viol)
85 get_filename_component(_viol_path ${_viol} PATH)
86 list(APPEND _violfiles ${_viol})
87 if(EXISTS ${_srcfile}.h)
88 add_custom_command(OUTPUT ${CHECKDIR}/${_srcfile_short}.h.xml
89 COMMAND ${CMAKE_COMMAND} -E make_directory ${_viol_path}
90 COMMAND ${RULECHECKER_SRCML} ${_srcfile}.h ${CHECKDIR}/${_srcfile_short}.h.xml
91 COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/check-hxml-touchfile
92 DEPENDS ${_srcfile}.h)
93 list(APPEND _violdeps ${CHECKDIR}/${_srcfile_short}.h.xml)
94 list(APPEND _module_factfile_deps ${CHECKDIR}/${_srcfile_short}.h.xml)
95 endif(EXISTS ${_srcfile}.h)
96 if(EXISTS ${_srcfile}.cxx)
97 add_custom_command(OUTPUT ${CHECKDIR}/${_srcfile_short}.cxx.xml
98 COMMAND ${CMAKE_COMMAND} -E make_directory ${_viol_path}
99 COMMAND ${RULECHECKER_SRCML} ${_srcfile}.cxx ${CHECKDIR}/${_srcfile_short}.cxx.xml
100 DEPENDS ${_srcfile}.cxx)
101 list(APPEND _violdeps ${CHECKDIR}/${_srcfile_short}.cxx.xml)
102 endif(EXISTS ${_srcfile}.cxx)
103 add_custom_command( OUTPUT ${_viol}
104 COMMAND ${JAVA_RUNTIME} -Xmx1024M -jar ${RULECHECKER_JAR} ${CHECKDIR}/${_srcfile_short}.cxx.xml ${CHECKDIR}/${_srcfile_short}.h.xml ${FACTFILE} ${RULECHECKER_RULES} > ${_viol}
106 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
107 endif(NOT _srcfile MATCHES "^.*LinkDef$" AND NOT _srcfile MATCHES ".*PYTHIA8/pythia8.*")
108 endforeach(_srcfile ${_sources})
112 add_custom_target(${MODULE}-check DEPENDS ${_violfiles})
113 add_dependencies(${MODULE}-check factfile)
114 add_dependencies(check-all ${MODULE}-check)
116 if(_module_factfile_deps)
117 add_custom_target(${MODULE}-hxml DEPENDS ${_module_factfile_deps})
118 add_dependencies(check-hxml ${MODULE}-hxml)
119 endif(_module_factfile_deps)
123 endif(RULECHECKER_FOUND)
124 endmacro(ALICE_CheckModule)