From e39d8d273701160773e44444993c20865e3731e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= Date: Fri, 4 May 2018 02:58:01 +0200 Subject: [PATCH 1/2] Split custom_target into custom_target and custom_command, avoid rebuilds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As stated in the add_custom_target documentation, the target "is always considered out of date". Instead, only add the output file as a target dependency and create the file using add_custom_command. With this change the documentation is only recreated when the input changes. Signed-off-by: Stefan Brüns --- CMakeModules/AsciidocHelpers.cmake | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/CMakeModules/AsciidocHelpers.cmake b/CMakeModules/AsciidocHelpers.cmake index c63836a4..dd61b70b 100644 --- a/CMakeModules/AsciidocHelpers.cmake +++ b/CMakeModules/AsciidocHelpers.cmake @@ -46,12 +46,18 @@ macro( add_adoc_pdf_target TARGET INFILE OUTFILE LANGUAGE ) #list( APPEND _A2X_OPTIONS -D "${_OUTPUT_DIR}" ) endif() - add_custom_target( ${TARGET} ALL ${A2X_COMMAND} ${_A2X_OPTIONS} ${INFILE} ) + add_custom_target( ${TARGET} DEPENDS ${OUTFILE} ) + add_custom_command( OUTPUT ${OUTFILE} + COMMAND ${A2X_COMMAND} ${_A2X_OPTIONS} ${INFILE} + DEPENDS ${INFILE} ) endmacro() # Add an asciidoc to HTML conversion target macro( add_adoc_html_target TARGET INFILE OUTFILE LANGUAGE ) - add_custom_target( ${TARGET} ALL ${ASCIIDOC_COMMAND} ${ASCIIDOC_OPTIONS} ${LANGUAGE_OPTIONS} -o ${OUTFILE} ${INFILE} ) + add_custom_target( ${TARGET} DEPENDS ${OUTFILE} ) + add_custom_command( OUTPUT ${OUTFILE} + COMMAND ${ASCIIDOC_COMMAND} ${ASCIIDOC_OPTIONS} ${LANGUAGE_OPTIONS} -o ${OUTFILE} ${INFILE} + DEPENDS ${INFILE} ) endmacro() # Add an asciidoc to EPUB conversion target @@ -62,7 +68,10 @@ macro( add_adoc_epub_target TARGET INFILE OUTFILE LANGUAGE ) ${DOCINFO_OUT} ) set( _A2X_OPTIONS ${A2X_OPTIONS} ) list( APPEND _A2X_OPTIONS -f epub -a docinfo -a lang=${LANGUAGE} ) - add_custom_target( ${TARGET} ALL ${A2X_COMMAND} ${_A2X_OPTIONS} ${INFILE} ) + add_custom_target( ${TARGET} DEPENDS ${OUTFILE} ) + add_custom_command( OUTPUT ${OUTFILE} + COMMAND ${A2X_COMMAND} ${_A2X_OPTIONS} ${INFILE} + DEPENDS ${INFILE} ) endmacro() # Pass an option to asciidoc From 1a7bc751ca50d3f94c00205100ecca7cf56764e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= Date: Fri, 4 May 2018 03:02:36 +0200 Subject: [PATCH 2/2] Remove intermediate targets and use file dependencies instead MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of creating custom target for each intermediate output, like translated asciidocs, just add/append the generated output files as a dependency. Signed-off-by: Stefan Brüns --- CMakeModules/KiCadDocumentation.cmake | 45 +++++++++++++++++---------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/CMakeModules/KiCadDocumentation.cmake b/CMakeModules/KiCadDocumentation.cmake index b5d26273..99872eef 100644 --- a/CMakeModules/KiCadDocumentation.cmake +++ b/CMakeModules/KiCadDocumentation.cmake @@ -71,22 +71,31 @@ macro( KiCadDocumentation DOCNAME ) set( LANGUAGE_OPTIONS "-a lang=${LANGUAGE}" ) # Fall back to the default config file for this language. endif() + # Add targets for parallel builds, otherwise generation is run in parallel from multiple toplevel targets + set (TRANSLATED_CHAPTERS "") + foreach( CHAPTER ${DOCCHAPTERS} ) + list (APPEND TRANSLATED_CHAPTERS ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/${DOCNAME}_${CHAPTER}.adoc ) + endforeach() + add_custom_target( ${DOCNAME}_translate_${LANGUAGE} + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/${DOCNAME}.adoc + DEPENDS ${TRANSLATED_CHAPTERS} ) + if( "${LANGUAGE}" MATCHES "en" ) # No need to translate, so just make a renamed copy of the source instead such # that we have the same source target as every other language # This is made a target so that changes are reflected on subsequent builds! - add_custom_target( ${DOCNAME}_translate_${LANGUAGE} + add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/${DOCNAME}.adoc COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}" COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/images ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/images - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${DOCNAME}.adoc ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/${DOCNAME}.adoc ) + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${DOCNAME}.adoc ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/${DOCNAME}.adoc + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${DOCNAME}.adoc ) # Deal with chapters for English only (simple copy) foreach( CHAPTER ${DOCCHAPTERS} ) - add_custom_target( ${DOCNAME}_translate_${CHAPTER}_${LANGUAGE} + add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/${DOCNAME}_${CHAPTER}.adoc COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${DOCNAME}_${CHAPTER}.adoc - ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/${DOCNAME}_${CHAPTER}.adoc ) - - add_dependencies( ${DOCNAME}_translate_${LANGUAGE} ${DOCNAME}_translate_${CHAPTER}_${LANGUAGE} ) + ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/${DOCNAME}_${CHAPTER}.adoc + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${DOCNAME}_${CHAPTER}.adoc ) endforeach() else() # Targets to update the translation files - include individual language targets @@ -103,10 +112,12 @@ macro( KiCadDocumentation DOCNAME ) add_dependencies( updatepo_${LANGUAGE} ${DOCNAME}_updatepo_${LANGUAGE} ) add_dependencies( updatepo_all ${DOCNAME}_updatepo_${LANGUAGE} ) - add_custom_target( ${DOCNAME}_translate_${LANGUAGE} + add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/${DOCNAME}.adoc COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}" COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/images ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/images - COMMAND ${PO4A_COMMAND}-translate -f asciidoc -a ${CMAKE_CURRENT_SOURCE_DIR}/po/addendum.${LANGUAGE} -A utf-8 -M utf-8 -m ${CMAKE_CURRENT_SOURCE_DIR}/${DOCNAME}.adoc -p ${CMAKE_CURRENT_SOURCE_DIR}/po/${LANGUAGE}.po -k -0 -l ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/${DOCNAME}.adoc ) + COMMAND ${PO4A_COMMAND}-translate -f asciidoc -a ${CMAKE_CURRENT_SOURCE_DIR}/po/addendum.${LANGUAGE} -A utf-8 -M utf-8 -m ${CMAKE_CURRENT_SOURCE_DIR}/${DOCNAME}.adoc -p ${CMAKE_CURRENT_SOURCE_DIR}/po/${LANGUAGE}.po -k -0 -l ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/${DOCNAME}.adoc + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${DOCNAME}.adoc + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/po/${LANGUAGE}.po ) # Non-ascii languages needs some special treatments if( "${LANGUAGE}" MATCHES "ja" ) @@ -117,10 +128,13 @@ macro( KiCadDocumentation DOCNAME ) # Deal with chapters for all languages... foreach( CHAPTER ${DOCCHAPTERS} ) - add_custom_target( ${DOCNAME}_translate_${CHAPTER}_${LANGUAGE} - COMMAND ${PO4A_COMMAND}-translate -f asciidoc -A utf-8 -M utf-8 -m ${CMAKE_CURRENT_SOURCE_DIR}/${DOCNAME}_${CHAPTER}.adoc -p ${CMAKE_CURRENT_SOURCE_DIR}/po/${LANGUAGE}.po -k -0 -l ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/${DOCNAME}_${CHAPTER}.adoc ) - - add_dependencies( ${DOCNAME}_translate_${LANGUAGE} ${DOCNAME}_translate_${CHAPTER}_${LANGUAGE} ) + add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/${DOCNAME}_${CHAPTER}.adoc + COMMAND ${PO4A_COMMAND}-translate -f asciidoc -A utf-8 -M utf-8 + -m ${CMAKE_CURRENT_SOURCE_DIR}/${DOCNAME}_${CHAPTER}.adoc + -p ${CMAKE_CURRENT_SOURCE_DIR}/po/${LANGUAGE}.po -k -0 + -l ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/${DOCNAME}_${CHAPTER}.adoc + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/po/${LANGUAGE}.po + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${DOCNAME}_${CHAPTER}.adoc ) endforeach() endif() @@ -190,10 +204,6 @@ macro( KiCadDocumentation DOCNAME ) add_dependencies( ${DOCNAME}_pdf_${LANGUAGE} ${DOCNAME}_translate_${LANGUAGE} ) add_dependencies( ${DOCNAME} ${DOCNAME}_pdf_${LANGUAGE} ) - if( NOT "${HTML_BUILD}" EQUAL "-1" ) - add_dependencies( ${DOCNAME}_pdf_${LANGUAGE} ${DOCNAME}_html_${LANGUAGE} ) - endif() - install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGE}/${DOCNAME}.pdf DESTINATION ${KICAD_DOC_PATH}/${LANGUAGE} COMPONENT pdf-${LANGUAGE}) endif() @@ -210,7 +220,8 @@ macro( KiCadDocumentation DOCNAME ) add_dependencies( ${DOCNAME} ${DOCNAME}_epub_${LANGUAGE} ) # Make the epub target depend on the PDF build as the targets have a race - # condition, probably with intermediary files + # condition, a2x creates the intermediate docbook output directly in the output + # directory. if( NOT "${PDF_BUILD}" EQUAL "-1" ) add_dependencies( ${DOCNAME}_epub_${LANGUAGE} ${DOCNAME}_pdf_${LANGUAGE} ) endif()