vcpkg icon indicating copy to clipboard operation
vcpkg copied to clipboard

[vtk] Duplicate dependencies will result in an error

Open QiuYilin opened this issue 1 year ago • 6 comments

Operating system

Windows

Compiler

MSVC

Steps to reproduce the behavior

My vcpkg have package vtk[qt] and pcl[qt,vtk]. My cmake project has two components that depend on PCL and VTK respectively. component A

find_package(PCL REQUIRED)
target_link_libraries(${component} PRIVATE ${PCL_LIBRARIES})

component B

find_package(VTK REQUIRED)
target_link_libraries(${component} PRIVATE ${VTK_LIBRARIES})

If I compile the two components at the same time, an error will occur.

Failure logs

FindPEGL.cmake

if(TARGET taocpp::pegtl)
    message(STATUS "Searching for PEGTL - found target taocpp::pegtl")
    set_target_properties(taocpp::pegtl PROPERTIES IMPORTED_GLOBAL TRUE)
    if(NOT TARGET PEGTL::PEGTL)
       add_library(PEGTL::PEGTL IMPORTED INTERFACE)
       target_link_libraries(PEGTL::PEGTL INTERFACE taocpp::pegtl)
    endif()
else()

error

	"resource": "/C:/src/sfr-vcpkg/installed/x64-windows/share/vtk/FindPEGTL.cmake",
	"owner": "cmake-configure-diags",
	"severity": 8,
	"message": "CMake Error at C:/src/sfr-vcpkg/installed/x64-windows/share/vtk/FindPEGTL.cmake:26 (set_target_properties):Attempt to promote imported target \"taocpp::pegtl\" to global scope (by\nsetting IMPORTED_GLOBAL) which is not built in this directory.",

Additional context

I think it can be modified like this:

    get_target_property(TARGET_IMPORTED_GLOBAL taocpp::pegtl IMPORTED_GLOBAL)
      if(NOT TARGET_IMPORTED_GLOBAL)
        set_target_properties(taocpp::pegtl PROPERTIES IMPORTED_GLOBAL TRUE)
    endif()

QiuYilin avatar Nov 21 '23 06:11 QiuYilin

@QiuYilin, Thanks for posting this issue, please try use pcl port provide usage:

    find_package(PCL CONFIG REQUIRED)
    target_link_libraries(main PRIVATE ${PCL_LIBRARIES})

I tested the usage successfully on my machine:

cmake_minimum_required (VERSION 3.8)

project(test)

find_package(VTK REQUIRED)
include("${VTK_USE_FILE}")
find_package(PCL CONFIG REQUIRED)
# Add source to this project's executable.
add_executable (test "usageTest.cpp")

target_link_libraries(test PRIVATE ${VTK_LIBRARIES})
target_link_libraries(test PRIVATE ${PCL_LIBRARIES})
1> CMake generation started for configuration: 'x64-Debug'.
1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Visual Studio 17 2022" -A x64  -DCMAKE_CONFIGURATION_TYPES:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\test\source\repos\usageTest\out\install\x64-Debug"  -DCMAKE_TOOLCHAIN_FILE=F:/test/vcpkg/scripts/buildsystems/vcpkg.cmake "C:\Users\test\source\repos\usageTest" 2>&1"
1> Working directory: C:\Users\test\source\repos\usageTest\out\build\x64-Debug
1> [CMake] -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
1> [CMake] -- The C compiler identification is MSVC 19.37.32826.1
1> [CMake] -- The CXX compiler identification is MSVC 19.37.32826.1
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- Detecting CXX compiler ABI info
1> [CMake] -- Detecting CXX compiler ABI info - done
1> [CMake] -- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting CXX compile features
1> [CMake] -- Detecting CXX compile features - done
1> [CMake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
1> [CMake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
1> [CMake] -- Looking for pthread_create in pthreads
1> [CMake] -- Looking for pthread_create in pthreads - not found
1> [CMake] -- Looking for pthread_create in pthread
1> [CMake] -- Looking for pthread_create in pthread - not found
1> [CMake] -- Found Threads: TRUE  
1> [CMake] -- Performing Test HAVE_STDATOMIC
1> [CMake] -- Performing Test HAVE_STDATOMIC - Success
1> [CMake] -- Found WrapAtomic: TRUE  
1> [CMake] -- Found ZLIB: optimized;F:/test/vcpkg/installed/x64-windows/lib/zlib.lib;debug;F:/test/vcpkg/installed/x64-windows/debug/lib/zlibd.lib (found version "1.3.0")  
1> [CMake] -- Found utf8cpp: F:/test/vcpkg/installed/x64-windows/include/utf8cpp  
1> [CMake] -- Found JsonCpp: F:/test/vcpkg/installed/x64-windows/debug/lib/jsoncpp.lib (found version "1.9.5") 
1> [CMake] -- Found OGG: F:/test/vcpkg/installed/x64-windows/debug/lib/ogg.lib  
1> [CMake] -- Found THEORA: F:/test/vcpkg/installed/x64-windows/debug/lib/theora.lib  
1> [CMake] -- Found NetCDF: F:/test/vcpkg/installed/x64-windows/include (found version "4.8.1") 
1> [CMake] -- Found TIFF: optimized;F:/test/vcpkg/installed/x64-windows/lib/tiff.lib;debug;F:/test/vcpkg/installed/x64-windows/debug/lib/tiffd.lib (found version "4.6.0")  
1> [CMake] -- Found ZLIB: optimized;F:/test/vcpkg/installed/x64-windows/lib/zlib.lib;debug;F:/test/vcpkg/installed/x64-windows/debug/lib/zlibd.lib (found suitable version "1.3.0", minimum required is "1")  
1> [CMake] -- Searching for PEGTL
1> [CMake] -- Searching for PEGTL - found target taocpp::pegtl
1> [CMake] -- Found Iconv: F:/test/vcpkg/installed/x64-windows/debug/lib/iconv.lib (found version "1.17") 
1> [CMake] -- Found ZLIB: optimized;F:/test/vcpkg/installed/x64-windows/lib/zlib.lib;debug;F:/test/vcpkg/installed/x64-
1> [CMake] 
1> [CMake] -- Found CGNS: F:/test/vcpkg/installed/x64-windows/include (found suitable version "4.40", minimum required is "4.10") 
1> [CMake] -- Found LibHaru: F:/test/vcpkg/installed/x64-windows/debug/lib/hpdf.lib (found suitable version "2.4.4", minimum required is "2.4.0") 
1> [CMake] -- Found PNG: optimized;F:/test/vcpkg/installed/x64-windows/lib/libpng16.lib;debug;F:/test/vcpkg/installed/x64-windows/debug/lib/libpng16d.lib (found version "1.6.39") 
1> [CMake] -- Found nlohmann_json: F:/test/vcpkg/installed/x64-windows/share/nlohmann_json/nlohmann_jsonConfig.cmake (found version "3.11.2") 
1> [CMake] -- Found SQLite3: F:/test/vcpkg/installed/x64-windows/include (found version "3.43.2") 
1> [CMake] -- Found Eigen3: F:/test/vcpkg/installed/x64-windows/include/eigen3 (found version "3.4.0") 
1> [CMake] -- Found OpenGL: opengl32  found components: OpenGL 
1> [CMake] -- Found EXPAT: optimized;F:/test/vcpkg/installed/x64-windows/lib/libexpat.lib;debug;F:/test/vcpkg/installed/x64-windows/debug/lib/libexpatd.lib (found version "2.5.0") 
1> [CMake] -- Found double-conversion: F:/test/vcpkg/installed/x64-windows/debug/lib/double-conversion.lib  
1> [CMake] -- Found LibLZMA: optimized;F:/test/vcpkg/installed/x64-windows/lib/lzma.lib;debug;F:/test/vcpkg/installed/x64-windows/debug/lib/lzma.lib (found version "5.4.4") 
1> [CMake] -- Found LZMA: optimized;F:/test/vcpkg/installed/x64-windows/lib/lzma.lib;debug;F:/test/vcpkg/installed/x64-windows/debug/lib/lzma.lib (found version "5.4.4") 
1> [CMake] -- Found JPEG: optimized;F:/test/vcpkg/installed/x64-windows/lib/jpeg.lib;debug;F:/test/vcpkg/installed/x64-windows/debug/lib/jpeg.lib (found version "62") 
1> [CMake] -- Found Freetype: optimized;F:/test/vcpkg/installed/x64-

1> [CMake] 
1> [CMake] -- Generating done (0.1s)
1> [CMake] -- Build files have been written to: C:/Users/test/source/repos/usageTest/out/build/x64-debug
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted toolchain configurations.
1> Extracted includes paths.
1> CMake generation finished.

JonLiu1993 avatar Nov 22 '23 07:11 JonLiu1993

@JonLiu1993 The problem does not arise when dependencies are simply repeated, but when different components depend on them separately.The VTK_USE_FILE is no longer used starting with 8.90.

project A
-component a
   CMakeLists.txt
-component b
   CMakeLists.txt
CMakeLists.txt

QiuYilin avatar Nov 22 '23 07:11 QiuYilin

@JonLiu1993 The problem does not arise when dependencies are simply repeated, but when different components depend on them separately.The VTK_USE_FILE is no longer used starting with 8.90.

project A
-component a
   CMakeLists.txt
-component b
   CMakeLists.txt
CMakeLists.txt

Could you please provide a simple reproducible example? I need to reproduce this error locally.

JonLiu1993 avatar Nov 22 '23 08:11 JonLiu1993

@JonLiu1993 This is example : wrong example

The actual situation is:

project A
-example
   CMakeLists.txt  (target_link_libraries(example PRIVATE A::a) find_package(VTK))
-component a
   CMakeLists.txt(find_package(VTK))
-component b
   CMakeLists.txt  (find_package(PCL))
CMakeLists.txt

find_package(VTK) in “example” is unnecessary, but it does cause problems.

QiuYilin avatar Nov 24 '23 01:11 QiuYilin

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 28 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

github-actions[bot] avatar Dec 23 '23 01:12 github-actions[bot]

We ran into the same issue where two targets depend on VTK and each calls find_package(VTK).

We could "solve" the issue by deleting FindPEGTL.cmake from the installed VTK package, that is in vcpkg_installed/x64-windows/share/vtk/. After that, VTK can be included multiple times.

(Tested on Windows with CMake 3.28.3, MSVC 17.8.6)

martinfalk avatar Feb 14 '24 12:02 martinfalk

@JonLiu1993 Is there any progress on this issue?

QiuYilin avatar Mar 20 '24 04:03 QiuYilin

@martinfalk, It looks like you have solved the problem, could you submit a PR to vcpkg to fix it? Greatful.

JonLiu1993 avatar Mar 20 '24 07:03 JonLiu1993

I have integrated the fix suggested by @QiuYilin in a PR.

martinfalk avatar Mar 20 '24 09:03 martinfalk

I have integrated the fix suggested by @QiuYilin in a PR.

Thanks for your contribution.

JonLiu1993 avatar Mar 20 '24 09:03 JonLiu1993