-
Notifications
You must be signed in to change notification settings - Fork 14.1k
[Offload] Correctly regenerate API files if modified #141679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -2,8 +2,8 @@ | |||||||
# include directory. These files are checked in with the rest of the source, | ||||||||
# therefore it is only needed when making changes to the API. | ||||||||
|
||||||||
find_program(CLANG_FORMAT clang-format PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) | ||||||||
if (CLANG_FORMAT) | ||||||||
find_program(clang_format clang-format PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) | ||||||||
if (clang_format) | ||||||||
set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/OffloadAPI.td) | ||||||||
|
||||||||
tablegen(OFFLOAD OffloadAPI.h -gen-api) | ||||||||
|
@@ -13,15 +13,31 @@ if (CLANG_FORMAT) | |||||||
tablegen(OFFLOAD OffloadPrint.hpp -gen-print-header) | ||||||||
tablegen(OFFLOAD OffloadErrcodes.inc -gen-errcodes) | ||||||||
|
||||||||
set(FILES_TO_COPY "OffloadAPI.h;OffloadEntryPoints.inc;OffloadFuncs.inc;OffloadImplFuncDecls.inc;OffloadPrint.hpp") | ||||||||
set(GEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include/generated) | ||||||||
set(files_to_copy "OffloadAPI.h;OffloadEntryPoints.inc;OffloadFuncs.inc;OffloadImplFuncDecls.inc;OffloadPrint.hpp") | ||||||||
set(generated_dir ${CMAKE_CURRENT_SOURCE_DIR}/../include/generated) | ||||||||
set(shared_dir ${LIBOMPTARGET_INCLUDE_DIR}/Shared) | ||||||||
add_public_tablegen_target(OffloadGenerate) | ||||||||
add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CLANG_FORMAT} | ||||||||
-i ${TABLEGEN_OUTPUT}) | ||||||||
add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND} | ||||||||
-E copy_if_different ${FILES_TO_COPY} ${GEN_DIR}) | ||||||||
add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND} | ||||||||
-E copy_if_different OffloadErrcodes.inc "${LIBOMPTARGET_INCLUDE_DIR}/Shared/OffloadErrcodes.inc") | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be missing after the change. @RossBrunton I'm not sure why it's separate from the others, is it because the output directory is different? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this confused me because there's no such file in this directory and there's already a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RossBrunton it's safe to delete this, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is here because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, so this is generated like the others but installed there. We really should just tablegen these on demand. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I very nearly have a PR ready to do that, should be up later today There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||||||||
|
||||||||
add_custom_target(OffloadAPI DEPENDS OffloadGenerate) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
add_custom_command( | ||||||||
OUTPUT ${shared_dir}/OffloadErrcodes.inc | ||||||||
COMMAND ${clang_format} -i OffloadErrcodes.inc | ||||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different OffloadErrcodes.inc ${shared_dir} | ||||||||
DEPENDS OffloadErrcodes.inc | ||||||||
) | ||||||||
add_custom_target(OffloadAPI.OffloadErrcodes.inc DEPENDS ${shared_dir}/OffloadErrcodes.inc) | ||||||||
add_dependencies(OffloadAPI OffloadAPI.OffloadErrcodes.inc) | ||||||||
foreach(file IN LISTS files_to_copy) | ||||||||
add_custom_command( | ||||||||
OUTPUT ${generated_dir}/${file} | ||||||||
COMMAND ${clang_format} -i ${file} | ||||||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${generated_dir} | ||||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${file} ${generated_dir} | ||||||||
DEPENDS ${file} | ||||||||
) | ||||||||
add_custom_target(OffloadAPI.${file} DEPENDS ${generated_dir}/${file}) | ||||||||
add_dependencies(OffloadAPI OffloadAPI.${file}) | ||||||||
endforeach() | ||||||||
else() | ||||||||
message(WARNING "clang-format was not found, so the OffloadGenerate target\ | ||||||||
will not be available. Offload will still build, but you will not be\ | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,11 @@ if(LLVM_HAVE_LINK_VERSION_SCRIPT) | |
endif() | ||
|
||
target_include_directories(LLVMOffload PUBLIC | ||
${CMAKE_CURRENT_BINARY_DIR}/../include | ||
${CMAKE_CURRENT_SOURCE_DIR}/include | ||
${CMAKE_CURRENT_SOURCE_DIR}/include/generated | ||
${CMAKE_CURRENT_SOURCE_DIR}/../include | ||
${CMAKE_CURRENT_SOURCE_DIR}/../plugins-nextgen/common/include) | ||
${CMAKE_CURRENT_BINARY_DIR}/../include | ||
${CMAKE_CURRENT_SOURCE_DIR}/include | ||
${CMAKE_CURRENT_SOURCE_DIR}/include/generated | ||
${CMAKE_CURRENT_SOURCE_DIR}/../include | ||
${CMAKE_CURRENT_SOURCE_DIR}/../plugins-nextgen/common/include) | ||
Comment on lines
+22
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] unrelated noise |
||
|
||
target_compile_options(LLVMOffload PRIVATE ${offload_compile_flags}) | ||
target_link_options(LLVMOffload PRIVATE ${offload_link_flags}) | ||
|
@@ -33,6 +33,11 @@ target_compile_definitions(LLVMOffload PRIVATE | |
DEBUG_PREFIX="Liboffload" | ||
) | ||
|
||
# Make sure these are up-to-date if modified. | ||
if(TARGET OffloadAPI) | ||
add_dependencies(LLVMOffload OffloadAPI) | ||
endif() | ||
|
||
set_target_properties(LLVMOffload PROPERTIES | ||
POSITION_INDEPENDENT_CODE ON | ||
INSTALL_RPATH "$ORIGIN" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
find_program creates an entry into the
CMakeCache.txt
. By convention, those are upper case.