From f7f243d5137bea4f016922e68715dfe204b9ab27 Mon Sep 17 00:00:00 2001 From: Ranjith Ramakrishnan Date: Wed, 23 Feb 2022 16:15:40 -0800 Subject: [PATCH] File Reorganization with backward compatibility Header installed in /opt/rocm/include/hsakmt Wrapper header files for backward compatibility Change-Id: I5f6ccac996a43a7c20e0f75e48b1c55b610f0a16 [ROCm/ROCR-Runtime commit: 5f2c75b7d62b6a1b33f7ac6f40d55df5098812d9] --- projects/rocr-runtime/CMakeLists.txt | 10 ++- .../rocr-runtime/hsakmt-backward-compat.cmake | 71 +++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 projects/rocr-runtime/hsakmt-backward-compat.cmake diff --git a/projects/rocr-runtime/CMakeLists.txt b/projects/rocr-runtime/CMakeLists.txt index 273335d7cd..cf37aa5d2d 100644 --- a/projects/rocr-runtime/CMakeLists.txt +++ b/projects/rocr-runtime/CMakeLists.txt @@ -143,7 +143,7 @@ target_sources ( ${HSAKMT_TARGET} PRIVATE ${HSAKMT_SRC} ) target_include_directories( ${HSAKMT_TARGET} PUBLIC $ - $ + $ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src ) @@ -214,9 +214,15 @@ install ( TARGETS ${HSAKMT_TARGET} EXPORT ${HSAKMT_TARGET}Targets #install ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT devel ) # Install public headers -install ( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +install ( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${HSAKMT_TARGET} COMPONENT devel PATTERN "linux" EXCLUDE ) +# Option to build header path migration helpers. +option(INCLUDE_PATH_COMPATIBILITY "Generate backward compatible headers and include paths. Use of these headers will warn when included." ON) +if(INCLUDE_PATH_COMPATIBILITY) + include(hsakmt-backward-compat.cmake) +endif() + # Record our usage data for clients find_package calls. install ( EXPORT ${HSAKMT_TARGET}Targets FILE ${HSAKMT_TARGET}Targets.cmake diff --git a/projects/rocr-runtime/hsakmt-backward-compat.cmake b/projects/rocr-runtime/hsakmt-backward-compat.cmake new file mode 100644 index 0000000000..89f356c552 --- /dev/null +++ b/projects/rocr-runtime/hsakmt-backward-compat.cmake @@ -0,0 +1,71 @@ +# Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved. +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +set(HSAKMT_WRAPPER_DIR ${CMAKE_CURRENT_BINARY_DIR}/wrapper_dir) +set(HSAKMT_WRAPPER_INC_DIR ${HSAKMT_WRAPPER_DIR}/include) +#Function to generate header template file +function(create_header_template) + file(WRITE ${HSAKMT_WRAPPER_DIR}/header.hpp.in "/* + Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the \"Software\"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */\n\n#ifndef @include_guard@\n#define @include_guard@ \n\n#pragma message(\"@file_name@ has moved to @CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/hsakmt and package include paths have changed.\\nInclude as \\\"hsakmt/@file_name@\\\" when using cmake packages.\")\n@include_statements@\n\n#endif") +endfunction() + +#use header template file and generate wrapper header files +function(generate_wrapper_header) + file(MAKE_DIRECTORY ${HSAKMT_WRAPPER_INC_DIR}) + #find all header files from include folder + file(GLOB include_files ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h) + #generate wrapper header files + foreach(header_file ${include_files}) + # set include guard + get_filename_component(INC_GUARD_NAME ${header_file} NAME_WE) + string(TOUPPER ${INC_GUARD_NAME} INC_GUARD_NAME) + set(include_guard "${include_guard}HSAKMT_WRAPPER_INCLUDE_${INC_GUARD_NAME}_H") + # set include statements + get_filename_component(file_name ${header_file} NAME) + set(include_statements "${include_statements}#include \"hsakmt/${file_name}\"\n") + configure_file(${HSAKMT_WRAPPER_DIR}/header.hpp.in ${HSAKMT_WRAPPER_INC_DIR}/${file_name}) + unset(include_guard) + unset(include_statements) + endforeach() +endfunction() + +#Creater a template for header file +create_header_template() +#Use template header file and generater wrapper header files +generate_wrapper_header() +install(DIRECTORY ${HSAKMT_WRAPPER_INC_DIR} DESTINATION . COMPONENT devel PATTERN "linux" EXCLUDE)