在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"
;它没有修复它。
Pandoc使用的程序是pdflatex(它在Ubuntu中的texlive latex基本包中(。所以我在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 ()