Skip to content

Commit

Permalink
Cherry pick file dump required for SWDEV-334945
Browse files Browse the repository at this point in the history
Change-Id: I6c8f7f89ffd3479fd2116f0db23326e91164a43c
(cherry picked from commit e852c4019381329f93d42bc52276647c68449fa0)
  • Loading branch information
Jenkins authored and nunnikri committed May 4, 2022
1 parent 472c361 commit a52cb6f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [0.7.3]
### Added
- Header wrapper functionality included. This is to support the change in header file locations in ROCm 5.2, while providing backwards compatibility via header file wrappers.
The associated deprecation warning can be disabled by defining `ROCM_NO_WRAPPER_HEADER_WARNING` before including the wrapper header.
### Fixed
- Fixed spurious failures in `rocm_check_target_ids` for target ids with target features when `-Werror` is enabled.
The `HAVE_<target-id>` result variable has been renamed to `COMPILER_HAS_TARGET_ID_<sanitized-target-id>`.
Expand Down
14 changes: 11 additions & 3 deletions doc/src/ROCMHeaderWrapper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ Commands
[GUARDS <guard>...]
[WRAPPER_LOCATIONS <wrapper-location>...]
[OUTPUT_LOCATIONS <output-location>...]
[ORIGINAL_FILES <original-file>...]
)
Create a C/C++ wrapper file for each specified header file.
Create a C/C++ wrapper file for each specified header file. The wrapper is simply a C/C++ header
that emits a deprecation warning before including its corresponding header. The warning can be
turned off by defining ``ROCM_NO_WRAPPER_HEADER_WARNING``.

Any relative header or wrapper locations are relative to ``${CPACK_PACKAGING_INSTALL_PREFIX}`` if it is set,
or to ``${CMAKE_INSTALL_PREFIX}`` otherwise (i.e. the install directory).
Expand Down Expand Up @@ -67,21 +70,26 @@ The second wrapper file uses the default locations, so it will be created at ``$
Its include guard will be ``ROCM_EXAMPLE_INC_FOO_BAR_H``, and it will include the file ``../../../include/rocexample/foo/bar.h``
(which is the correct file when this wrapper is installed at ``${CMAKE_INSTALL_PREFIX}/rocexample/include/foo/bar.h``)

If the name of the wrapper file being generated is the same as the name of any ``<original-file>``, the contents of that
``<original-file>`` will be added to the wrapper file inside a ``#if 0`` block. This has no effect on the code of the header,
but it does allow projects which search for specific strings inside a header file to function correctly.


.. cmake::command:: rocm_wrap_header_dir
.. code-block:: cmake
rocm_wrap_header_file(
rocm_wrap_header_dir(
<include-directory>
[HEADER_LOCATION <header-location>]
[GUARDS <guard>...]
[WRAPPER_LOCATIONS <wrapper-location>...]
[OUTPUT_LOCATIONS <output-location>...]
[PATTERNS <pattern>...]
[ORIGINAL_FILES <original-file>...]
)
Create a C/C++ wrapper file for each header file in the given directory (or any subdirectory) matching at least one pattern.

Each file in the specified directory which matches a pattern will have a wrapper file created for it.
The ``<header-file>`` used in each call to ``rocm_wrap_header_file`` is the path to the header file relative to ``<include-directory>``.
The ``<header-file>`` used in each call to ``rocm_wrap_header_file`` is the path to the header file relative to ``<include-directory>``.
35 changes: 32 additions & 3 deletions share/rocm/cmake/ROCMHeaderWrapper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(ROCM_WRAPPER_TEMPLATE_HEADER "${CMAKE_CURRENT_LIST_DIR}/header_template.h.in
function(rocm_wrap_header_dir DIRECTORY)
set(options )
set(oneValueArgs HEADER_LOCATION INCLUDE_LOCATION)
set(multiValueArgs PATTERNS GUARDS WRAPPER_LOCATIONS OUTPUT_LOCATIONS)
set(multiValueArgs PATTERNS GUARDS WRAPPER_LOCATIONS OUTPUT_LOCATIONS ORIGINAL_FILES)
cmake_parse_arguments(PARSE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT PARSE_HEADER_LOCATION)
set(PARSE_HEADER_LOCATION "include/${CMAKE_PROJECT_NAME}")
Expand All @@ -19,6 +19,9 @@ function(rocm_wrap_header_dir DIRECTORY)
if(NOT PARSE_PATTERNS)
set(PARSE_PATTERNS "*.h;*.hpp;*.hh;*.hxx;*.inl")
endif()
if(NOT DEFINED PARSE_ORIGINAL_FILES)
set(PARSE_ORIGINAL_FILES)
endif()
foreach(PATTERN IN LISTS PARSE_PATTERNS)
list(APPEND QUALIFIED_PATTERNS "${DIRECTORY}/${PATTERN}")
endforeach()
Expand All @@ -31,14 +34,15 @@ function(rocm_wrap_header_dir DIRECTORY)
INCLUDE_LOCATION ${PARSE_INCLUDE_LOCATION}
WRAPPER_LOCATIONS ${PARSE_WRAPPER_LOCATIONS}
OUTPUT_LOCATIONS ${PARSE_OUTPUT_LOCATIONS}
ORIGINAL_FILES ${PARSE_ORIGINAL_FILES}
)
endforeach()
endfunction()

function(rocm_wrap_header_file)
set(options )
set(oneValueArgs HEADER_LOCATION INCLUDE_LOCATION)
set(multiValueArgs GUARDS WRAPPER_LOCATIONS OUTPUT_LOCATIONS HEADERS)
set(multiValueArgs GUARDS WRAPPER_LOCATIONS OUTPUT_LOCATIONS HEADERS ORIGINAL_FILES)
cmake_parse_arguments(PARSE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(PARSE_HEADERS ${PARSE_HEADERS} ${PARSE_UNPARSED_ARGUMENTS})
if(NOT PARSE_HEADER_LOCATION)
Expand All @@ -47,14 +51,39 @@ function(rocm_wrap_header_file)
if(NOT PARSE_INCLUDE_LOCATION)
set(PARSE_INCLUDE_LOCATION "include")
endif()
if(NOT DEFINED PARSE_ORIGINAL_FILES)
set(PARSE_ORIGINAL_FILES)
endif()
foreach(INCLUDE_FILE IN LISTS PARSE_HEADERS)
get_filename_component(INCLUDE_FILE_NAME "${INCLUDE_FILE}" NAME)
set(original_contents "")
foreach(ORIGINAL_FILE IN LISTS PARSE_ORIGINAL_FILES)
get_filename_component(ORIGINAL_FILE_NAME "${ORIGINAL_FILE}" NAME)
if(INCLUDE_FILE_NAME STREQUAL ORIGINAL_FILE_NAME)
file(READ ${ORIGINAL_FILE} file_contents)
set(original_contents_section
"#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_contents}
#endif")
endif()
endforeach()
set(GUARD_LIST ${PARSE_GUARDS})
set(WRAPPER_LOC_LIST ${PARSE_WRAPPER_LOCATIONS})
set(OUTPUT_LOC_LIST ${PARSE_OUTPUT_LOCATIONS})
if(CPACK_PACKAGING_INSTALL_PREFIX)
set(HEADER_INSTALL_PREFIX "${CPACK_PACKAGING_INSTALL_PREFIX}")
else()
elseif(CMAKE_INSTALL_PREFIX)
set(HEADER_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
else()
if(NOT WIN32)
set(HEADER_INSTALL_PREFIX "/usr/local")
else()
set(HEADER_INSTALL_PREFIX "c:/Program Files/${PROJECT_NAME}")
endif()
endif()
get_filename_component(header_location "${PARSE_HEADER_LOCATION}/${INCLUDE_FILE}"
ABSOLUTE BASE_DIR "${HEADER_INSTALL_PREFIX}")
Expand Down
19 changes: 10 additions & 9 deletions share/rocm/cmake/header_template.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
#ifndef @include_guard@
#define @include_guard@

#ifndef ROCM_@ITEM_GUARD@_GAVE_WARNING
#define ROCM_@ITEM_GUARD@_GAVE_WARNING

#if defined(ROCM_NO_WRAPPER_HEADER_WARNING) || defined(ROCM_@ITEM_GUARD@_GAVE_WARNING)
/* include file */
#include "@file_rel_path@"
#else
/* give warning */
#if defined(_MSC_VER)
#pragma message(": warning:This file is deprecated. Use the header file from @header_location@ by using #include <@correct_include@>")
#elif defined(__GNUC__)
#pragma message(": warning : This file is deprecated. Use the header file from @header_location@ by using #include <@correct_include@>")
#endif
/* include file */
#define ROCM_@ITEM_GUARD@_GAVE_WARNING
#include "@file_rel_path@"

#undef ROCM_@ITEM_GUARD@_GAVE_WARNING
#else

#include "@file_rel_path@"
#endif /* defined(ROCM_NO_WRAPPER_HEADER_WARNING) || defined(ROCM_@ITEM_GUARD@_GAVE_WARNING) */

#endif // ROCM_@ITEM_GUARD@_GAVE_WARNING
#endif /* @include_guard@ */

#endif // @include_guard@
@original_contents_section@
34 changes: 34 additions & 0 deletions test/pass/wrapper-nowarn.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ######################################################################################################################
# Copyright (C) 2022 Advanced Micro Devices, Inc.
# ######################################################################################################################

install_dir(${TEST_DIR}/libwrapper
CMAKE_ARGS -DBUILD_SHARED_LIBS=On -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=On -DERR_ON_WARN=ON
-DCMAKE_CXX_FLAGS='-DROCM_NO_WRAPPER_HEADER_WARNING')
test_check_package(
NAME test-wrapper
HEADER wrapper.h
TARGET wrapper)
test_check_package(
NAME test-wrapper
HEADER wrapper/wrapper.h
TARGET wrapper
)
test_check_package(
NAME test-wrapper
HEADER other.h
TARGET wrapper)
test_check_package(
NAME test-wrapper
HEADER other/other.h
TARGET wrapper
)
test_check_package(
NAME test-wrapper
HEADER other/th/two-letter-dir.h
TARGET wrapper)
test_check_package(
NAME test-wrapper
HEADER th/two-letter-dir.h
TARGET wrapper
)

0 comments on commit a52cb6f

Please sign in to comment.