Logo AND Algorithmique Numérique Distribuée

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