[CMake] QtAssistant Docs (Experimental)

Mike Jackson imikejackson at gmail.com
Wed Nov 28 14:02:09 EST 2007


The following shell script is a hack that I created to generate a  
rough set of Docs that can be viewed/searched using QtAssistant from  
Qt4. There are probably some bugs in the script but it seems to  
generate ok on my system. Also, checking the HTML against BBEdit's  
HTML validator, there seem to be some HTML generation issues from  
cmake itself (<p> is never closed, <a name="...." /> seems to be  
bad).  The current (as of 11/28/2007 CMake cvs will NOT generate the  
module html files. I get a seg fault) so I switch to the cmake 2.4.7  
part way through to at least get the text versions of those help files.

Comments are welcome. I would like to see this wrapped up as its own  
CMake Docs Application or as a "Help.." menu in the QtCmakeSetup app  
that is in CVS.

Comments are welcome...

---------------- Begin Shell Script------------------------------------

#!/bin/bash
# This is a shell script to generate a QtAssistant set of docs from  
the CMake distribution.
#
# Couple of things to get you started with this file:function file
# 1. Set the CMAKE variable to the cmake executable for the CMAKE cvs  
if it is not
# the default on your system
# 2. I change the definition of CMAKE to 'cmake' when I generate the  
"module" list because
# the current CMake cvs seg faults when I use the cmake --help-module- 
list command
# 3. All the files are generated in the /tmp directory. If you want  
them somewhere else
# set the 'generationDir' variable
# 4. Launch QtAssistant with the -profile argument, for example on OS  
X I use
# ./assistant.app/Contents/MacOS/assistant -profile /private/tmp/ 
cmake_assistant_docs/CMakeDocs.adp
# where my pwd is: ${QTDIR}/bin or
# /Users/Shared/Toolkits/Qt-4.3.2-UBLib/bin
# Change the 'qtassistant' variable to point to your QtAssistant  
executable


qtassistant="${QTDIR}/bin/assistant.app/Contents/MacOS/assistant"
CMAKE="/Users/Shared/OpenSource/CMake/build/bin/cmake"

generationDir="/tmp"
assistantDir="${generationDir}/cmake_assistant_docs"
commandDocDirName="cmake_command_docs"
moduleDocDirName="cmake_module_docs"
commandDocDir="${assistantDir}/${commandDocDirName}"
moduleDocDir="${assistantDir}/${moduleDocDirName}"
tmpHTMLFile="${commandDocDir}${generationDir}.html"

mkdir ${assistantDir}
mkdir ${commandDocDir}
mkdir ${moduleDocDir}

commandListFile="${generationDir}/cmake_command_list.txt"
${CMAKE} --help-command-list ${commandListFile}

#----------------------------------------------------------------
# Generate all the individual cmake command html files
#----------------------------------------------------------------
i=0
exec 9<${commandListFile}
while read -u 9 line
   do
   if [[ ${i} -gt 0 ]]; then
     echo ${i}": ${line}"
     # Seems that CMake only puts out the body portion of the html

     ${CMAKE} --help-command ${line} ${tmpHTMLFile}
     commandFile=${commandDocDir}/${line}.html
     # Clear the file in case it is left over from previous run
     echo "" > ${commandFile}
     echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01  
Transitional//EN\"" >> ${commandFile}
     echo "\"http://www.w3.org/TR/html4/loose.dtd\">" >> ${commandFile}
     echo "<html><head>" >> ${commandFile}
     echo "<META http-equiv=\"Content-Type\" content=\"text/html;  
charset=UTF-8\"> " >> ${commandFile}
     echo "<title>CMake Command ${line}</title>" >> ${commandFile}
     echo "</head>" >> ${commandFile}
     echo "<body>" >> ${commandFile}
     cat ${tmpHTMLFile} >> ${commandFile}
     echo "</body></html>" >> ${commandFile}
   fi
   let i=i+1
done
exec 9<&-

#----------------------------------------------------------------
# Generate the CMake command Index File
#----------------------------------------------------------------
commandIndexFile="command_index.html"
indexFile=${commandDocDir}/${commandIndexFile}
echo "" > ${indexFile}
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN 
\"" >> ${indexFile}
echo "\"http://www.w3.org/TR/html4/loose.dtd\">" >> ${indexFile}
echo "<html><head>" >> ${indexFile}
echo "<META http-equiv=\"Content-Type\" content=\"text/html;  
charset=UTF-8\"> " >> ${indexFile}
echo "<title>CMake Command Index</title>" >> ${indexFile}
echo "</head>" >> ${indexFile}
echo "<body>" >> ${indexFile}

i=0
exec 9<${commandListFile}
while read -u 9 line
   do
   if [[ ${i} -gt 0 ]]; then
     echo "<p><a href=\"${line}.html\">${line}</a></p>" >> ${indexFile}
   fi
   let i=i+1
done
exec 9<&-
echo "</body></html>" >> ${indexFile}


# Create the Module list file
# Change to current CMake as there is a bug in the cvs cmake
CMAKE=cmake
moduleListFile="${generationDir}/cmake_module_list.txt"
cmake --help-module-list ${moduleListFile}
#----------------------------------------------------------------
# Generate all the individual cmake module html files
#----------------------------------------------------------------
i=0
exec 9<${moduleListFile}
while read -u 9 line
   do
   if [[ ${i} -gt 0 ]]; then
     echo ${i}": ${line}"
     # Seems that CMake only puts out the body portion of the html

     ${CMAKE} --help-module ${line} ${tmpHTMLFile}
     commandFile=${moduleDocDir}/${line}.html
     # Clear the file in case it is left over from previous run
     echo "" > ${commandFile}
     echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01  
Transitional//EN\"" >> ${commandFile}
     echo "\"http://www.w3.org/TR/html4/loose.dtd\">" >> ${commandFile}
     echo "<html><head>" >> ${commandFile}
     echo "<META http-equiv=\"Content-Type\" content=\"text/html;  
charset=UTF-8\"> " >> ${commandFile}
     echo "<title>CMake Command ${line}</title>" >> ${commandFile}
     echo "</head>" >> ${commandFile}
     echo "<body>" >> ${commandFile}
     cat ${tmpHTMLFile} >> ${commandFile}
     echo "</body></html>" >> ${commandFile}
   fi
   let i=i+1
done
exec 9<&-

#----------------------------------------------------------------
# Generate the CMake module Index File
#----------------------------------------------------------------
moduleIndexFile="cmake_module_index.html"
indexFile=${moduleDocDir}/${moduleIndexFile}
echo "" > ${indexFile}
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN 
\"" >> ${indexFile}
echo "\"http://www.w3.org/TR/html4/loose.dtd\">" >> ${indexFile}
echo "<html><head>" >> ${indexFile}
echo "<META http-equiv=\"Content-Type\" content=\"text/html;  
charset=UTF-8\"> " >> ${indexFile}
echo "<title>CMake Module Index</title>" >> ${indexFile}
echo "</head>" >> ${indexFile}
echo "<body>" >> ${indexFile}

i=0
exec 9<${moduleListFile}
while read -u 9 line
   do
   if [[ ${i} -gt 0 ]]; then
     echo "<p><a href=\"${line}.html\">${line}</a></p>" >> ${indexFile}
   fi
   let i=i+1
done
exec 9<&-
echo "</body></html>" >> ${indexFile}


#----------------------------------------------------------------
# Generate the main index.html file
#----------------------------------------------------------------
mainIndexFileName="index.html"
indexFile=${assistantDir}/${mainIndexFileName}
mainIndexFile=${indexFile}
echo "" > ${indexFile}
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN 
\"" >> ${indexFile}
echo "\"http://www.w3.org/TR/html4/loose.dtd\">" >> ${indexFile}
echo "<html><head>" >> ${indexFile}
echo "<META http-equiv=\"Content-Type\" content=\"text/html;  
charset=UTF-8\"> " >> ${indexFile}
echo "<title>CMake Documentation</title>" >> ${indexFile}
echo "</head>" >> ${indexFile}
echo "<body>" >> ${indexFile}
echo "<p><a href=\"./${commandDocDirName}/${commandIndexFile}\">CMake  
Commands</a></p>" >> ${indexFile}
echo "<p><a href=\"./${moduleDocDirName}/${moduleIndexFile}\">CMake  
Modules</a></p>" >> ${indexFile}
echo "</body></html>" >> ${indexFile}

#----------------------------------------------------------------
# Generate the Qt DCF file
#----------------------------------------------------------------
adpFile=${assistantDir}/CMakeDocs.adp
echo "" > ${adpFile}
echo "<assistantconfig version=\"3.2.0\">" > ${adpFile}
echo "<profile>" >> ${adpFile}
echo "     <property name=\"name\">cmake documentation</property>" >>  
${adpFile}
echo "     <property name=\"title\">CMake Docs</property>" >> ${adpFile}
#echo "     <property name=\"applicationicon\"></property>" >> $ 
{adpFile}
echo "     <property name=\"startpage\">index.html</property>" >> $ 
{adpFile}
echo "     <property name=\"aboutmenutext\">About CMake Docs Viewer</ 
property>" >> ${adpFile}
#echo "     <property name=\"abouturl\">about.txt</property>" >> $ 
{adpFile}
#echo "     <property name=\"cmake_docs\">.</property>" >> ${adpFile}
echo " </profile>" >> ${adpFile}
echo "" >> ${adpFile}
echo "    <DCF ref=\"${mainIndexFileName}\" icon=\"\" imagedir=\"\"  
title=\"CMake Docs Handbook\">" >> ${adpFile}


#----------------------------------------------------------------
# Create the CMake Commands Section
#----------------------------------------------------------------
echo "      <section ref=\"${commandDocDirName}/${commandIndexFile}\"  
title=\"CMake Commands\">" >> ${adpFile}
i=0
exec 9<${commandListFile}
while read -u 9 line
   do
   if [[ ${i} -gt 0 ]]; then
     commandFile=${commandDocDirName}/${line}.html
     echo "        <keyword ref=\"${commandFile}\">${line}</keyword>"  
 >> ${adpFile}
     echo "        <section ref=\"${commandFile}\" title=\"${line}\"/ 
 >" >> ${adpFile}
   fi
   let i=i+1
done
exec 9<&-
echo "   </section>" >> ${adpFile}


#----------------------------------------------------------------
# Create the CMake Module Section
#----------------------------------------------------------------
echo "      <section ref=\"${moduleDocDirName}/${moduleIndexFile}\"  
title=\"CMake Modules\">" >> ${adpFile}
i=0
exec 9<${moduleListFile}
while read -u 9 line
   do
   if [[ ${i} -gt 0 ]]; then
     commandFile=${moduleDocDirName}/${line}.html
     echo "        <keyword ref=\"${commandFile}\">${line}</keyword>"  
 >> ${adpFile}
     echo "        <section ref=\"${commandFile}\" title=\"${line}\"/ 
 >" >> ${adpFile}
   fi
   let i=i+1
done
exec 9<&-
echo "   </section>" >> ${adpFile}


#----------------------------------------------------------------
# Finish the .adp File
#----------------------------------------------------------------
echo "    </DCF>" >> ${adpFile}
echo "</assistantconfig>" >> ${adpFile}

${qtassistant} -profile ${adpFile} &

---------------- End Shell Script------------------------------------



--
Mike Jackson
imikejackson & gmail * com





More information about the CMake mailing list