Building LLVM with both DYLIB and MLIR enabled fails on cmake

Enabling both mlir and dylib fails on current master (tested with cmake 3.7 & 3.16)

cmake -DLLVM_TARGETS_TO_BUILD=host -DLLVM_ENABLE_PROJECTS=mlir -DLLVM_BUILD_LLVM_DYLIB:BOOL=ON ~/src/llvm-project/llvm

[snip]
– Targeting X86
CMake Error at /home/vchuravy/src/llvm-project/mlir/lib/Analysis/CMakeLists.txt:29 (target_link_libraries):
The keyword signature for target_link_libraries has already been used with
the target “MLIRAnalysis”. 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:

  • /home/vchuravy/src/llvm-project/llvm/cmake/modules/AddLLVM.cmake:608 (target_link_libraries)

CMake Error at /home/vchuravy/src/llvm-project/mlir/lib/Conversion/AffineToStandard/CMakeLists.txt:16 (target_link_libraries):
The keyword signature for target_link_libraries has already been used with
the target “MLIRAffineToStandard”. 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:

  • /home/vchuravy/src/llvm-project/llvm/cmake/modules/AddLLVM.cmake:608 (target_link_libraries)
    [snip]

https://cmake.org/cmake/help/latest/policy/CMP0023.html

Forcing CMP0023 to OLD circumvents the issue, but it is probably better to fix this in MLIR.
(However odd it is that CMP0023 is not defaulting to OLD)

-V