|
6 | 6 | #---------------------------------------------------------------------------#
|
7 | 7 |
|
8 | 8 | configure_file("version.json.in" "version.json" @ONLY)
|
9 |
| -add_custom_target(doc ALL) |
10 |
| -add_custom_command(TARGET doc |
11 |
| - COMMAND "${CMAKE_COMMAND}" -E env |
12 |
| - "CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}" |
13 |
| - "${SPHINX_EXECUTABLE}" -q |
14 |
| - -d "${CMAKE_CURRENT_BINARY_DIR}/doctrees" |
15 |
| - -b html |
16 |
| - "${CMAKE_CURRENT_SOURCE_DIR}" |
17 |
| - "${CMAKE_CURRENT_BINARY_DIR}/html" |
18 |
| - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" |
19 |
| - COMMENT "Building HTML documentation with Sphinx" |
20 |
| - BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/html/index.html" |
| 9 | + |
| 10 | +function(flibcpp_build_sphinx type output) |
| 11 | + add_custom_command(OUTPUT "${output}" |
| 12 | + VERBATIM COMMAND |
| 13 | + "${CMAKE_COMMAND}" -E env |
| 14 | + "PYTHONPATH=${FLIBCPP_PYTHONPATH}" |
| 15 | + "CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}" |
| 16 | + "${SPHINX_EXECUTABLE}" -q |
| 17 | + -d "${CMAKE_CURRENT_BINARY_DIR}/doctrees" |
| 18 | + -b ${type} |
| 19 | + "${CMAKE_CURRENT_SOURCE_DIR}" |
| 20 | + "${CMAKE_CURRENT_BINARY_DIR}/${type}" |
| 21 | + COMMENT "Building ${type} documentation with Sphinx" |
| 22 | + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/conf.py" |
| 23 | + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" |
| 24 | + ${ARGN} |
| 25 | + ) |
| 26 | +endfunction() |
| 27 | + |
| 28 | +set(_doc_html "${CMAKE_CURRENT_BINARY_DIR}/html/index.html") |
| 29 | +flibcpp_build_sphinx(html "${_doc_html}") |
| 30 | +add_custom_target(doc ALL DEPENDS "${_doc_html}") |
| 31 | + |
| 32 | +install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html/" |
| 33 | + DESTINATION "${CMAKE_INSTALL_DOCDIR}" |
21 | 34 | )
|
22 | 35 |
|
23 |
| -# Note: latex generation creates a makefile that muts be run |
24 |
| -add_custom_target(doc_latex) |
25 |
| -add_custom_command(TARGET doc_latex |
26 |
| - COMMAND "${CMAKE_COMMAND}" -E env |
27 |
| - "CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}" |
28 |
| - "${SPHINX_EXECUTABLE}" -q |
29 |
| - -d "${CMAKE_CURRENT_BINARY_DIR}/doctrees" |
30 |
| - -b latex |
31 |
| - "${CMAKE_CURRENT_SOURCE_DIR}" |
32 |
| - "${CMAKE_CURRENT_BINARY_DIR}/latex" |
33 |
| - COMMENT "Building LaTeX documentation with Sphinx" |
34 |
| - BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/latex/Flibcpp.tex" |
| 36 | +# Note: latex generation creates a makefile that must be run |
| 37 | +set(_doc_tex "${CMAKE_CURRENT_BINARY_DIR}/latex/Flibcpp.tex") |
| 38 | +flibcpp_build_sphinx(latex "${_doc_tex}") |
| 39 | + |
| 40 | +find_program(LATEXMK_EXECUTABLE latexmk) |
| 41 | +if(NOT LATEXMK_EXECUTABLE) |
| 42 | + # Local variable to give helpful error at runtime? |
| 43 | + set(LATEXMK_EXECUTABLE latexmk) |
| 44 | +endif() |
| 45 | + |
| 46 | +# Download ornltm class |
| 47 | +set(_ornltm_base "${CMAKE_CURRENT_BINARY_DIR}/latex/ornltm") |
| 48 | +ExternalProject_Add(ornltm |
| 49 | + GIT_REPOSITORY https://code.ornl.gov/s3j/ornltm.git |
| 50 | + GIT_TAG 2ad59291117b487666d15d10a105de0d680e72a6 |
| 51 | + CONFIGURE_COMMAND "" |
| 52 | + BUILD_COMMAND "" |
| 53 | + INSTALL_COMMAND "" |
| 54 | + SOURCE_DIR "${_ornltm_base}" |
35 | 55 | )
|
36 |
| -add_custom_target(doc_pdf) |
37 |
| -add_custom_command(TARGET doc_pdf |
38 |
| - COMMAND "${CMAKE_COMMAND}" -E env |
39 |
| - "LATEXOPTS=" |
40 |
| - latexmk -pdf flibcpp-tm-header Flibcpp |
41 |
| - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/latex" |
42 |
| - COMMENT "Building PDF documentation from LaTeX" |
43 |
| - BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/latex/Flibcpp.pdf" |
| 56 | + |
| 57 | +set(_texenv "LATEXOPTS=" "TEXINPUTS=${_ornltm_base}/ornltm:") |
| 58 | +function(flibcpp_build_latex input output) |
| 59 | + add_custom_command(OUTPUT "${output}" |
| 60 | + VERBATIM COMMAND |
| 61 | + "${CMAKE_COMMAND}" -E env ${_texenv} |
| 62 | + "${LATEXMK_EXECUTABLE}" -pdf "${input}" |
| 63 | + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/latex" |
| 64 | + ${ARGN} |
| 65 | + ) |
| 66 | +endfunction() |
| 67 | + |
| 68 | +# Generate header |
| 69 | +set(_header_pdf "${CMAKE_CURRENT_BINARY_DIR}/latex/flibcpp-tm-header.pdf") |
| 70 | +flibcpp_build_latex( |
| 71 | + "${CMAKE_CURRENT_SOURCE_DIR}/_static/flibcpp-tm-header.tex" |
| 72 | + "${_header_pdf}" |
| 73 | + COMMENT "Building tech memo header" |
| 74 | + DEPENDS ornltm |
44 | 75 | )
|
45 |
| -add_dependencies(doc_pdf doc_latex) |
46 | 76 |
|
47 |
| -install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html/" |
48 |
| - DESTINATION "${CMAKE_INSTALL_DOCDIR}" |
| 77 | +# Generate header |
| 78 | +set(_footer_pdf "${CMAKE_CURRENT_BINARY_DIR}/latex/flibcpp-tm-footer.pdf") |
| 79 | +flibcpp_build_latex( |
| 80 | + "${CMAKE_CURRENT_SOURCE_DIR}/_static/flibcpp-tm-footer.tex" |
| 81 | + "${_footer_pdf}" |
| 82 | + COMMENT "Building tech memo footer" |
| 83 | + DEPENDS ornltm |
| 84 | +) |
| 85 | + |
| 86 | +# Generate PDF |
| 87 | +set(_doc_pdf "${CMAKE_CURRENT_BINARY_DIR}/latex/Flibcpp.pdf") |
| 88 | +flibcpp_build_latex( |
| 89 | + Flibcpp |
| 90 | + "${_doc_pdf}" |
| 91 | + COMMENT "Building PDF documentation from LaTeX" |
| 92 | + DEPENDS "${_doc_tex}" "${_header_pdf}" "${_footer_pdf}" ornltm |
49 | 93 | )
|
50 | 94 |
|
| 95 | +add_custom_target(doc_pdf DEPENDS "${_doc_pdf}") |
0 commit comments