Jump to content

Minimal Cmake Pdf | Better

cmake_minimum_required(VERSION 3.15) project(Manual) find_program(PANDOC pandoc REQUIRED) find_package(LATEX REQUIRED) # for pdflatex engine

find_package(LATEX QUIET) if(NOT LATEX_FOUND) message(STATUS "PDF generation disabled (pdflatex not found)") else() # ... add_custom_command and add_custom_target as above endif() This preserves the minimal philosophy: no hard failures, just feature detection. | Aspect | Minimal CMake Approach | |--------|------------------------| | Tooling | 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 | minimal cmake pdf

add_custom_target(pdf DEPENDS $PDF_OUTPUT) Sometimes you want the PDF content to reflect CMake variables (e.g., version number). With minimal CMake, you can generate a .tex or .md file first: cmake_minimum_required(VERSION 3

The pattern is ideal for documentation that lives alongside code, where you want a simple, cross‑platform way to say “build the PDF if you have the tools” – no extra scripting, no fragile pipelines, just CMake doing what it does best: finding executables and running them. With minimal CMake, you can generate a

add_custom_command( OUTPUT $PDF_OUTPUT COMMAND $PANDOC $MD_SOURCE -o $PDF_OUTPUT --pdf-engine=$PDFLATEX_COMPILER DEPENDS $MD_SOURCE COMMENT "Converting Markdown to PDF" )

×
×
  • Create New...