diff --git a/CMakeLists.txt b/CMakeLists.txt index 61e65d4ba8..7a2763a10b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,10 @@ set( CPACK_GENERATOR "TGZ;DEB;RPM" CACHE STRING "package types to be produced " set( COPYRIGHT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/copyright" ) set( BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR} ) +if(NOT ENABLE_ASAN_PACKAGING) + option(FILE_REORG_BACKWARD_COMPATIBILITY "Enable File Reorg with backward compatibility" OFF) +endif() + ## Set variables set_variables() @@ -64,6 +68,29 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/rocm-core.prerm ${BUILD_DIR}/prerm @ #Generate BUILD_INFO configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/rocm_version.h.in ${BUILD_DIR}/rocm_version.h @ONLY ) +#File reorg Backward compatibility function +if(NOT WIN32) + if(FILE_REORG_BACKWARD_COMPATIBILITY) + # To enabe/disable #error in wrapper header files + if(NOT DEFINED ROCM_HEADER_WRAPPER_WERROR) + if(DEFINED ENV{ROCM_HEADER_WRAPPER_WERROR}) + set(ROCM_HEADER_WRAPPER_WERROR "$ENV{ROCM_HEADER_WRAPPER_WERROR}" + CACHE STRING "Header wrapper warnings as errors.") + else() + set(ROCM_HEADER_WRAPPER_WERROR "OFF" CACHE STRING "Header wrapper warnings as errors.") + endif() + endif() + + if(ROCM_HEADER_WRAPPER_WERROR) + set(deprecated_error 1) + else() + set(deprecated_error 0) + endif() + + include(rocm-core-backward-compat.cmake) + endif() #FILE_REORG_BACKWARD_COMPATIBILITY +endif() + #Make the rocmlib set( SRCS rocm_version.cpp ) add_library( ${CORE_TARGET} ${SRCS} ) diff --git a/header_template.hpp.in b/header_template.hpp.in new file mode 100644 index 0000000000..0d8c481e90 --- /dev/null +++ b/header_template.hpp.in @@ -0,0 +1,48 @@ +/* + MIT License + + Copyright (c) 2017 - 2023 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. + */ +#ifndef @include_guard@ +#define @include_guard@ + +#ifndef ROCM_HEADER_WRAPPER_WERROR +#define ROCM_HEADER_WRAPPER_WERROR @deprecated_error@ +#endif +#if ROCM_HEADER_WRAPPER_WERROR /* ROCM_HEADER_WRAPPER_WERROR 1 */ +#error "@file_name@ has moved to @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/@headerfile_dir@ " +#else /* ROCM_HEADER_WRAPPER_WERROR 0 */ +#if defined(__GNUC__) +#warning "@file_name@ has moved to @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/@headerfile_dir@ " +#else +#pragma message ("@file_name@ has moved to @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/@headerfile_dir@ ") +#endif +#endif /* ROCM_HEADER_WRAPPER_WERROR */ + +@include_statements@ + +@hashzero_check@ + +@file_contents@ + +@hash_endif@ + +#endif diff --git a/rocm-core-backward-compat.cmake b/rocm-core-backward-compat.cmake new file mode 100644 index 0000000000..e96572e669 --- /dev/null +++ b/rocm-core-backward-compat.cmake @@ -0,0 +1,63 @@ +# Copyright (c) 2023 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. + +cmake_minimum_required(VERSION 3.16.8) + +set(ROCM_CORE_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}) +set(ROCM_CORE_WRAPPER_DIR ${ROCM_CORE_BUILD_DIR}/wrapper_dir) +set(ROCM_CORE_WRAPPER_INC_DIR ${ROCM_CORE_WRAPPER_DIR}/include) +set(headerfile_dir "rocm-core") + +#Function to set actual file contents in wrapper files +#Some components grep for the contents in the file +function(set_file_contents input_file) + set(hashzero_check "#if 0 +/* The following is a copy of the original file for the benefit of build systems which grep for values + * in this file rather than preprocess it. This is just for backward compatibility */") + + file(READ ${input_file} file_contents) + set(hash_endif "#endif") + get_filename_component(file_name ${input_file} NAME) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/header_template.hpp.in ${ROCM_CORE_WRAPPER_INC_DIR}/${file_name}) +endfunction() + +#use header template file and generate wrapper header files +function(generate_wrapper_header) + file(MAKE_DIRECTORY ${ROCM_CORE_WRAPPER_INC_DIR}) + + #find all header files + file(GLOB include_files ${ROCM_CORE_BUILD_DIR}/*.h) + #Create wrapper files + foreach(header_file ${include_files}) + # set include guard + get_filename_component(INC_GAURD_NAME ${header_file} NAME_WE) + string(TOUPPER ${INC_GAURD_NAME} INC_GAURD_NAME) + set(include_guard "ROCM_CORE_WRAPPER_INCLUDE_${INC_GAURD_NAME}_H") + #set #include statement + get_filename_component(file_name ${header_file} NAME) + set(include_statements "#include \"${headerfile_dir}/${file_name}\"\n") + set_file_contents(${header_file}) + endforeach() + +endfunction() + +#Use template header file and generater wrapper header files +generate_wrapper_header() +install(DIRECTORY ${ROCM_CORE_WRAPPER_INC_DIR} DESTINATION . COMPONENT runtime) +