cmake_minimum_required(VERSION 3.10) project(MinimalLatexPDF) # Define the source and output set(LATEX_SOURCE "$CMAKE_CURRENT_SOURCE_DIR/document.tex") set(PDF_OUTPUT "$CMAKE_CURRENT_BINARY_DIR/document.pdf") # Instruction to run pdflatex add_custom_command( OUTPUT $PDF_OUTPUT COMMAND pdflatex -interaction=nonstopmode $LATEX_SOURCE DEPENDS $LATEX_SOURCE WORKING_DIRECTORY $CMAKE_CURRENT_BINARY_DIR ) # Create a build target add_custom_target(generate_pdf ALL DEPENDS $PDF_OUTPUT) Use code with caution. Copied to clipboard Why Use CMake for PDFs?
: Using DEPENDS , CMake only re-compiles the PDF if the .tex file has changed, saving time on large projects. minimal cmake pdf
| Aspect | Minimal CMake Approach | |--------|------------------------| | | find_package(LATEX) or find_program(PANDOC) | | Build step | One add_custom_command | | User interface | One add_custom_target(pdf) | | External dependencies | None (CMake only) | | Complexity | ~10 lines of CMake | cmake_minimum_required(VERSION 3