Skip to content

Commit ade28a7

Browse files
authored
[clang-doc][cmake] Copy assets to build directory (llvm#95187)
While we copy the asset files, like index.js, into the correct location in the install step, tests do not have access to those resources in the build directory. This patch copies the contents of the clang-doc/assets directory into the build folder, so that they can be used in testing. Pull Request: llvm#95185
1 parent a66e2a1 commit ade28a7

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

clang-tools-extra/clang-doc/tool/CMakeLists.txt

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,38 @@ target_link_libraries(clang-doc
1818
clangDoc
1919
)
2020

21-
install(FILES ../assets/clang-doc-default-stylesheet.css
22-
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
23-
COMPONENT clang-doc)
2421

25-
install(FILES ../assets/index.js
26-
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
27-
COMPONENT clang-doc)
22+
set(assets
23+
index.js
24+
clang-doc-default-stylesheet.css
25+
)
26+
27+
set(asset_dir "${CMAKE_CURRENT_SOURCE_DIR}/../assets")
28+
set(resource_dir "${CMAKE_BINARY_DIR}/share/clang")
29+
set(out_files)
30+
31+
function(copy_files_to_dst src_dir dst_dir file)
32+
set(src "${src_dir}/${file}")
33+
set(dst "${dst_dir}/${file}")
34+
add_custom_command(OUTPUT ${dst}
35+
DEPENDS ${src}
36+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
37+
COMMENT "Copying ${file} to ${dst_dir}"
38+
)
39+
list(APPEND out_files ${dst})
40+
set(out_files ${out_files} PARENT_SCOPE)
41+
endfunction(copy_files_to_dst)
42+
43+
foreach(f ${assets})
44+
install(FILES ${asset_dir}/${f}
45+
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
46+
COMPONENT clang-doc)
47+
copy_files_to_dst(${asset_dir} ${resource_dir} ${f})
48+
endforeach(f)
49+
50+
add_custom_target(copy-clang-doc-assets
51+
DEPENDS ${out_files}
52+
COMMENT "Copying Clang-Doc Assets"
53+
)
54+
set_target_properties(copy-clang-doc-assets PROPERTIES FOLDER "Clang-Doc/Assets")
55+
add_dependencies(clang-doc copy-clang-doc-assets)

0 commit comments

Comments
 (0)