diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2016-09-15 00:37:46 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2016-09-15 00:37:46 +0200 |
commit | 7f098579387bb16c775ab28490be2f347b05e51b (patch) | |
tree | 4064322990b90a42d155d0d9c14a4ea11af717ae /cmake/kicad_gerber.cmake | |
parent | e4444b71b96c896690817a02cf66199183b68a19 (diff) | |
download | kicad-utils-7f098579387bb16c775ab28490be2f347b05e51b.tar.gz kicad-utils-7f098579387bb16c775ab28490be2f347b05e51b.tar.bz2 kicad-utils-7f098579387bb16c775ab28490be2f347b05e51b.tar.xz kicad-utils-7f098579387bb16c775ab28490be2f347b05e51b.zip |
Adding CMake commands:
kicad_pcb_plot() that plots the PCB in PDF, PS and SVG formats.
kicad_gerber() that generates GERBER files from a PCB. Can optionally create a ZIP file with all the files. Supports old (protel) naming of files.
Diffstat (limited to 'cmake/kicad_gerber.cmake')
-rw-r--r-- | cmake/kicad_gerber.cmake | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/cmake/kicad_gerber.cmake b/cmake/kicad_gerber.cmake new file mode 100644 index 0000000..330c5bd --- /dev/null +++ b/cmake/kicad_gerber.cmake @@ -0,0 +1,88 @@ +function(kicad_gerber) + set(options ALL) + set(one_value_args TARGET PCB_FILE DIR ZIP_FILE NAMING_STYLE) + set(multi_value_args) + cmake_parse_arguments(ARGS "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN}) + + if (NOT ARGS_PCB_FILE) + message(SEND_ERROR "Missing required argument: PCB_FILE") + return() + endif () + + if (NOT ARGS_NAMING_STYLE) + set(ARGS_NAMING_STYLE MODERN) + endif () + + if (ARGS_NAMING_STYLE STREQUAL MODERN) + elseif (ARGS_NAMING_STYLE STREQUAL PROTEL) + set(protel --protel-extension) + else () + message(SEND_ERROR "Unsupported NAMING_STYLE: ${ARGS_NAMING_STYLE}") + return() + endif () + + set(pcb_file "${ARGS_PCB_FILE}") + get_filename_component(pcb_file "${ARGS_PCB_FILE}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + get_filename_component(basename "${pcb_file}" NAME_WE) + + if (NOT ARGS_TARGET) + set(target "${basename}-gerber") + else () + set(target "${ARGS_TARGET}") + endif () + + if (NOT ARGS_DIR) + message(SEND_ERROR "Missing required argument: DIR") + return() + endif () + + set(out_dir "${ARGS_DIR}") + set(prefix "${out_dir}/${basename}") + + execute_process( + COMMAND "${KicadUtilsPyDir}/kicad_gerber.py" --pcb "${pcb_file}" --output-directory "${out_dir}" ${protel} --detect-files-only + OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/${target}-gerber-index.txt + OUTPUT_VARIABLE out + ERROR_VARIABLE err + RESULT_VARIABLE res) + + file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/${target}-gerber-index.txt outputs) + + if (NOT res EQUAL 0) + message(SEND_ERROR "kicad_gerber.py failed: ${out} ${err}") + return() + endif () + +# foreach (o ${out}) +# list(APPEND outputs ${prefix}${o}) +# endforeach () + + # message("out=${out}") + message("outputs=${outputs}") + add_custom_command( + OUTPUT ${outputs} + COMMAND cmake -E make_directory "${out_dir}" + COMMAND "${KicadUtilsPyDir}/kicad_gerber.py" --pcb "${pcb_file}" --output-directory "${out_dir}" ${protel} + MAIN_DEPENDENCY "${pcb_file}") + + if (ARGS_ALL) + set(all ALL) + endif () + + if (ARGS_ZIP_FILE) + if (NOT IS_ABSOLUTE ARGS_ZIP_FILE) + set(ARGS_ZIP_FILE ${CMAKE_CURRENT_BINARY_DIR}/${ARGS_ZIP_FILE}) + endif () + + add_custom_command( + OUTPUT ${ARGS_ZIP_FILE} + MAIN_DEPENDENCY "${pcb_file}" + DEPENDS ${outputs} + COMMAND cmake -E remove -f ${ARGS_ZIP_FILE} + COMMAND zip -q ${ARGS_ZIP_FILE} -j ${outputs}) + endif () + + add_custom_target( + ${target} ${all} + DEPENDS ${outputs} ${ARGS_ZIP_FILE}) +endfunction() |