cmake “target_link_libraries的使用必须是全关键字或全纯文本”

lnlaulya  于 2022-11-11  发布在  其他
关注(0)|答案(2)|浏览(476)

我设法构建了llvm和clang,现在我正试图根据clang文档创建一个ClangTool。但是当我试图构建它时,我得到了以下错误:

CMake Error at tools/clang/tools/loop-convert/CMakeLists.txt:6 (target_link_libraries):
  The keyword signature for target_link_libraries has already been used with 
  the target "loop-convert".  All uses of target_link_libraries with a target
  must be either all-keyword or all-plain.

  The uses of the keyword signature are here:

    * cmake/modules/LLVM-Config.cmake:105 (target_link_libraries)
    * cmake/modules/AddLLVM.cmake:771 (target_link_libraries)

我目前的CMakeLists.txt是:

set(LLVM_LINK_COMPONENTS support)

add_clang_executable(loop-convert
  LoopConvert.cpp
)

target_link_libraries(loop-convert
  clangTooling
  clangBasic
  clangASTMatchers
)
0kjbasz6

0kjbasz61#

您需要使用关键字target_link_libraries签名;实际上,您需要将PRIVATE添加到CMakeLists.txt中的target_link_libraries语句中:

target_link_libraries(loop-convert PRIVATE
  clangTooling
  clangBasic
  clangASTMatchers
)

这是因为add_llvm_executable使用了这样的签名,您不能在CMake中混合它们。

nwo49xxi

nwo49xxi2#

恕我直言,CMake应该只是打印一个迂腐的警告,而不是硬破坏人们一直依赖的API。下面的代码使函数向后兼容,同时仍然允许使用较新的签名。它打印一个警告,提醒你升级代码。

function(target_link_libraries target)
    if(ARGV1 MATCHES "^(PRIVATE|PUBLIC|INTERFACE)$")
        _target_link_libraries(${target} ${ARGN})
    else()
        _target_link_libraries(${target} PUBLIC ${ARGN})
        message(AUTHOR_WARNING "target_link_libraries: missing PRIVATE, PUBLIC or INTERFACE for target ${target}. Defaulting to PUBLIC.")
    endif()
endfunction()

相关问题