Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8be3928638ece5b4bd940a99ebd2da7aeb25fd69
[simgrid.git] / buildtools / Cmake / GenerateDoc.cmake
1 if(BIBTEX2HTML)
2         set(BIBTEX2HTML_PATH ${BIBTEX2HTML})
3 else(BIBTEX2HTML)
4         find_path(BIBTEX2HTML_PATH      NAMES bibtex2html       PATHS NO_DEFAULT_PATHS)
5 endif(BIBTEX2HTML)
6
7 find_path(FIG2DEV_PATH  NAMES fig2dev   PATHS NO_DEFAULT_PATHS)
8 find_path(DOXYGEN_PATH  NAMES doxygen   PATHS NO_DEFAULT_PATHS)
9 find_path(BIBTOOL_PATH  NAMES bibtool   PATHS NO_DEFAULT_PATHS)
10 find_path(ICONV_PATH    NAMES iconv     PATHS NO_DEFAULT_PATHS)
11
12 ### Check whether the bibtex2html that we found is the one that Arnaud requires
13 exec_program("${BIBTEX2HTML_PATH}/bibtex2html -version" OUTPUT_VARIABLE OUTPUT_BIBTEX2HTML_VERSION)
14 STRING(REPLACE "[-bibtex]" "" OUTPUT_BIBTEX2HTML_VERSION_2 ${OUTPUT_BIBTEX2HTML_VERSION})
15
16 file(GLOB_RECURSE source_doxygen
17         "${CMAKE_HOME_DIRECTORY}/tools/gras/*.[chl]"
18         "${CMAKE_HOME_DIRECTORY}/src/*.[chl]"
19         "${CMAKE_HOME_DIRECTORY}/include/*.[chl]"
20 )
21
22 if(${OUTPUT_BIBTEX2HTML_VERSION_2} STREQUAL ${OUTPUT_BIBTEX2HTML_VERSION}) # wrong version
23         SET(GOOD_BIBTEX2HTML_VERSION 0)
24 else(${OUTPUT_BIBTEX2HTML_VERSION_2} STREQUAL ${OUTPUT_BIBTEX2HTML_VERSION}) # good version
25         SET(GOOD_BIBTEX2HTML_VERSION 1)
26 endif(${OUTPUT_BIBTEX2HTML_VERSION_2} STREQUAL ${OUTPUT_BIBTEX2HTML_VERSION})
27
28 if(DOXYGEN_PATH AND FIG2DEV_PATH AND BIBTOOL_PATH AND BIBTEX2HTML_PATH AND ICONV_PATH AND GOOD_BIBTEX2HTML_VERSION)
29
30         string(REGEX REPLACE ";.*logcategories.doc" "" LISTE_DEUX "${LISTE_DEUX}")
31
32         #DOC_SOURCE=doc/*.doc, defined in DefinePackage
33         set(DOCSSOURCES "${source_doxygen}\n${DOC_SOURCE}")
34         string(REPLACE "\n" ";" DOCSSOURCES ${DOCSSOURCES})
35
36
37         set(DOC_PNGS 
38                 ${CMAKE_HOME_DIRECTORY}/doc/webcruft/simgrid_logo.png
39                 ${CMAKE_HOME_DIRECTORY}/doc/webcruft/simgrid_logo_small.png
40                 ${CMAKE_HOME_DIRECTORY}/doc/webcruft/poster_thumbnail.png
41         )
42         
43         configure_file(${CMAKE_HOME_DIRECTORY}/doc/Doxyfile.in ${CMAKE_HOME_DIRECTORY}/doc/Doxyfile @ONLY)
44         configure_file(${CMAKE_HOME_DIRECTORY}/doc/footer.html.in ${CMAKE_HOME_DIRECTORY}/doc/footer.html @ONLY)                
45         
46         ADD_CUSTOM_TARGET(simgrid_documentation
47                 COMMENT "Generating the SimGrid documentation..."
48                 DEPENDS ${DOC_SOURCES} ${DOC_FIGS} ${source_doxygen}
49                 COMMAND ${FIG2DEV_PATH}/fig2dev -Lmap ${CMAKE_HOME_DIRECTORY}/doc/fig/simgrid_modules.fig | perl -pe 's/imagemap/simgrid_modules/g'| perl -pe 's/<IMG/<IMG style=border:0px/g' | ${CMAKE_HOME_DIRECTORY}/tools/doxygen/fig2dev_postprocessor.pl > ${CMAKE_HOME_DIRECTORY}/doc/simgrid_modules.map
50                 WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/doc
51         )
52
53         ADD_CUSTOM_COMMAND(
54                 OUTPUT ${CMAKE_HOME_DIRECTORY}/doc/logcategories.doc
55                 DEPENDS ${source_doxygen}
56                 COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_HOME_DIRECTORY}/doc/logcategories.doc
57                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/xbt_log_extract_hierarchy.pl > ${CMAKE_HOME_DIRECTORY}/doc/logcategories.doc
58                 WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
59         )
60
61         foreach(file ${DOC_FIGS})
62                 string(REPLACE ".fig" ".png" tmp_file ${file})
63                 string(REPLACE "${CMAKE_HOME_DIRECTORY}/doc/fig/" "${CMAKE_HOME_DIRECTORY}/doc/html/" tmp_file ${tmp_file})
64                 ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
65                         COMMAND ${FIG2DEV_PATH}/fig2dev -Lpng ${file} ${tmp_file}
66                 )
67         endforeach(file ${DOC_FIGS})
68         
69         foreach(file ${DOC_PNGS})
70                 ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
71                         COMMAND ${CMAKE_COMMAND} -E copy ${file} ${CMAKE_HOME_DIRECTORY}/doc/html/
72                 )
73         endforeach(file ${DOC_PNGS})
74
75         ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
76                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/doc/webcruft/Paje_MSG_screenshot_thn.jpg ${CMAKE_HOME_DIRECTORY}/doc/html/
77                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/doc/webcruft/Paje_MSG_screenshot.jpg     ${CMAKE_HOME_DIRECTORY}/doc/html/
78                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/doc/triva-graph_configuration.png        ${CMAKE_HOME_DIRECTORY}/doc/html/
79                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/doc/triva-graph_visualization.png        ${CMAKE_HOME_DIRECTORY}/doc/html/
80                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/doc/simgrid.css                          ${CMAKE_HOME_DIRECTORY}/doc/html/
81         )
82         
83         ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
84             COMMAND ${CMAKE_COMMAND} -E echo "XX First Doxygen pass"
85                 COMMAND ${DOXYGEN_PATH}/doxygen Doxyfile
86                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/index_create.pl simgrid.tag index-API.doc
87                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/toc_create.pl FAQ.doc index.doc contrib.doc gtut-introduction.doc history.doc
88                 
89                 COMMAND ${CMAKE_COMMAND} -E echo "XX Second Doxygen pass"
90                 COMMAND ${DOXYGEN_PATH}/doxygen Doxyfile
91                 
92                 COMMAND ${CMAKE_COMMAND} -E echo "XX Post-processing Doxygen result"
93                 COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/doc/html/dir*
94                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/index_php.pl index.php.in html/index.html index.php
95                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/doxygen_postprocesser.pl
96         
97                 COMMAND ${CMAKE_COMMAND} -E echo "XX Create shortcuts pages"
98                 COMMAND ${CMAKE_COMMAND} -E echo \"<html><META HTTP-EQUIV='Refresh' content='0;URL=http://simgrid.gforge.inria.fr/doc/group__GRAS__API.html'>\" > ${CMAKE_HOME_DIRECTORY}/doc/html/gras.html
99                 COMMAND ${CMAKE_COMMAND} -E echo \"<center><h2><br><a href='http://simgrid.gforge.inria.fr/doc/group__GRAS__API.html'>Grid Reality And Simulation.</a></h2></center></html>\" >> ${CMAKE_HOME_DIRECTORY}/doc/html/gras.html
100                 
101                 COMMAND ${CMAKE_COMMAND} -E echo \"<html><META HTTP-EQUIV='Refresh' content='0;URL=http://simgrid.gforge.inria.fr/doc/group__AMOK__API.html'>\" > ${CMAKE_HOME_DIRECTORY}/doc/html/amok.html
102                 COMMAND ${CMAKE_COMMAND} -E echo \"<center><h2><br><a href='http://simgrid.gforge.inria.fr/doc/group__AMOK__API.html'>Advanced Metacomputing Overlay Kit.</a></h2></center></html>\" >> ${CMAKE_HOME_DIRECTORY}/doc/html/amok.html
103         
104                 COMMAND ${CMAKE_COMMAND} -E echo \"<html><META HTTP-EQUIV='Refresh' content='0;URL=http://simgrid.gforge.inria.fr/doc/group__MSG__API.html'>\" > ${CMAKE_HOME_DIRECTORY}/doc/html/msg.html
105                 COMMAND ${CMAKE_COMMAND} -E echo \"<center><h2><br><a href='http://simgrid.gforge.inria.fr/doc/group__MSG__API.html'>Meta SimGrid.</a></h2></center></html>\" >> ${CMAKE_HOME_DIRECTORY}/doc/html/msg.html
106         
107                 COMMAND ${CMAKE_COMMAND} -E echo \"<html><META HTTP-EQUIV='Refresh' content='0;URL=http://simgrid.gforge.inria.fr/doc/group__SD__API.html'>\" > ${CMAKE_HOME_DIRECTORY}/doc/html/simdag.html
108                 COMMAND ${CMAKE_COMMAND} -E echo \"<center><h2><br><a href='http://simgrid.gforge.inria.fr/doc/group__SD__API.html'>DAG Simulator.</a></h2></center></html>\" >> ${CMAKE_HOME_DIRECTORY}/doc/html/simdag.html
109                 WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/doc/
110         )
111
112         ADD_CUSTOM_TARGET(bib_files
113                 DEPENDS ${CMAKE_HOME_DIRECTORY}/doc/all.bib
114                 COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_HOME_DIRECTORY}/doc/html
115                 COMMAND ${CMAKE_COMMAND} -E make_directory   ${CMAKE_HOME_DIRECTORY}/doc/html
116                 COMMAND ${CMAKE_COMMAND} -E echo "XX Generate publis_core.bib publis_extern.bib publis_intra.bib"
117                 COMMAND ${BIBTOOL_PATH}/bibtool -- 'select.by.string={category \"core\"}' -- 'preserve.key.case={on}' -- 'preserve.keys={on}' all.bib -o publis_core.bib
118                 COMMAND ${BIBTOOL_PATH}/bibtool -- 'select.by.string={category \"extern\"}' -- 'preserve.key.case={on}' -- 'preserve.keys={on}' all.bib -o publis_extern.bib
119                 COMMAND ${BIBTOOL_PATH}/bibtool -- 'select.by.string={category \"intra\"}' -- 'preserve.key.case={on}' -- 'preserve.keys={on}' all.bib -o publis_intra.bib
120
121                 COMMAND ${CMAKE_COMMAND} -E echo "XX Generate publis_count.html"
122                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/bibtex2html_table_count.pl < ${CMAKE_HOME_DIRECTORY}/doc/all.bib > ${CMAKE_HOME_DIRECTORY}/doc/publis_count.html
123                 
124                 COMMAND ${CMAKE_COMMAND} -E echo "XX Generate publis_core.html publis_extern.html publis_intra.html"
125                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/bibtex2html_wrapper.pl publis_core
126                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/bibtex2html_wrapper.pl publis_extern
127                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/bibtex2html_wrapper.pl publis_intra
128                 
129                 WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/doc/
130         )
131
132         add_dependencies(simgrid_documentation bib_files)
133         
134 else(DOXYGEN_PATH AND FIG2DEV_PATH AND BIBTOOL_PATH AND BIBTEX2HTML_PATH AND ICONV_PATH AND GOOD_BIBTEX2HTML_VERSION)
135
136         ADD_CUSTOM_TARGET(simgrid_documentation
137                         COMMENT "Generating the SimGrid documentation..."
138                         )
139
140         if(NOT GOOD_BIBTEX2HTML_VERSION) # wrong version
141                 ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
142                         COMMAND ${CMAKE_COMMAND} -E echo "This is not the good bibtex2html program !!!"
143                         COMMAND ${CMAKE_COMMAND} -E echo  "You can download it from:"
144                         COMMAND ${CMAKE_COMMAND} -E echo  "  ftp://ftp-sop.inria.fr/epidaure/Softs/bibtex2html/bibtex2html-1.02.tar.gz"
145                         COMMAND ${CMAKE_COMMAND} -E echo  "There is also an unofficial Debian/Ubuntu package, see:"
146                         COMMAND ${CMAKE_COMMAND} -E echo  "  http://www.loria.fr/~lnussbau/bibtex2html/README"
147                         )
148         endif(NOT GOOD_BIBTEX2HTML_VERSION)
149
150         ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
151                         COMMAND ${CMAKE_COMMAND} -E echo "DOXYGEN_PATH          = ${DOXYGEN_PATH}"
152                         COMMAND ${CMAKE_COMMAND} -E echo "FIG2DEV_PATH          = ${FIG2DEV_PATH}"
153                         COMMAND ${CMAKE_COMMAND} -E echo "BIBTOOL_PATH          = ${BIBTOOL_PATH}"
154                         COMMAND ${CMAKE_COMMAND} -E echo "BIBTEX2HTML_PATH      = ${BIBTEX2HTML_PATH}"
155                         COMMAND ${CMAKE_COMMAND} -E echo "ICONV_PATH            = ${ICONV_PATH}"
156                         COMMAND ${CMAKE_COMMAND} -E echo "IN ORDER TO GENERATE THE DOCUMENTATION YOU NEED ALL TOOLS !!!"
157                         COMMAND ${CMAKE_COMMAND} -E echo "FAIL TO MAKE SIMGRID DOCUMENTATION see previous messages for details ..."
158                         COMMAND false
159                         )
160
161                 
162 endif(DOXYGEN_PATH AND FIG2DEV_PATH AND BIBTOOL_PATH AND BIBTEX2HTML_PATH AND ICONV_PATH AND GOOD_BIBTEX2HTML_VERSION)
163
164 ##############################################################################"
165
166 message(STATUS "Check individual TOCs")
167 file(GLOB_RECURSE LISTE_GTUT
168         "${CMAKE_HOME_DIRECTORY}/doc/gtut-tour-*.doc"
169 )
170 foreach(file_name ${LISTE_GTUT})
171         file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc)
172         file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc)
173         
174         file(READ "${file_name}" file_content)
175         string(REGEX MATCH "Table of Contents.*<hr>" valeur_line "${file_content}")
176         string(REPLACE "\n" ";" valeur_line "${valeur_line}")
177         string(REPLACE "\n" ";" file_content "${file_content}")
178         
179         foreach(line ${file_content})
180                 string(REGEX MATCH "[\\]s?u?b?s?u?b?section.*" line2 "${line}")
181                 string(REGEX MATCH ".*_toc.*" line3 "${line}")
182                 if(line2 AND NOT line3)
183                         string(REPLACE "\\section " "" line2 ${line2})
184                         string(REPLACE "\\subsection " "subsection" line2 ${line2})
185                         string(REPLACE "\\subsubsection " "subsubsection" line2 ${line2})
186                         string(REGEX REPLACE " .*" "" line2 ${line2})
187                         set(line2                               " - \\ref ${line2}")
188                         string(REPLACE " - \\ref subsection"    "   - \\ref " line2 ${line2})
189                         string(REPLACE " - \\ref subsubsection" "     - \\ref " line2 ${line2})
190                         file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc "${line2}\n")
191                 endif(line2 AND NOT line3)
192         endforeach(line ${file_content})
193         
194         foreach(line ${valeur_line})
195                 string(REGEX MATCH ".*ref.*" line_ok ${line})
196                 if(line_ok)
197                         file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc "${line_ok}\n")
198                 endif(line_ok)
199         endforeach(line ${valeur_line})
200         
201         exec_program("${CMAKE_COMMAND} -E compare_files ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc" OUTPUT_VARIABLE compare_files)
202         if(compare_files)
203                 message(STATUS "Wrong toc for ${file_name}. Should be:")
204                 file(READ "${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc" file_content)
205                 message("${file_content}")
206                 exec_program("diff -u ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc")
207         endif(compare_files)
208 endforeach(file_name ${LISTE_GTUT})
209
210 file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc)
211 file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc)
212
213 message(STATUS "Check main TOC")
214
215 foreach(file_name ${LISTE_GTUT})
216         file(READ "${file_name}" file_content)  
217         string(REGEX MATCH "Table of Contents.*<hr>" valeur_line "${file_content}")
218         string(REPLACE "\n" ";" valeur_line "${valeur_line}")
219         string(REPLACE "\n" ";" file_content "${file_content}")
220         
221         foreach(line ${file_content})
222                 string(REGEX MATCH ".*@page.*" line2 "${line}")
223                 if(line2)
224                         string(REPLACE "@page " "" line2 "${line2}")
225                         string(REGEX REPLACE " .*" "" line2 "${line2}")
226                         set(line2 " - \\ref ${line2}")
227                         file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc "${line2}\n")
228                 endif(line2)
229         endforeach(line ${file_content})
230         
231         foreach(line ${valeur_line})
232                 string(REGEX MATCH ".*toc.*" line1 "${line}")
233                 string(REGEX MATCH ".*<hr>.*" line2 "${line}")
234                 string(REGEX MATCH "^[ ]*$" line3 "${line}")
235                 string(REGEX MATCH "Table of Contents" line4 "${line}")
236                 if(NOT line1 AND NOT line2 AND NOT line3 AND NOT line4)
237                         file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc "   ${line}\n")
238                 endif(NOT line1 AND NOT line2 AND NOT line3 AND NOT line4)
239         endforeach(line ${valeur_line})
240 endforeach(file_name ${LISTE_GTUT})     
241
242 file(READ "${CMAKE_HOME_DIRECTORY}/doc/gtut-tour.doc" file_content)
243 string(REPLACE "\n" ";" file_content "${file_content}")
244 foreach(line ${file_content})
245         string(REGEX MATCH "^[ ]+.*\\ref" line1 "${line}")
246         if(line1)
247                 file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc "${line}\n")
248         endif(line1)
249 endforeach(line ${file_content})
250         
251 exec_program("${CMAKE_COMMAND} -E compare_files ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc" OUTPUT_VARIABLE compare_files)
252 if(compare_files)
253         message(STATUS "Wrong toc for gtut-tour.doc Right one is in tmp.realtoc")
254         exec_program("diff -u ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc")
255 else(compare_files)
256         file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc)
257 endif(compare_files)    
258   
259 file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc)