VS: Generator can't handle imported targets that define multiple import libraries
Hi,
I've run into a small issue; using CMake 3.16.4 and VS 2019 x64 (16.4.6). The following CMakeLists.txt demonstrates the problem:
cmake_minimum_required(VERSION 3.16)
project(Test)
add_library(A SHARED IMPORTED)
set_target_properties(A PROPERTIES
IMPORTED_IMPLIB "c:/tmp/A.lib;c:/tmp/B.lib"
)
add_library(TestLib SHARED main.cpp)
target_link_libraries(TestLib PRIVATE A)
If I configure the above project using cmake -S . -B build -G "Visual Studio 16 2019" -A x64
and open the generated solution in VS, then select TestLib
, go to Project Properties -> Linker -> Input -> Additional Dependencies
, I get the following as the first line in the edit box:
c:\tmp\A.lib%3Bc:\tmp\B.lib
Note the '%3B' instead of the expected semicolon. Now, VS displays the 'evaluated value' correctly, in two separate lines, however the value that gets passed to the compiler is that entire string (as a single argument) and the compiler fails to find the import libraries and as a result, the linking step fails. If I open the .vcxproj
in a text editor, I can see the incorrect value inside the <Link>
element: <AdditionalDependencies>c:\tmp\A.lib%3Bc:\tmp\B.lib...
.
Changing the '%3B' character to a semicolon, it works, but I haven't found a way for the CMake + VS generator to produce the desired value (other than adding import libraries directly to the TestLib target via target_link_libraries, but that is less than ideal).