Skip to content
Merged
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions clang-tools-extra/clang-doc/tool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ install(FILES ../assets/clang-doc-default-stylesheet.css
install(FILES ../assets/index.js
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
COMPONENT clang-doc)

add_custom_target(copy-clang-doc-assets
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer having a rule per file since most systems don't have a reliable way to tell if the directory content has changed. The approach we usually use to to have one add_custom_command per file with a single add_custom_target that depends on all output files, see for example

foreach(f ${files})
set(src "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
set(dst "${LIBCXX_GENERATED_INCLUDE_DIR}/${f}")
add_custom_command(OUTPUT ${dst}
DEPENDS ${src}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
COMMENT "Copying CXX header ${f}")
list(APPEND _all_includes "${dst}")
endforeach()
# Generate the IWYU mapping. This depends on all header files but it's also considered as an
# "include" for dependency tracking.
add_custom_command(OUTPUT "${LIBCXX_GENERATED_INCLUDE_DIR}/libcxx.imp"
COMMAND "${Python3_EXECUTABLE}" "${LIBCXX_SOURCE_DIR}/utils/generate_iwyu_mapping.py" "-o" "${LIBCXX_GENERATED_INCLUDE_DIR}/libcxx.imp"
DEPENDS ${_all_includes}
COMMENT "Generate the mapping file for include-what-you-use"
)
list(APPEND _all_includes "${LIBCXX_GENERATED_INCLUDE_DIR}/libcxx.imp")
add_custom_target(generate-cxx-headers ALL DEPENDS ${_all_includes})
or https://github.com/llvm/llvm-project/blob/092dbfaad257885692fa64559e9eb43a5c466798/clang/lib/Headers/CMakeLists.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I’ll take a pass at adapting one of those for use here. If I think I can generalize it, I’ll make another PR to add it as a utility in the llvm cmake module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is addressed now. I more or less cribed directly from the clang header example. Initially I tried to have the function be a bit more generic and put it in llvm/cmake/modules/CopyLLVMFiles.cmake, but my normal methods of including don't seem to work in clang-doc. Likely I'm just holding that part wrong, but I don't see anything in clang-tools-extra using include(AddLLVM) or some other module.

Happy to refactor if you have some other suggestions.

COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different "${CMAKE_CURRENT_SOURCE_DIR}/../assets" "${CMAKE_BINARY_DIR}/share/clang"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../assets"
COMMENT "Copying Clang-Doc Assets"
)
set_target_properties(copy-clang-doc-assets PROPERTIES FOLDER "Clang-Doc/Assets")
add_dependencies(clang-doc copy-clang-doc-assets)