diff options
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/KicadUtilsConfig.cmake | 2 | ||||
-rw-r--r-- | cmake/kicad_generate_header.cmake | 57 |
2 files changed, 59 insertions, 0 deletions
diff --git a/cmake/KicadUtilsConfig.cmake b/cmake/KicadUtilsConfig.cmake new file mode 100644 index 0000000..2302fe2 --- /dev/null +++ b/cmake/KicadUtilsConfig.cmake @@ -0,0 +1,2 @@ +include("${CMAKE_CURRENT_LIST_DIR}/kicad_generate_header.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/KicadUtilsTargets.cmake") diff --git a/cmake/kicad_generate_header.cmake b/cmake/kicad_generate_header.cmake new file mode 100644 index 0000000..930c5ed --- /dev/null +++ b/cmake/kicad_generate_header.cmake @@ -0,0 +1,57 @@ +function(kicad_generate_header) + set(options IN_SOURCE) + set(oneValueArgs OUTPUT NET REF OUTPUT_DIR TEMPLATE TEMPLATE_LIB_LIST) + + cmake_parse_arguments(kicad_gen "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if (NOT kicad_gen_OUTPUT) + message(FATAL_ERROR "OUTPUT is required") + endif () + set(output "${kicad_gen_OUTPUT}") + + if (NOT kicad_gen_NET) + message(FATAL_ERROR "NET is required") + endif () + set(NET "${CMAKE_CURRENT_SOURCE_DIR}/${kicad_gen_NET}") + + if (NOT kicad_gen_REF) + message(FATAL_ERROR "REF is required") + endif () + set(REF "${kicad_gen_REF}") + + if (kicad_gen_OUTPUT_DIR) + if (kicad_gen_IN_SOURCE) + message(FATAL_ERROR "IN_SOURCE can't be used if OUTPUT_DIR is used") + endif () + + set(output_dir "${kicad_gen_OUTPUT_DIR}") + set(output_rel_dir "${output_dir}") + else () + if (kicad_gen_IN_SOURCE) + set(output_dir "${CMAKE_CURRENT_SOURCE_DIR}") + set(output_rel_dir "${CMAKE_SOURCE_DIR}") + else () + set(output_dir "${CMAKE_CURRENT_BINARY_DIR}") + set(output_rel_dir "${CMAKE_BINARY_DIR}") + endif () + endif () + + if (kicad_gen_TEMPLATE) + set(t "-t") + set(template "${kicad_gen_TEMPLATE}") + endif () + + set(lib "-l;${CMAKE_CURRENT_SOURCE_DIR}") + foreach(l IN LISTS kicad_gen_TEMPLATE_LIB_LIST) + list(APPEND lib -l) + list(APPEND lib "${l}") + endforeach () + + set(output_file "${output_dir}/${output}") + file(RELATIVE_PATH output_file_rel "${output_rel_dir}" ${output_file}) + + add_custom_command(OUTPUT "${output_file}" + COMMAND KicadUtils::generate-header -n ${NET} -r ${REF} -o ${output_file} ${t} ${template} ${lib} + MAIN_DEPENDENCY ${NET} + COMMENT "Generating ${output_file_rel}") +endfunction() |