ROCm / hcc

HCC is an Open Source, Optimizing C++ Compiler for Heterogeneous Compute currently for the ROCm GPU Computing Platform
https://github.com/RadeonOpenCompute/hcc/wiki
Other
424 stars 106 forks source link

CMake warning on nested find_package #1448

Open MathiasMagnus opened 4 years ago

MathiasMagnus commented 4 years ago

It has annoyed me to no ends how the configuration output of rocLIBRARIES are CMake warnings that may be suppressed using -Wno-dev, but I am infact the dev of these libraries, so I don't want to universally turn of CMake script dev warnings. The warnings can be traced back to the package config scripts of HCC.

Problem

https://github.com/RadeonOpenCompute/hcc/blob/1b4c92ba631e8a5080dc82f96b3309ec834f1b19/lib/hcc-config.cmake.in#L30

The line is seemingly unecessary, as it relays to a one-liner script:

include(FindPkgConfig)

Which in turn emits a find_package(PkgConfig) command, however nesting find_package commands will mess up reporting results via canonical variables (hence the warning).

[cmake] CMake Warning (dev) at /snap/cmake/340/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:272 (message):
[cmake]   The package name passed to `find_package_handle_standard_args` (PkgConfig)
[cmake]   does not match the name of the calling package (hcc).  This can lead to
[cmake]   problems in calling code that expects `find_package` result variables
[cmake]   (e.g., `_FOUND`) to follow a certain pattern.
[cmake] Call Stack (most recent call first):
[cmake]   /snap/cmake/340/share/cmake-3.17/Modules/FindPkgConfig.cmake:45 (find_package_handle_standard_args)
[cmake]   /opt/rocm/hcc/lib/cmake/hcc/ImportedTargets.cmake:1 (include)
[cmake]   /opt/rocm/hcc/lib/cmake/hcc/hcc-config.cmake:54 (include)
[cmake]   cmake/VerifyCompiler.cmake:54 (find_package)
[cmake]   CMakeLists.txt:47 (include)
[cmake] This warning is for project developers.  Use -Wno-dev to suppress it.
[cmake] 
[cmake] -- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
[cmake] CMake Warning (dev) at /snap/cmake/340/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:272 (message):
[cmake]   The package name passed to `find_package_handle_standard_args` (PkgConfig)
[cmake]   does not match the name of the calling package (hcc).  This can lead to
[cmake]   problems in calling code that expects `find_package` result variables
[cmake]   (e.g., `_FOUND`) to follow a certain pattern.
[cmake] Call Stack (most recent call first):
[cmake]   /snap/cmake/340/share/cmake-3.17/Modules/FindPkgConfig.cmake:45 (find_package_handle_standard_args)
[cmake]   /opt/rocm/hcc/lib/cmake/hcc/ImportedTargets.cmake:1 (include)
[cmake]   /opt/rocm/hcc/lib/cmake/hcc/hcc-config.cmake:54 (include)
[cmake]   /snap/cmake/340/share/cmake-3.17/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
[cmake]   /opt/rocm/hip/lib/cmake/hip/hip-config.cmake:77 (find_dependency)
[cmake]   cmake/VerifyCompiler.cmake:58 (find_package)
[cmake]   CMakeLists.txt:47 (include)
[cmake] This warning is for project developers.  Use -Wno-dev to suppress it.

The offending code which spawns these warnings are ordinary find_package calls to hcc and hip.

https://github.com/ROCmSoftwarePlatform/rocPRIM/blob/develop/cmake/VerifyCompiler.cmake#L54-L58

The warnings actually do mangle up, as the second warning actually looks for hip, but the warning message still says hcc for both line 54 and 58.

Solution

Uncommenting this line causes no harm, as nothing after it actually makes use of PkgConfig, so why include it? If it has to leak to some external script, unrelated to hcc-config.cmake, include it there. If you really insist on keeping it, use find_dependency instead, which as per the docs was created for this very purpose:

It is designed to be used in a Package Configuration File (<PackageName>Config.cmake).

Please remove the inclusion of FindPkgConfig or change to find_dependency if need be.