Skip to content

Commit

Permalink
Switch warning to error in wrapper headers. (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
lawruble13 authored Mar 14, 2023
1 parent 027404a commit 026eb10
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Change Log for rocm-cmake

## [(Unreleased) rocm-cmake]
### Added
- Added the option ROCM_HEADER_WRAPPER_WERROR
- Compile-time C macro in the wrapper headers causes errors to be emitted instead of warnings.
- Configure-time CMake option sets the default for the C macro.

## [(Unreleased) rocm-cmake 0.8.1 for ROCm 5.5]
### Fixed
- ROCMInstallTargets: Added compatibility symlinks for included cmake files in `<ROCM>/lib/cmake/<PACKAGE>`.
### Changed
Expand Down Expand Up @@ -110,4 +116,3 @@

## [0.4]
Pre Change Log versions

5 changes: 4 additions & 1 deletion doc/src/ROCMHeaderWrapper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ Commands
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``.
turned off by defining ``ROCM_NO_WRAPPER_HEADER_WARNING`` when using the wrapper header files.
There is an additional configure-time CMake variable ``ROCM_HEADER_WRAPPER_WERROR``, which is used
to set the default value for the compile-time C macro of the same name (with CMake truthy values setting a default of
true/1). If the compile-time macro is true, then deprecation errors will be emitted instead of warnings.

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
15 changes: 15 additions & 0 deletions share/rocm/cmake/ROCMHeaderWrapper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ ${file_contents}
file(RELATIVE_PATH correct_include "${HEADER_INSTALL_PREFIX}/${PARSE_INCLUDE_LOCATION}" "${header_location}")
string(REPLACE "/" ";" path_dirs "${file_path}")

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 "Wrapper header files emit error instead of warning.")
else()
set(ROCM_HEADER_WRAPPER_WERROR "OFF" CACHE STRING "Wrapper header files emit error instead of warning.")
endif()
endif()

if (ROCM_HEADER_WRAPPER_WERROR)
set(deprecated_error 1)
else()
set(deprecated_error 0)
endif()

set(guard_common "")
foreach(subdir IN LISTS path_dirs)
if(NOT (subdir STREQUAL '' OR subdir STREQUAL '.'))
Expand Down
7 changes: 7 additions & 0 deletions share/rocm/cmake/header_template.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@
/* include file */
#include "@file_rel_path@"
#else
#ifndef ROCM_HEADER_WRAPPER_WERROR
#define ROCM_HEADER_WRAPPER_WERROR @deprecated_error@
#endif
#if ROCM_HEADER_WRAPPER_WERROR /* ROCM_HEADER_WRAPPER_WERROR 1 */
#error "This file is deprecated. Use the header file from @header_location@ by using #include <@correct_include@>"
#else /* ROCM_HEADER_WRAPPER_WERROR 0 */
/* 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__)
#warning "This file is deprecated. Use the header file from @header_location@ by using #include <@correct_include@>"
#endif
#endif /* ROCM_HEADER_WRAPPER_WERROR */
/* include file */
#define ROCM_@ITEM_GUARD@_GAVE_WARNING
#include "@file_rel_path@"
Expand Down
33 changes: 33 additions & 0 deletions test/fail/wrapper-error.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ######################################################################################################################
# Copyright (C) 2022 Advanced Micro Devices, Inc.
# ######################################################################################################################

install_dir(${TEST_DIR}/libwrapper
CMAKE_ARGS -DBUILD_SHARED_LIBS=On -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=On -DROCM_HEADER_WRAPPER_WERROR=ON)
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 026eb10

Please sign in to comment.