]>
Commit | Line | Data |
---|---|---|
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 | ||
6b06712c | 8 | cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR) |
6db31708 | 9 | |
10 | find_program(RULECHECKER_SRCML NAMES src2srcml) | |
11 | message(STATUS "Check for src2srcml: ${RULECHECKER_SRCML}") | |
12 | find_package(Java) | |
13 | message(STATUS "Check for Java: ${JAVA_RUNTIME}") | |
14 | ||
e3d9d369 | 15 | find_file(RULECHECKER_JAR NAMES NewRuleChecker.jar PATHS ${CMAKE_SOURCE_DIR}/RuleChecker NO_DEFAULT_PATH) |
16 | find_file(RULECHECKER_RULES NAMES CodingConventions.xml PATHS ${CMAKE_SOURCE_DIR}/RuleChecker NO_DEFAULT_PATH) | |
17 | find_file(FACTEXTRACTOR_JAR NAMES FactExtractor.jar PATHS ${CMAKE_SOURCE_DIR}/RuleChecker NO_DEFAULT_PATH) | |
18 | find_file(SMELLDETECTOR_JAR NAMES SmellDetector.jar PATHS ${CMAKE_SOURCE_DIR}/RuleChecker NO_DEFAULT_PATH) | |
19 | if(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME AND SMELLDETECTOR_JAR) | |
20 | set(RULECHECKER_FOUND TRUE) | |
21 | message(STATUS "RuleChecker jar : ${RULECHECKER_JAR}") | |
22 | message(STATUS "RuleChecker rules : ${RULECHECKER_RULES}") | |
23 | message(STATUS "RuleChecker factextractor : ${FACTEXTRACTOR_JAR}") | |
24 | message(STATUS "RuleChecker smelldetector : ${SMELLDETECTOR_JAR}") | |
25 | message(STATUS "RuleChecker found on the system") | |
26 | ||
27 | if(NOT EXISTS ${CMAKE_BINARY_DIR}/check-hxml-touchfile) | |
28 | file(WRITE ${CMAKE_BINARY_DIR}/check-hxml-touchfile "Dummy dependency for factfile") | |
29 | endif(NOT EXISTS ${CMAKE_BINARY_DIR}/check-hxml-touchfile) | |
30 | set(FACTFILE ${CMAKE_BINARY_DIR}/factFile.xml) | |
31 | set(_factfile_deps) | |
32 | ||
33 | file(GLOB_RECURSE _root_headers ${ROOTSYS}/include/*.h) | |
34 | foreach(_root_header ${_root_headers}) | |
35 | if(NOT _root_header MATCHES ".*G__ci.h") | |
36 | string (REGEX REPLACE "${ROOTSYS}/include/" "" _rel_root_header ${_root_header}) | |
37 | string (REGEX REPLACE "h$" "h.xml" _rel_root_hxml ${_rel_root_header}) | |
38 | get_filename_component(_rel_root_header_path ${_rel_root_hxml} PATH) | |
39 | set(_root_hxml ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_hxml}) | |
40 | if(NOT EXISTS ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_header_path}) | |
41 | file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_header_path}) | |
42 | endif(NOT EXISTS ${CMAKE_BINARY_DIR}/roothxml/${_rel_root_header_path}) | |
43 | list(APPEND _factfile_deps ${_root_hxml}) | |
44 | add_custom_command(OUTPUT ${_root_hxml} | |
45 | COMMAND ${RULECHECKER_SRCML} ${_root_header} ${_root_hxml} | |
46 | DEPENDS ${_root_header}) | |
47 | endif(NOT _root_header MATCHES ".*G__ci.h") | |
48 | endforeach(_root_header ${_root_headers}) | |
6db31708 | 49 | else() |
50 | message(STATUS "RuleChecker not found on this system") | |
e3d9d369 | 51 | endif(RULECHECKER_JAR AND RULECHECKER_RULES AND RULECHECKER_SRCML AND JAVA_RUNTIME AND SMELLDETECTOR_JAR) |
6db31708 | 52 | |
c2a2c0b8 | 53 | macro(ALICE_CheckModule) |
54 | if(RULECHECKER_FOUND) | |
811ffdcc | 55 | set(CHECKDIR ${CMAKE_BINARY_DIR}/${MODULE}/check) |
e93f6949 | 56 | |
57 | file(GLOB_RECURSE _headers ${CMAKE_CURRENT_SOURCE_DIR}/*.h) | |
58 | file(GLOB_RECURSE _sources_tmp ${CMAKE_CURRENT_SOURCE_DIR}/*.cxx) | |
59 | list(APPEND _sources_tmp ${_headers}) | |
60 | foreach(_srcfile ${_sources_tmp}) | |
61 | string(REPLACE ".h" "" _srcfile_tmp ${_srcfile}) | |
62 | string(REPLACE ".cxx" "" _srcfile ${_srcfile_tmp}) | |
63 | list(APPEND _sources ${_srcfile}) | |
64 | endforeach(_srcfile ${_sources_tmp}) | |
65 | list(REMOVE_DUPLICATES _sources) | |
66 | list(SORT _sources) | |
67 | ||
68 | set(_violfiles) | |
ae388d3b | 69 | set(_smellfiles) |
e93f6949 | 70 | set(_module_factfile_deps) |
71 | foreach(_srcfile ${_sources}) | |
72 | if(NOT _srcfile MATCHES "^.*LinkDef$" AND NOT _srcfile MATCHES ".*PYTHIA8/pythia8.*") | |
73 | set(_violdeps) | |
74 | string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" _srcfile_short ${_srcfile}) | |
75 | set(_viol ${CHECKDIR}/${_srcfile_short}.viol) | |
ae388d3b | 76 | set(_smell ${CHECKDIR}/${_srcfile_short}.smell) |
e93f6949 | 77 | get_filename_component(_viol_path ${_viol} PATH) |
78 | list(APPEND _violfiles ${_viol}) | |
ae388d3b | 79 | list(APPEND _smellfiles ${_smell}) |
e93f6949 | 80 | if(EXISTS ${_srcfile}.h) |
81 | add_custom_command(OUTPUT ${CHECKDIR}/${_srcfile_short}.h.xml | |
82 | COMMAND ${CMAKE_COMMAND} -E make_directory ${_viol_path} | |
83 | COMMAND ${RULECHECKER_SRCML} ${_srcfile}.h ${CHECKDIR}/${_srcfile_short}.h.xml | |
84 | COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/check-hxml-touchfile | |
85 | DEPENDS ${_srcfile}.h) | |
86 | list(APPEND _violdeps ${CHECKDIR}/${_srcfile_short}.h.xml) | |
87 | list(APPEND _module_factfile_deps ${CHECKDIR}/${_srcfile_short}.h.xml) | |
88 | endif(EXISTS ${_srcfile}.h) | |
89 | if(EXISTS ${_srcfile}.cxx) | |
90 | add_custom_command(OUTPUT ${CHECKDIR}/${_srcfile_short}.cxx.xml | |
91 | COMMAND ${CMAKE_COMMAND} -E make_directory ${_viol_path} | |
92 | COMMAND ${RULECHECKER_SRCML} ${_srcfile}.cxx ${CHECKDIR}/${_srcfile_short}.cxx.xml | |
93 | DEPENDS ${_srcfile}.cxx) | |
94 | list(APPEND _violdeps ${CHECKDIR}/${_srcfile_short}.cxx.xml) | |
95 | endif(EXISTS ${_srcfile}.cxx) | |
96 | add_custom_command( OUTPUT ${_viol} | |
97 | COMMAND ${JAVA_RUNTIME} -Xmx1024M -jar ${RULECHECKER_JAR} ${CHECKDIR}/${_srcfile_short}.cxx.xml ${CHECKDIR}/${_srcfile_short}.h.xml ${FACTFILE} ${RULECHECKER_RULES} > ${_viol} | |
98 | DEPENDS ${_violdeps} | |
99 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | |
ae388d3b | 100 | add_custom_command( OUTPUT ${_smell} |
101 | COMMAND ${JAVA_RUNTIME} -Xmx1024M -jar ${SMELLDETECTOR_JAR} ${CHECKDIR}/${_srcfile_short}.cxx.xml ${CHECKDIR}/${_srcfile_short}.h.xml > ${_smell} | |
102 | DEPENDS ${_violdeps} | |
103 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | |
e93f6949 | 104 | endif(NOT _srcfile MATCHES "^.*LinkDef$" AND NOT _srcfile MATCHES ".*PYTHIA8/pythia8.*") |
105 | endforeach(_srcfile ${_sources}) | |
106 | ||
e93f6949 | 107 | if(_violfiles) |
108 | add_custom_target(${MODULE}-check DEPENDS ${_violfiles}) | |
109 | add_dependencies(${MODULE}-check factfile) | |
110 | add_dependencies(check-all ${MODULE}-check) | |
111 | ||
ae388d3b | 112 | add_custom_target(${MODULE}-smell DEPENDS ${_smellfiles}) |
113 | add_dependencies(smell-all ${MODULE}-smell) | |
114 | ||
e93f6949 | 115 | if(_module_factfile_deps) |
116 | add_custom_target(${MODULE}-hxml DEPENDS ${_module_factfile_deps}) | |
117 | add_dependencies(check-hxml ${MODULE}-hxml) | |
118 | endif(_module_factfile_deps) | |
119 | endif(_violfiles) | |
120 | ||
c2a2c0b8 | 121 | |
122 | endif(RULECHECKER_FOUND) | |
123 | endmacro(ALICE_CheckModule) | |
124 |