Transitive link libraries creates invalid include path
CMake produces an incorrect include path, where two includes are merged into one with a semicolor (;
) separator. The platform is Windows with MSYS2. Specifically, the bug occurs when linking against MSMPI and boost, which are two imported targets.
-I"/C/Program Files (x86)/Microsoft SDKs/MPI/Include;C:/Users/giraldeauf/.conan/data/boost/1.44.0/fg/stable/package/17c652b0a006fb0b661c7230a896550edc056b19/include/boost-1_44"
The two include paths should not be merged into one. For the case above, the correct include path is:
-isystem /C/Users/giraldeauf/.conan/data/boost/1.44.0/nrc/stable/package/17c652b0a006fb0b661c7230a896550edc056b19/include/boost-1_44 -isystem "/C/Program Files (x86)/Microsoft SDKs/MPI/Include"
I was able to reproduce the problem with a small sample:
# Case 1 - PASS : direct linking, no transitivity
add_executable(pass1 main.cpp)
target_link_libraries(pass1 MPI::MPI_CXX CONAN_PKG::boost)
# Case 2 - PASS : (foo1, boost) -> (bar1, mpi) -> pass2
add_library(foo1 foo.cpp)
target_link_libraries(foo1 CONAN_PKG::boost)
add_library(bar1 bar.cpp)
target_link_libraries(bar1 foo1 MPI::MPI_CXX)
add_executable(pass2 main.cpp)
target_link_libraries(pass2 bar1)
# Case 3 - FAIL : (bar2, mpi) -> (foo2, boost) -> fail1
add_library(bar2 bar.cpp)
target_link_libraries(bar2 MPI::MPI_CXX)
add_library(foo2 foo.cpp)
target_link_libraries(foo2 bar2 CONAN_PKG::boost)
add_executable(fail1 main.cpp)
target_link_libraries(fail1 foo2)
Case 1 and 2 produce the correct include path, while in case 3 the include path is incorrect. I suspect that it is related to the fact that one of the path contains spaces and the quotes are required.
As a workaround, I do explicit linking of dependent libraries instead of relying on transitivity.