aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2016-09-15 00:37:46 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2016-09-15 00:37:46 +0200
commit7f098579387bb16c775ab28490be2f347b05e51b (patch)
tree4064322990b90a42d155d0d9c14a4ea11af717ae /cmake
parente4444b71b96c896690817a02cf66199183b68a19 (diff)
downloadkicad-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')
-rw-r--r--cmake/KicadUtilsConfig.cmake2
-rw-r--r--cmake/kicad_gerber.cmake88
-rw-r--r--cmake/kicad_schematic_plot.cmake46
3 files changed, 136 insertions, 0 deletions
diff --git a/cmake/KicadUtilsConfig.cmake b/cmake/KicadUtilsConfig.cmake
index a2e6419..f8b91b7 100644
--- a/cmake/KicadUtilsConfig.cmake
+++ b/cmake/KicadUtilsConfig.cmake
@@ -1,5 +1,7 @@
set(kicad_generate_header_cmd KicadUtils::generate-header)
include("${CMAKE_CURRENT_LIST_DIR}/kicad_generate_header.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/kicad_pcb_plot.cmake")
+#include("${CMAKE_CURRENT_LIST_DIR}/kicad_schematic_plot.cmake")
+include("${CMAKE_CURRENT_LIST_DIR}/kicad_gerber.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/KicadUtilsTargets.cmake")
set(KicadUtilsPyDir "${CMAKE_CURRENT_LIST_DIR}/../../../share/kicad-utils/py")
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()
diff --git a/cmake/kicad_schematic_plot.cmake b/cmake/kicad_schematic_plot.cmake
new file mode 100644
index 0000000..d4b77f9
--- /dev/null
+++ b/cmake/kicad_schematic_plot.cmake
@@ -0,0 +1,46 @@
+function(kicad_schematic_plot)
+ set(options ALL)
+ set(one_value_args TARGET SCHEMATIC_FILE DIR)
+ set(multi_value_args)
+ cmake_parse_arguments(kicad_schematic_plot "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
+
+ if (NOT kicad_schematic_plot_SCHEMATIC_FILE)
+ message(SEND_ERROR "Missing required argument: SCHEMATIC_FILE")
+ return()
+ endif ()
+
+ set(schematic_file "${kicad_schematic_plot_SCHEMATIC_FILE}")
+ get_filename_component(schematic_file "${kicad_schematic_plot_SCHEMATIC_FILE}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+ get_filename_component(basename "${schematic_file}" NAME_WE)
+
+ if (NOT kicad_schematic_plot_TARGET)
+ set(target "${basename}-plots")
+ else ()
+ set(target "${kicad_schematic_plot_TARGET}")
+ endif ()
+
+ if (NOT kicad_schematic_plot_DIR)
+ message(SEND_ERROR "Missing required argument: DIR")
+ return()
+ endif ()
+
+ set(out_dir "${kicad_schematic_plot_DIR}")
+ set(pdf_prefix "${out_dir}/${basename}")
+
+ set(outputs
+ "${pdf_prefix}.pdf")
+
+ add_custom_command(
+ OUTPUT ${outputs}
+ COMMAND cmake -E make_directory "${out_dir}"
+ COMMAND "${KicadUtilsPyDir}/kicad_schematic_plot.py" "${schematic_file}" "${out_dir}"
+ MAIN_DEPENDENCY "${schematic_file}")
+
+ if (kicad_schematic_plot_ALL)
+ set(all ALL)
+ endif ()
+
+ add_custom_target(
+ ${target} ${all}
+ DEPENDS ${outputs})
+endfunction()