function(kicad_schematic_to_pdf source target) get_filename_component(name ${source} NAME) get_filename_component(dir ${source} DIRECTORY) file(RELATIVE_PATH rel "${CMAKE_SOURCE_DIR}" "${dir}") set(name_pdf "${name}.pdf") set(pdf ${CMAKE_BINARY_DIR}/${rel}/${name_pdf}) add_custom_command( OUTPUT ${pdf} COMMAND kicad-cli sch export pdf --output ${pdf} ${source} DEPENDS ${source} ) add_custom_target( "${target}" ALL DEPENDS ${pdf} ) endfunction()