ビルド プロセスの一環として、PlantUMLダイアグラムを PNGにレンダリングする単純な CMake 関数を提供しようとしています。.uml
アイデアは、ビルド プロセスの一部として PNG にレンダリングしたい PlantUML ダイアグラムを含むファイルがたくさんあるということです。add_library()
etに似た機能が欲しいです。アル。これは、イメージ ファイルがソース ファイルよりも古いダイアグラムをレンダリングします。
を使用add_custom_command()
して、次のスニペットを思いつきました。
#
# Create top-level target that renders a PlantUML diagram to a PNG image.
#
function(add_diagram target source)
# Program used to render the diagram.
set(plantuml java -jar ${PLANTUML_JARFILE})
# Diagram source file basename used to create output file name.
get_filename_component(output ${source} NAME_WE)
# Render the diagram and write an "${output}.png"
# file in the current binary folder.
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/${output}.png
COMMAND
${plantuml} -o ${CMAKE_CURRENT_BINARY_DIR} -tpng ${source}
MAIN_DEPENDENCY
${source}
COMMENT
"Rendering diagram '${output}'."
)
# Top-level target to build the output file.
add_custom_target(${target}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${output}.png)
endfunction()
そして、この関数を次のように呼び出します。
add_diagram(foo ${CMAKE_CURRENT_SOURCE_DIR}/foo.uml)
ここfoo.uml
で、PlantUML ダイアグラムを含むファイルです。非常に基本的なレベルでは、これは手動で構築できる名前付きのトップレベル ターゲットを作成するという点で "機能" します (たとえばmake foo
、nmake foo
、jom foo
、 などを使用)。
このターゲットをデフォルトのターゲット (すべて?) に追加して、残りのライブラリと実行可能ファイルで自動的にビルドされるようにするにはどうすればよいですか?