Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Cleanup cmake rules #566

Merged
merged 2 commits into from
May 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions CMakeModules/AsciidocHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
45 changes: 28 additions & 17 deletions CMakeModules/KiCadDocumentation.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" )
Expand All @@ -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()

Expand Down Expand Up @@ -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()

Expand All @@ -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()
Expand Down