'"uses of target_link_libraries must be either all-keyword or all-plain"

I managed to build llvm and clang and now I am trying to create a ClangTool according to clang docs. But I am getting the following error when I am trying to build it:

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)

My current CMakeLists.txt is:

set(LLVM_LINK_COMPONENTS support)

add_clang_executable(loop-convert
  LoopConvert.cpp
)

target_link_libraries(loop-convert
  clangTooling
  clangBasic
  clangASTMatchers
)


Solution 1:[1]

If you can't migrate all calls to target_link_libraries to the new keyword-based signature, you can work around the pedantic error with:

function(target_link_libraries target)
    if(ARGV1 MATCHES "^(PRIVATE|PUBLIC|INTERFACE)$")
        _target_link_libraries(${target} ${ARGN})
    else()
        _target_link_libraries(${target} PUBLIC ${ARGN})
    endif()
endfunction()

This makes the function backward-compatible, while still allowing the newer signature to be used. IMHO, this should have be been CMake's default behavior.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1