我真的应该将头文件指定为 target_sources() 吗?

ein*_*ica 6 c++ cmake header-files buildconfiguration

In his Meeting C++ 2019 talk (and also in 2018), presenter Deniz Bahadir recommends that we specify targets' C++ header files using target_sources(), with some of them being PUBLIC or INTERFACE.

But - when I try to do that (using relative paths, like I used to with the good old add_target()), I get this kind of error:

CMake Warning (dev) at CMakeLists.txt:26 (target_sources):
  Policy CMP0076 is not set: target_sources() command converts relative paths
  to absolute.  Run "cmake --help-policy CMP0076" for policy details.  Use
  the cmake_policy command to set the policy and suppress this warning.

  An interface source of target "cuda-api-wrappers" has a relative path.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
CMake Error in CMakeLists.txt:
  Target "cuda-api-wrappers" INTERFACE_SOURCES property contains relative
  path:

    "src/cuda/api/miscellany.hpp"
Run Code Online (Sandbox Code Playgroud)

So, what, am I supposed to put the header file names in generator expressions or something? I certainly don't want absolute paths to my source dir ending up in the library's interface. This seems weird to me. Maybe I just should bother with the header files in target_sources() after all?

PS - Using CMake 3.13.4 on Devuan 3.

uvs*_*tid 6

CMakeLists.txt如果指定以上版本,此错误就会消失3.13.0

cmake_minimum_required(VERSION 3.13.0)
Run Code Online (Sandbox Code Playgroud)

来自官方文档:

  • 这里

    相对源文件路径被解释为相对于当前源目录...

  • 这里

    在 CMake 3.13 及更高版本中,target_sources() 命令现在将相对源文件路径转换为绝对路径...