我試圖提供一個簡單的CMake函數來將PlantUML圖表呈現爲PNG,作爲我的構建過程的一部分。這個想法是,我有一堆.uml
文件,其中包含我想要作爲構建過程的一部分呈現給PNG的PlantUML圖。我想要有一個功能類似於add_library()
et。人。,它呈現圖像文件比源文件更舊的任何圖。用於新命令行工具的CMake包裝
使用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
等)。
如何將此目標添加到默認目標(全部?),以便它可以與其餘的庫和可執行文件自動構建?
很好找!我會試試看,讓你知道它是怎麼回事。 – 2012-01-01 02:19:52
謝謝,我所要做的就是在'add_custom_target()'調用中添加'ALL',一切都像魅力一樣! – 2012-01-01 03:57:44
如果您正在運行構建的操作系統沒有安裝plantuml,您在做什麼? – AlexTheo 2015-04-08 19:28:52