1

在 PerfectTIN ( https://github.com/phma/perfecttin ) 中,我使用此 CMakeLists 文件构建文档:

find_program(PANDOC pandoc)

if (PANDOC)
execute_process(COMMAND ${PANDOC} "--resource-path=/" INPUT_FILE /dev/null ERROR_FILE /dev/null RESULT_VARIABLE pandoc_exit)
endif ()

if (PANDOC AND NOT pandoc_exit)
add_custom_command(OUTPUT perfecttin.pdf MAIN_DEPENDENCY perfecttin.xml COMMAND pandoc -f docbook -o perfecttin.pdf -V papersize=a4 -V margin-left=15mm -V margin-right=15mm -V margin-top=15mm -V margin-bottom=20mm --resource-path=${PROJECT_SOURCE_DIR}/doc ${PROJECT_SOURCE_DIR}/doc/perfecttin.xml)
add_custom_command(OUTPUT fileformat.pdf MAIN_DEPENDENCY fileformat.xml COMMAND pandoc -f docbook -o fileformat.pdf -V papersize=a4 -V margin-left=15mm -V margin-right=15mm -V margin-top=15mm -V margin-bottom=20mm --resource-path=${PROJECT_SOURCE_DIR}/doc ${PROJECT_SOURCE_DIR}/doc/fileformat.xml)
add_custom_target(perfecttin-doc ALL DEPENDS perfecttin.pdf fileformat.pdf)
install(FILES ${PROJECT_BINARY_DIR}/doc/fileformat.pdf ${PROJECT_BINARY_DIR}/doc/perfecttin.pdf DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/perfecttin)
endif ()

如果 Pandoc 不存在,它就不会构建文档。如果 Pandoc 和 TeXLive 都存在,它会构建文档。但是如果 Pandoc 存在但 TeXLive 不存在,则构建失败。在尝试构建文档之前,如何检查 Pandoc 是否具有所需的内容?

我试过了"--resource-path=/ -f docbook -o /dev/zero";它没有解决它。

4

1 回答 1

1

Pandoc 使用的程序是 pdflatex(在 Ubuntu 的 texlive-latex-base 包中)。所以我在 CMakeLists.txt 中添加了对 pdflatex 的搜索:

find_program(PANDOC pandoc)
find_program(PDFLATEX pdflatex)

if (PANDOC AND PDFLATEX)
execute_process(COMMAND ${PANDOC} "--resource-path=/" INPUT_FILE /dev/null ERROR_FILE /dev/null RESULT_VARIABLE pandoc_exit)
endif ()

if (PANDOC AND PDFLATEX AND NOT pandoc_exit)
add_custom_command(OUTPUT perfecttin.pdf MAIN_DEPENDENCY perfecttin.xml COMMAND pandoc -f docbook -o perfecttin.pdf -V papersize=a4 -V margin-left=15mm -V margin-right=15mm -V margin-top=15mm -V margin-bottom=20mm --resource-path=${PROJECT_SOURCE_DIR}/doc ${PROJECT_SOURCE_DIR}/doc/perfecttin.xml)
add_custom_command(OUTPUT fileformat.pdf MAIN_DEPENDENCY fileformat.xml COMMAND pandoc -f docbook -o fileformat.pdf -V papersize=a4 -V margin-left=15mm -V margin-right=15mm -V margin-top=15mm -V margin-bottom=20mm --resource-path=${PROJECT_SOURCE_DIR}/doc ${PROJECT_SOURCE_DIR}/doc/fileformat.xml)
add_custom_target(perfecttin-doc ALL DEPENDS perfecttin.pdf fileformat.pdf)
install(FILES ${PROJECT_BINARY_DIR}/doc/fileformat.pdf ${PROJECT_BINARY_DIR}/doc/perfecttin.pdf DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/perfecttin)
endif ()
于 2020-10-26T06:32:59.060 回答