Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
bbcd09790e27021949e1d709bdc242fcef92b9b7
[simgrid.git] / buildtools / Cmake / GenerateDoc.cmake
1 #### Generate the html documentation
2
3 if(BIBTEX2HTML)
4         set(BIBTEX2HTML_PATH ${BIBTEX2HTML})
5 else(BIBTEX2HTML)
6         find_path(BIBTEX2HTML_PATH      NAMES bibtex2html       PATHS NO_DEFAULT_PATHS)
7 endif(BIBTEX2HTML)
8
9 find_path(FIG2DEV_PATH  NAMES fig2dev   PATHS NO_DEFAULT_PATHS)
10 find_path(DOXYGEN_PATH  NAMES doxygen   PATHS NO_DEFAULT_PATHS)
11 find_path(BIBTOOL_PATH  NAMES bibtool   PATHS NO_DEFAULT_PATHS)
12 find_path(ICONV_PATH    NAMES iconv     PATHS NO_DEFAULT_PATHS)
13
14 ### Check whether the bibtex2html that we found is the one that Arnaud requires
15 exec_program("${BIBTEX2HTML_PATH}/bibtex2html -version" OUTPUT_VARIABLE OUTPUT_BIBTEX2HTML_VERSION)
16 STRING(REPLACE "[-bibtex]" "" OUTPUT_BIBTEX2HTML_VERSION_2 ${OUTPUT_BIBTEX2HTML_VERSION})
17
18 file(GLOB_RECURSE source_doxygen
19         "${CMAKE_HOME_DIRECTORY}/tools/gras/*.[chl]"
20         "${CMAKE_HOME_DIRECTORY}/src/*.[chl]"
21         "${CMAKE_HOME_DIRECTORY}/include/*.[chl]"
22 )
23
24 if(${OUTPUT_BIBTEX2HTML_VERSION_2} STREQUAL ${OUTPUT_BIBTEX2HTML_VERSION}) # wrong version
25         SET(GOOD_BIBTEX2HTML_VERSION 0)
26 else(${OUTPUT_BIBTEX2HTML_VERSION_2} STREQUAL ${OUTPUT_BIBTEX2HTML_VERSION}) # good version
27         SET(GOOD_BIBTEX2HTML_VERSION 1)
28 endif(${OUTPUT_BIBTEX2HTML_VERSION_2} STREQUAL ${OUTPUT_BIBTEX2HTML_VERSION})
29
30 if(DOXYGEN_PATH AND FIG2DEV_PATH AND BIBTOOL_PATH AND BIBTEX2HTML_PATH AND ICONV_PATH AND GOOD_BIBTEX2HTML_VERSION)
31
32         string(REGEX REPLACE ";.*logcategories.doc" "" LISTE_DEUX "${LISTE_DEUX}")
33
34         #DOC_SOURCE=doc/*.doc, defined in DefinePackage
35         set(DOCSSOURCES "${source_doxygen}\n${DOC_SOURCE}")
36         string(REPLACE "\n" ";" DOCSSOURCES ${DOCSSOURCES})
37
38
39         set(DOC_PNGS 
40                 ${CMAKE_HOME_DIRECTORY}/doc/webcruft/simgrid_logo.png
41                 ${CMAKE_HOME_DIRECTORY}/doc/webcruft/simgrid_logo_small.png
42                 ${CMAKE_HOME_DIRECTORY}/doc/webcruft/poster_thumbnail.png
43         )
44         
45         configure_file(${CMAKE_HOME_DIRECTORY}/doc/Doxyfile.in ${CMAKE_HOME_DIRECTORY}/doc/Doxyfile @ONLY)
46         configure_file(${CMAKE_HOME_DIRECTORY}/doc/footer.html.in ${CMAKE_HOME_DIRECTORY}/doc/footer.html @ONLY)                
47         
48         ADD_CUSTOM_TARGET(simgrid_documentation
49                 COMMENT "Generating the SimGrid documentation..."
50                 DEPENDS ${DOC_SOURCES} ${DOC_FIGS} ${source_doxygen}
51                 COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_HOME_DIRECTORY}/doc/html
52             COMMAND ${CMAKE_COMMAND} -E make_directory   ${CMAKE_HOME_DIRECTORY}/doc/html
53                 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
54                 WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/doc
55         )
56                 
57         ADD_CUSTOM_COMMAND(
58                 OUTPUT ${CMAKE_HOME_DIRECTORY}/doc/logcategories.doc
59                 DEPENDS ${source_doxygen}
60                 COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_HOME_DIRECTORY}/doc/logcategories.doc
61                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/xbt_log_extract_hierarchy.pl > ${CMAKE_HOME_DIRECTORY}/doc/logcategories.doc
62                 WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
63         )
64
65         foreach(file ${DOC_FIGS})
66                 string(REPLACE ".fig" ".png" tmp_file ${file})
67                 string(REPLACE "${CMAKE_HOME_DIRECTORY}/doc/fig/" "${CMAKE_HOME_DIRECTORY}/doc/html/" tmp_file ${tmp_file})
68                 ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
69                         COMMAND ${FIG2DEV_PATH}/fig2dev -Lpng ${file} ${tmp_file}
70                 )
71         endforeach(file ${DOC_FIGS})
72         
73         foreach(file ${DOC_PNGS})
74                 ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
75                         COMMAND ${CMAKE_COMMAND} -E copy ${file} ${CMAKE_HOME_DIRECTORY}/doc/html/
76                 )
77         endforeach(file ${DOC_PNGS})
78
79         ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
80                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/doc/webcruft/Paje_MSG_screenshot_thn.jpg ${CMAKE_HOME_DIRECTORY}/doc/html/
81                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/doc/webcruft/Paje_MSG_screenshot.jpg     ${CMAKE_HOME_DIRECTORY}/doc/html/
82                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/doc/triva-graph_configuration.png        ${CMAKE_HOME_DIRECTORY}/doc/html/
83                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/doc/triva-graph_visualization.png        ${CMAKE_HOME_DIRECTORY}/doc/html/
84                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/doc/simgrid.css                          ${CMAKE_HOME_DIRECTORY}/doc/html/
85         )
86         
87         ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
88             COMMAND ${CMAKE_COMMAND} -E echo "XX First Doxygen pass"
89                 COMMAND ${DOXYGEN_PATH}/doxygen Doxyfile
90                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/index_create.pl simgrid.tag index-API.doc
91                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/toc_create.pl index.doc gtut-introduction.doc installSimgrid.doc bindings.doc options.doc
92                 
93                 COMMAND ${CMAKE_COMMAND} -E echo "XX Second Doxygen pass"
94                 COMMAND ${DOXYGEN_PATH}/doxygen Doxyfile
95                 
96                 COMMAND ${CMAKE_COMMAND} -E echo "XX Post-processing Doxygen result"
97                 COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/doc/html/dir*
98                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/doxygen_postprocesser.pl
99                 
100                 COMMAND ${CMAKE_COMMAND} -E echo "XX Create shortcuts pages"
101                 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
102                 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
103                 
104                 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
105                 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
106         
107                 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
108                 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
109         
110                 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
111                 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
112                 WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/doc/
113         )
114         
115 else(DOXYGEN_PATH AND FIG2DEV_PATH AND BIBTOOL_PATH AND BIBTEX2HTML_PATH AND ICONV_PATH AND GOOD_BIBTEX2HTML_VERSION)
116
117         ADD_CUSTOM_TARGET(simgrid_documentation
118                         COMMENT "Generating the SimGrid documentation..."
119                         )
120
121         if(NOT GOOD_BIBTEX2HTML_VERSION) # wrong version
122                 ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
123                         COMMAND ${CMAKE_COMMAND} -E echo "This is not the good bibtex2html program !!!"
124                         COMMAND ${CMAKE_COMMAND} -E echo  "You can download it from:"
125                         COMMAND ${CMAKE_COMMAND} -E echo  "  ftp://ftp-sop.inria.fr/epidaure/Softs/bibtex2html/bibtex2html-1.02.tar.gz"
126                         COMMAND ${CMAKE_COMMAND} -E echo  "There is also an unofficial Debian/Ubuntu package, see:"
127                         COMMAND ${CMAKE_COMMAND} -E echo  "  http://www.loria.fr/~lnussbau/bibtex2html/README"
128                         )
129         endif(NOT GOOD_BIBTEX2HTML_VERSION)
130
131         ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
132                         COMMAND ${CMAKE_COMMAND} -E echo "DOXYGEN_PATH          = ${DOXYGEN_PATH}"
133                         COMMAND ${CMAKE_COMMAND} -E echo "FIG2DEV_PATH          = ${FIG2DEV_PATH}"
134                         COMMAND ${CMAKE_COMMAND} -E echo "BIBTOOL_PATH          = ${BIBTOOL_PATH}"
135                         COMMAND ${CMAKE_COMMAND} -E echo "BIBTEX2HTML_PATH      = ${BIBTEX2HTML_PATH}"
136                         COMMAND ${CMAKE_COMMAND} -E echo "ICONV_PATH            = ${ICONV_PATH}"
137                         COMMAND ${CMAKE_COMMAND} -E echo "IN ORDER TO GENERATE THE DOCUMENTATION YOU NEED ALL TOOLS !!!"
138                         COMMAND ${CMAKE_COMMAND} -E echo "FAIL TO MAKE SIMGRID DOCUMENTATION see previous messages for details ..."
139                         COMMAND false
140                         )
141
142                 
143 endif(DOXYGEN_PATH AND FIG2DEV_PATH AND BIBTOOL_PATH AND BIBTEX2HTML_PATH AND ICONV_PATH AND GOOD_BIBTEX2HTML_VERSION)
144
145 ##############################################################################"
146
147 message(STATUS "Check individual TOCs")
148 set(LISTE_GTUT
149         doc/gtut-tour-00-install.doc
150         doc/gtut-tour-01-bones.doc
151         doc/gtut-tour-02-simple.doc
152         doc/gtut-tour-03-args.doc
153         doc/gtut-tour-04-callback.doc
154         doc/gtut-tour-05-globals.doc
155         doc/gtut-tour-06-logs.doc
156         doc/gtut-tour-07-timers.doc
157         doc/gtut-tour-08-exceptions.doc
158         doc/gtut-tour-09-simpledata.doc
159         doc/gtut-tour-10-rpc.doc
160         doc/gtut-tour-11-explicitwait.doc
161         doc/gtut-tour-recap-messages.doc
162         doc/gtut-tour-12-staticstruct.doc
163         doc/gtut-tour-13-pointers.doc
164         doc/gtut-tour-14-dynar.doc
165         doc/gtut-tour-15-manualdatadef.doc
166         doc/gtut-tour-16-exchangecb.doc
167 )
168
169 foreach(file_name ${LISTE_GTUT})
170         file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc)
171         file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc)
172         
173         file(READ "${file_name}" file_content)
174         string(REGEX MATCH "Table of Contents.*<hr>" valeur_line "${file_content}")
175         string(REPLACE "\n" ";" valeur_line "${valeur_line}")
176         string(REPLACE "\n" ";" file_content "${file_content}")
177                
178         file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc "\n") # make sure it exists
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         file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc "\n") # make sure it exists
195         foreach(line ${valeur_line})
196                 string(REGEX MATCH ".*ref.*" line_ok ${line})
197                 if(line_ok)
198                         file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc "${line_ok}\n")
199                 endif(line_ok)
200         endforeach(line ${valeur_line})
201         
202         exec_program("${CMAKE_COMMAND} -E compare_files ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc" OUTPUT_VARIABLE compare_files)
203         if(compare_files)
204                 message(STATUS "Wrong toc for ${file_name}. Should be:")
205                 file(READ "${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc" file_content)
206                 message("${file_content}")
207                 exec_program("diff -u ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc")
208         endif(compare_files)
209 endforeach(file_name ${LISTE_GTUT})
210
211 file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc)
212 file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc)
213
214 message(STATUS "Check main TOC")
215
216 foreach(file_name ${LISTE_GTUT})
217         file(READ "${file_name}" file_content)  
218         string(REGEX MATCH "Table of Contents.*<hr>" valeur_line "${file_content}")
219         string(REPLACE "\n" ";" valeur_line "${valeur_line}")
220         string(REPLACE "\n" ";" file_content "${file_content}")
221         
222         foreach(line ${file_content})
223                 string(REGEX MATCH ".*@page.*" line2 "${line}")
224                 if(line2)
225                         string(REPLACE "@page " "" line2 "${line2}")
226                         string(REGEX REPLACE " .*" "" line2 "${line2}")
227                         set(line2 " - \\ref ${line2}")
228                         file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc "${line2}\n")
229                 endif(line2)
230         endforeach(line ${file_content})
231         
232         foreach(line ${valeur_line})
233                 string(REGEX MATCH ".*toc.*" line1 "${line}")
234                 string(REGEX MATCH ".*<hr>.*" line2 "${line}")
235                 string(REGEX MATCH "^[ ]*$" line3 "${line}")
236                 string(REGEX MATCH "Table of Contents" line4 "${line}")
237                 if(NOT line1 AND NOT line2 AND NOT line3 AND NOT line4)
238                         file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc "   ${line}\n")
239                 endif(NOT line1 AND NOT line2 AND NOT line3 AND NOT line4)
240         endforeach(line ${valeur_line})
241 endforeach(file_name ${LISTE_GTUT})     
242
243 file(READ "${CMAKE_HOME_DIRECTORY}/doc/gtut-tour.doc" file_content)
244 string(REPLACE "\n" ";" file_content "${file_content}")
245 foreach(line ${file_content})
246         string(REGEX MATCH "^[ ]+.*\\ref" line1 "${line}")
247         if(line1)
248                 file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc "${line}\n")
249         endif(line1)
250 endforeach(line ${file_content})
251         
252 exec_program("${CMAKE_COMMAND} -E compare_files ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc" OUTPUT_VARIABLE compare_files)
253 if(compare_files)
254         message(STATUS "Wrong toc for gtut-tour.doc Right one is in tmp.realtoc")
255         exec_program("diff -u ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc")
256 else(compare_files)
257         file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc)
258 endif(compare_files)    
259   
260 file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc)
261
262 #Website
263
264 configure_file(${CMAKE_HOME_DIRECTORY}/website/Doxyfile_website.in ${CMAKE_HOME_DIRECTORY}/website/Doxyfile_website @ONLY)
265
266 ADD_CUSTOM_TARGET(simgrid_website
267         COMMENT "Generating the SimGrid Website..."     
268         DEPENDS ${WEBSITE_SOURCES} ${CMAKE_HOME_DIRECTORY}/website/all.bib
269         COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/toc_create.pl FAQ.doc contrib.doc history.doc
270     COMMAND ${CMAKE_COMMAND} -E echo "XX Doxygen website pass"
271         COMMAND ${DOXYGEN_PATH}/doxygen Doxyfile_website
272                 
273         COMMAND ${CMAKE_COMMAND} -E echo "XX Post-processing Doxygen website result"
274         #COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/doxygen_postprocesser_website.pl
275         WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/website/
276 )
277
278 ADD_CUSTOM_TARGET(bib_files
279         DEPENDS ${CMAKE_HOME_DIRECTORY}/website/all.bib
280         COMMAND ${CMAKE_COMMAND} -E echo "XX Generate publis_core.bib publis_extern.bib publis_intra.bib"
281         COMMAND ${BIBTOOL_PATH}/bibtool -- 'select.by.string={category \"core\"}' -- 'preserve.key.case={on}' -- 'preserve.keys={on}' all.bib -o publis_core.bib
282         COMMAND ${BIBTOOL_PATH}/bibtool -- 'select.by.string={category \"extern\"}' -- 'preserve.key.case={on}' -- 'preserve.keys={on}' all.bib -o publis_extern.bib
283         COMMAND ${BIBTOOL_PATH}/bibtool -- 'select.by.string={category \"intra\"}' -- 'preserve.key.case={on}' -- 'preserve.keys={on}' all.bib -o publis_intra.bib
284
285         COMMAND ${CMAKE_COMMAND} -E echo "XX Generate publis_count.html"
286         COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/bibtex2html_table_count.pl < ${CMAKE_HOME_DIRECTORY}/website/all.bib > ${CMAKE_HOME_DIRECTORY}/website/publis_count.html
287         
288         COMMAND ${CMAKE_COMMAND} -E echo "XX Generate publis_core.html publis_extern.html publis_intra.html"
289         COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/bibtex2html_wrapper.pl publis_core
290         COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/bibtex2html_wrapper.pl publis_extern
291         COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/bibtex2html_wrapper.pl publis_intra
292         
293         WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/website/
294 )
295
296 add_dependencies(simgrid_website bib_files)