From 15210207eaac51fc8bda79ed33954b0dfbdc3ecf Mon Sep 17 00:00:00 2001 From: Adam Sapek Date: Tue, 24 Mar 2015 22:28:16 -0700 Subject: [PATCH] Add CMake project to build documentation The documentation is compiled from the markdown sources to html using `pandoc`. In order to install `pandoc` run: cabal install pandoc The documentation build is optional and if `pandoc` is not found during cmake project configuration the documentation build is skipped. --- CMakeLists.txt | 1 + doc/.pandoc/templates/default.html | 4 +- doc/CMakeLists.txt | 84 ++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 doc/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 997969cf..7470709c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} -C ${CMAKE_CFG_INTDIR} -- add_subdirectory (compiler) add_subdirectory (cpp) +add_subdirectory (doc) add_python_subdirectory (python) add_subdirectory (examples) diff --git a/doc/.pandoc/templates/default.html b/doc/.pandoc/templates/default.html index 4a05051c..01c6e379 100644 --- a/doc/.pandoc/templates/default.html +++ b/doc/.pandoc/templates/default.html @@ -11,9 +11,10 @@ $if(date-meta)$ $endif$ $if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$ -$if(highlighting-css)$ -$endif$ $for(css)$ $endfor$ diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt new file mode 100644 index 00000000..5c0bcac7 --- /dev/null +++ b/doc/CMakeLists.txt @@ -0,0 +1,84 @@ +include (CMakeParseArguments) +include (HaskellUtil) + +# +# add_pandoc_markdown (file.md [file2.md ...] +# [CODE code] +# [OUTPUT_DIR dir] +# [OUTPUT_NAME name] +# [TEMPLATE template] +# [OPTIONS opt [opt2 ...]]) +# +function (add_pandoc_markdown) + set (flagArgs) + set (oneValueArgs OUTPUT_NAME OUTPUT_DIR CODE TEMPLATE) + set (multiValueArgs OPTIONS) + cmake_parse_arguments (arg "${flagArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + set (options + --standalone + --smart + --data-dir=.pandoc + --highlight-style tango + ${arg_OPTIONS}) + if (arg_TEMPLATE) + list(APPEND options --template="${arg_TEMPLATE}") + else() + endif() + if (arg_CODE) + list(APPEND options --indented-code-classes="${arg_CODE}") + else() + endif() + set (inputs "${arg_UNPARSED_ARGUMENTS}") + foreach (file ${inputs}) + get_filename_component (name ${file} NAME_WE) + if (arg_OUTPUT_NAME) + set (outputName ${arg_OUTPUT_NAME}) + else() + set (outputName ${name}) + endif() + set (output "${CMAKE_CURRENT_BINARY_DIR}/html/${arg_OUTPUT_DIR}/${outputName}.html") + list (APPEND sources ${file}) + list (APPEND outputs ${output}) + add_custom_command( + OUTPUT ${output} + COMMAND ${Haskell_PANDOC_EXECUTABLE} ${options} --output="${output}" "${file}" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${file} ${PANDOC_EXECUTABLE}) + endforeach() + add_custom_target ("documentation_${name}" + DEPENDS ${outputs} + SOURCES ${sources}) + add_dependencies (documentation "documentation_${name}") +endfunction() + +find_haskell_program (pandoc) + +if (Haskell_PANDOC_EXECUTABLE) + add_custom_target (documentation) + + add_pandoc_markdown (src/bond_py.md src/bond_cpp.md + CODE "cpp,numberLines" + OPTIONS --self-contained --table-of-contents + OUTPUT_DIR manual) + + add_pandoc_markdown (src/bond_cs.md + CODE "cs,numberLines" + OPTIONS --self-contained --table-of-contents + OUTPUT_DIR manual) + + add_pandoc_markdown (src/reference_index.md + CODE "cpp" + OPTIONS --self-contained + OUTPUT_NAME index + OUTPUT_DIR reference) + + add_pandoc_markdown (../readme.md + TEMPLATE index.html + OUTPUT_NAME index + CODE python) + + add_pandoc_markdown (src/why_bond.md + TEMPLATE index.html + CODE python) +endif() +