microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.74k stars 6.29k forks source link

vtk build failure #12906

Open soroush opened 4 years ago

soroush commented 4 years ago

Host Environment

To Reproduce Steps to reproduce the behaviour:

Failure logs

CMake Error at C:/workspace/vcpkg/installed/x64-windows/share/vtk/FindLZ4.cmake:2 (set_target_properties):
  Attempt to promote imported target "lz4::lz4" to global scope (by setting
  IMPORTED_GLOBAL) which is not built in this directory.
Call Stack (most recent call first):
  C:/workspace/vcpkg/scripts/buildsystems/vcpkg.cmake:455 (_find_package)
  C:/workspace/vcpkg/installed/x64-windows/share/vtk/VTK-vtk-module-find-packages.cmake:1196 (find_package)
  C:/workspace/vcpkg/installed/x64-windows/share/vtk/vtk-config.cmake:129 (include)
  C:/workspace/vcpkg/scripts/buildsystems/vcpkg.cmake:455 (_find_package)
  src/CMakeLists.txt:22 (find_package)

Additional context -VTK itself compiles fine, though there are patches that promote its dependencies to the global scope. For example:

set_target_properties(lz4::lz4 PROPERTIES IMPORTED_GLOBAL TRUE)

Which then cause an error in my project.

Neumann-A commented 4 years ago

Instead of

+find_package(LZ4 CONFIG REQUIRED)
+set_target_properties(lz4::lz4 PROPERTIES IMPORTED_GLOBAL TRUE)
+add_library(LZ4::LZ4 ALIAS lz4::lz4)

you could try changing it to:

+find_package(LZ4 CONFIG REQUIRED)
+add_library(LZ4::LZ4 UNKNOWN IMPORTED)
+target_link_libraries(LZ4::LZ4 INTERFACE lz4::lz4)
Neumann-A commented 4 years ago

Also what is your cmake_minimum_required()?

soroush commented 4 years ago

Also what is your cmake_minimum_required()?

It is 3.16.0

Instead of

+find_package(LZ4 CONFIG REQUIRED)
+set_target_properties(lz4::lz4 PROPERTIES IMPORTED_GLOBAL TRUE)
+add_library(LZ4::LZ4 ALIAS lz4::lz4)

you could try changing it to:

+find_package(LZ4 CONFIG REQUIRED)
+add_library(LZ4::LZ4 UNKNOWN IMPORTED)
+target_link_libraries(LZ4::LZ4 INTERFACE lz4::lz4)

Changing the path to what you suggest, vtk itself fails to build:

ninja: error: 'LZ4::LZ4-NOTFOUND', needed by 'bin/vtkIOCore-9.0d.dll', missing and no known rule to make it
Neumann-A commented 4 years ago

try add_library(LZ4::LZ4 INTERFACE IMPORTED) instead of add_library(LZ4::LZ4 UNKNOWN IMPORTED)

so that the patch is:

+find_package(LZ4 CONFIG REQUIRED)
+add_library(LZ4::LZ4 INTERFACE IMPORTED) # maybe also with GLOBAL keyword
+target_link_libraries(LZ4::LZ4 INTERFACE lz4::lz4)
soroush commented 4 years ago

try add_library(LZ4::LZ4 INTERFACE IMPORTED) instead of add_library(LZ4::LZ4 UNKNOWN IMPORTED)

Seems the problem with LZ4 is resolved. I am going to apply the same for other dependencies as well, will report here soon.

soroush commented 4 years ago

Sorry, couldn't figure out what to do with hdf5::hdf5_hl-shared, taocpp::pegtl targets. They differ from LZ4. Quick question: What is it with the uppercase LZ4::LZ4 and the lowercase version?

Neumann-A commented 4 years ago

uppercase LZ4::LZ4 is used by VTK internally while lowercase is the one actually exported by lz4.

You can do the same for hdf5. just need to apply that for hdf5::hdf5 and hdf5::hdf5_hl in all the cases

soroush commented 4 years ago

So, the following change resolved my issues. Thanks

diff --git a/ports/vtk/FindHDF5.cmake b/ports/vtk/FindHDF5.cmake
index bda1a7633..1be15731b 100644
--- a/ports/vtk/FindHDF5.cmake
+++ b/ports/vtk/FindHDF5.cmake
@@ -1,10 +1,8 @@
 #The original VTK file is overdoing it and still prdouces errors that the target hdf5::hdf5_hl-shared cannot be found in dynamic builds
 find_package(hdf5 QUIET NO_MODULE)
 if(TARGET hdf5::hdf5-shared)
-  #set_target_properties(hdf5::hdf5-shared PROPERTIES IMPORTED_GLOBAL TRUE)
-  #add_library(hdf5::hdf5 ALIAS hdf5::hdf5-shared)
-  add_library(hdf5::hdf5 INTERFACE IMPORTED)
-  target_link_libraries(hdf5::hdf5 INTERFACE hdf5::hdf5-shared)
+  set_target_properties(hdf5::hdf5-shared PROPERTIES IMPORTED_GLOBAL TRUE)
+  add_library(hdf5::hdf5 ALIAS hdf5::hdf5-shared)
 elseif(TARGET hdf5::hdf5-static)
   set_target_properties(hdf5::hdf5-static PROPERTIES IMPORTED_GLOBAL TRUE)
   add_library(hdf5::hdf5 ALIAS hdf5::hdf5-static)
@@ -12,10 +10,8 @@ else()
   message(FATAL_ERROR "HDF5 target not found")
 endif()
 if(TARGET hdf5::hdf5_hl-shared)
-  #set_target_properties(hdf5::hdf5_hl-shared PROPERTIES IMPORTED_GLOBAL TRUE)
-  #add_library(hdf5::hdf5_hl ALIAS hdf5::hdf5_hl-shared)
-  add_library(hdf5::hdf5_hl INTERFACE IMPORTED)
-  target_link_libraries(hdf5::hdf5_hl INTERFACE hdf5::hdf5_hl-shared)
+  set_target_properties(hdf5::hdf5_hl-shared PROPERTIES IMPORTED_GLOBAL TRUE)
+  add_library(hdf5::hdf5_hl ALIAS hdf5::hdf5_hl-shared)
 elseif(TARGET hdf5::hdf5_hl-static)
   set_target_properties(hdf5::hdf5_hl-static PROPERTIES IMPORTED_GLOBAL TRUE)
   add_library(hdf5::hdf5_hl ALIAS hdf5::hdf5_hl-static)
diff --git a/ports/vtk/FindLZ4.patch b/ports/vtk/FindLZ4.patch
index a3e0bca54..dced8bf56 100644
--- a/ports/vtk/FindLZ4.patch
+++ b/ports/vtk/FindLZ4.patch
@@ -42,6 +42,6 @@ index 8c94e3bcd..ade3f9451 100644
 -  endif ()
 -endif ()
 +find_package(LZ4 CONFIG REQUIRED)
-+add_library(LZ4::LZ4 INTERFACE IMPORTED)
-+target_link_libraries(LZ4::LZ4 INTERFACE lz4::lz4)
++set_target_properties(lz4::lz4 PROPERTIES IMPORTED_GLOBAL TRUE)
++add_library(LZ4::LZ4 ALIAS lz4::lz4)
 \ No newline at end of file
diff --git a/ports/vtk/pegtl.patch b/ports/vtk/pegtl.patch
index 65e94fefe..6374bb3a8 100644
--- a/ports/vtk/pegtl.patch
+++ b/ports/vtk/pegtl.patch
@@ -15,8 +15,8 @@ index 73eee02f7..22d8bc159 100644
 +find_package(PEGTL CONFIG NAMES PEGTL-2)
 +if(TARGET taocpp::pegtl)
 +    message(STATUS "Searching for PEGTL - found target taocpp::pegtl")
-+    add_library(PEGTL::PEGTL INTERFACE IMPORTED)
-+    target_link_libraries(PEGTL::PEGTL INTERFACE taocpp::pegtl)
++    set_target_properties(taocpp::pegtl PROPERTIES IMPORTED_GLOBAL TRUE)
++    add_library(PEGTL::PEGTL ALIAS taocpp::pegtl)
 +else()
 +    find_path(PEGTL_INCLUDE_DIR
 +      NAMES pegtl/version.hpp
NancyLi1013 commented 4 years ago

@soroush Would you like to submit a pull request to fix this issue?

soroush commented 4 years ago

Sorry, I thought the problem is solved, but then realized that vtk itself does not compile with vcpkg. All these changes require a review.

NancyLi1013 commented 4 years ago

Thanks for your reply @soroush .

@Neumann-A Would you like to help review the changes mentioned above?

Thanks.

soroush commented 3 years ago

This is not fixed yet and it is a major blocker for our project.

I made a simple minimal example of the issue here: https://github.com/soroush/vtk-buildsystem

JackBoosY commented 2 years ago

Is this issue resolved?

soroush commented 2 years ago

Is this issue resolved?

No.

larshg commented 1 year ago

The original error in this one, does not apply anymore on a recent vcpkg version.

However, there is another error thats:

CMake Error at C:/vcpkg/installed/x64-windows/share/hdf5/hdf5-targets.cmake:42 (message): Some (but not all) targets in this export set were already defined.

Targets Defined: hdf5::hdf5-shared, hdf5::hdf5_hl-shared

Targets not yet defined: hdf5::hdf5_cpp-shared, hdf5::hdf5_hl_cpp-shared

Call Stack (most recent call first): C:/vcpkg/installed/x64-windows/share/hdf5/hdf5-config.cmake:148 (include) C:/vcpkg/installed/x64-windows/share/hdf5/vcpkg-cmake-wrapper.cmake:17 (_find_package) C:/vcpkg/scripts/buildsystems/vcpkg.cmake:787 (include) C:/vcpkg/installed/x64-windows/share/vtk/patches/99/FindHDF5.cmake:1 (find_package) C:/vcpkg/installed/x64-windows/share/hdf5/vcpkg-cmake-wrapper.cmake:17 (_find_package) C:/vcpkg/scripts/buildsystems/vcpkg.cmake:787 (include) C:/vcpkg/installed/x64-windows/share/vtk/VTK-vtk-module-find-packages.cmake:303 (find_package) C:/vcpkg/installed/x64-windows/share/vtk/vtk-config.cmake:136 (include) C:/vcpkg/scripts/buildsystems/vcpkg.cmake:833 (_find_package) bar/CMakeLists.txt:6 (find_package)

As find_package(VTK CONFIG REQUIRED) is called in each sub "project.

One can circumvent this, by only having the find_packge in the root CMakelist and then evt. wrap the per sub project find_package in a "if VTK (targets) exists" etc.

roachsinai commented 12 months ago

Get below error when compile ncnn on Windows using VS2019:

-- Searching for PEGTL
-- Searching for PEGTL - found target taocpp::pegtl
CMake Error at E:/vcpkg/installed/x64-windows/share/vtk/FindPEGTL.cmake:26 (set_target_properties):
  Attempt to promote imported target "taocpp::pegtl" to global scope (by
  setting IMPORTED_GLOBAL) which is not built in this directory.
Call Stack (most recent call first):
  E:/vcpkg/scripts/buildsystems/vcpkg.cmake:852 (_find_package)
  E:/vcpkg/installed/x64-windows/share/vtk/VTK-vtk-module-find-packages.cmake:585 (find_package)
  E:/vcpkg/installed/x64-windows/share/vtk/vtk-config.cmake:150 (include)
  E:/vcpkg/scripts/buildsystems/vcpkg.cmake:852 (_find_package)
  C:/Program Files/CMake/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  E:/vcpkg/installed/x64-windows/share/opencv4/OpenCVModules.cmake:40 (find_dependency)
  E:/vcpkg/installed/x64-windows/share/opencv4/OpenCVConfig.cmake:126 (include)
  E:/vcpkg/scripts/buildsystems/vcpkg.cmake:852 (_find_package)
  tools/quantize/CMakeLists.txt:4 (find_package)

vcpkg version: 2023-04-07-bedcba5172f5e4b91caac660ab7afe92c27a9895

Any suggestion will be appreciated!