Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find_package(VTK) causes IMPORTED_LOCATION not set for imported target "EXPAT::EXPAT" error in x64-linux #20237

Closed
jasjuang opened this issue Sep 18, 2021 · 7 comments · Fixed by #20356
Assignees
Labels
category:port-bug The issue is with a library, which is something the port should already support

Comments

@jasjuang
Copy link
Contributor

Environment

  • OS: Ubuntu 20.04
  • Compiler: gcc 9.3.0

To Reproduce
Please see below CMakeLists.txt to reproduce the error

set(CMAKE_TOOLCHAIN_FILE $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)

cmake_minimum_required(VERSION 3.20)

project(example)

find_package(VTK)

add_executable(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/main.cpp)

target_link_libraries(${PROJECT_NAME} ${VTK_LIBRARIES})

In x64-linux, a simple mkdir build && cd build && cmake .. shows the below error

-- Searching for PEGTL
-- Searching for PEGTL - found target taocpp::pegtl
-- Found LibXml2: /home/jasjuang/vcpkg/installed/x64-linux/lib/libxml2.a (found version "2.9.12") 
-- Configuring done
CMake Error in CMakeLists.txt:
  IMPORTED_LOCATION not set for imported target "EXPAT::EXPAT".


-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

After some debugging, I realized that if I insert set(CMAKE_BUILD_TYPE "Release") the error will go away, e.g.

set(CMAKE_TOOLCHAIN_FILE $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)

cmake_minimum_required(VERSION 3.20)

project(example)

set(CMAKE_BUILD_TYPE "Release")

find_package(VTK)

add_executable(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/main.cpp)

target_link_libraries(${PROJECT_NAME} ${VTK_LIBRARIES})

However, cmake config should not fail even if CMAKE_BUILD_TYPE is not set. Would appreciate if someone can fix this.

@JackBoosY JackBoosY self-assigned this Sep 18, 2021
@JackBoosY JackBoosY added the category:port-bug The issue is with a library, which is something the port should already support label Sep 18, 2021
@dg0yt
Copy link
Contributor

dg0yt commented Sep 24, 2021

VTK comes with its own FindEXPAT.cmake. And vcpkg comes with a patch for it. There is one suspicious spot in that patch:

+ if(EXPAT_LIBRARY_RELEASE)
+ vtk_detect_library_type(expat_library_type
+ PATH "${EXPAT_LIBRARY_RELEASE}")
+ elseif(EXPAT_LIBRARY_DEBUG)
+ vtk_detect_library_type(expat_library_type
+ PATH "${EXPAT_LIBRARY_RELEASE}")

In the last line, what was meant is probably EXPAT_LIBRARY_DEBUG. EXPAT_LIBRARY_RELEASE is known to resolve to false at this point.

@JackBoosY JackBoosY added the requires:repro The issue is not currently repro-able label Sep 26, 2021
@JackBoosY
Copy link
Contributor

JackBoosY commented Sep 26, 2021

But I can't repro it:

cmake_minimum_required(VERSION 3.10)

project(sample)
find_package(VTK REQUIRED)
add_executable(sample test.cpp)
target_link_libraries(sample PRIVATE ${VTK_LIBRARIES})
root@usrUb:/home/usr/work/test# ./../vcpkg/downloads/tools/cmake-3.20.2-linux/cmake-3.20.2-linux-x86_64/bin/cmake CMakeLists.txt  -DCMAKE_TOOLCHAIN_FILE=/home/usr/work/20237/vcpkg/scripts/buildsystems/vcpkg.cmake
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
CMake Warning (dev) at /home/usr/work/20237/vcpkg/installed/x64-linux/share/zlib/vcpkg-cmake-wrapper.cmake:13 (_find_package):
  Policy CMP0074 is not set: find_package uses <PackageName>_ROOT variables.
  Run "cmake --help-policy CMP0074" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  CMake variable ZLIB_ROOT is set to:

    /home/usr/work/20237/vcpkg/installed/x64-linux

  For compatibility, CMake is ignoring the variable.
Call Stack (most recent call first):
  /home/usr/work/20237/vcpkg/scripts/buildsystems/vcpkg.cmake:740 (include)
  /home/usr/work/20237/vcpkg/installed/x64-linux/share/freetype/vcpkg-cmake-wrapper.cmake:4 (find_package)
  /home/usr/work/20237/vcpkg/scripts/buildsystems/vcpkg.cmake:740 (include)
  /home/usr/work/20237/vcpkg/installed/x64-linux/share/vtk/patches/99/FindX11.cmake:207 (find_package)
  /home/usr/work/20237/vcpkg/scripts/buildsystems/vcpkg.cmake:786 (_find_package)
  /home/usr/work/20237/vcpkg/installed/x64-linux/share/vtk/VTK-vtk-module-find-packages.cmake:162 (find_package)
  /home/usr/work/20237/vcpkg/installed/x64-linux/share/vtk/vtk-config.cmake:136 (include)
  /home/usr/work/20237/vcpkg/scripts/buildsystems/vcpkg.cmake:786 (_find_package)
  CMakeLists.txt:5 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found ZLIB: /home/usr/work/20237/vcpkg/installed/x64-linux/lib/libz.a (found version "1.2.11")
-- Found BZip2: /home/usr/work/20237/vcpkg/installed/x64-linux/lib/libbz2.a (found version "1.0.8")
-- Looking for BZ2_bzCompressInit
-- Looking for BZ2_bzCompressInit - found
-- Found PNG: /home/usr/work/20237/vcpkg/installed/x64-linux/debug/lib/libpng.a (found version "1.6.37")
-- Found X11: /usr/include
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so  found components: OpenGL GLX
-- Found OGG: /home/usr/work/20237/vcpkg/installed/x64-linux/debug/lib/libogg.a
-- Found THEORA: /home/usr/work/20237/vcpkg/installed/x64-linux/debug/lib/libtheora.a
-- Found NetCDF: /home/usr/work/20237/vcpkg/installed/x64-linux/include (found version "4.7.4")
-- Searching for PEGTL
-- Searching for PEGTL - found target taocpp::pegtl
-- Found JsonCpp: /home/usr/work/20237/vcpkg/installed/x64-linux/debug/lib/libjsoncpp.a (found suitable version "1.9.3", minimum required is "0.7.0")
-- Found LibXml2: /home/usr/work/20237/vcpkg/installed/x64-linux/debug/lib/libxml2.a (found version "2.9.12")
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Performing Test Iconv_IS_BUILT_IN
-- Performing Test Iconv_IS_BUILT_IN - Success
-- Found Iconv: /usr/lib/x86_64-linux-gnu/libc.so
-- Found LibHaru: /home/usr/work/20237/vcpkg/installed/x64-linux/lib/libhpdf.a (found suitable version "2.4.0-dev", minimum required is "2.4.0")
-- Found SQLite3: /home/usr/work/20237/vcpkg/installed/x64-linux/include (found version "3.36.0")
-- Found LibPROJ: /home/usr/work/20237/vcpkg/installed/x64-linux/debug/lib/libproj.a (found version "7.2.1")
-- Found Eigen3: /home/usr/work/20237/vcpkg/installed/x64-linux/include/eigen3 (found version "3.3.9")
-- Found EXPAT: /home/usr/work/20237/vcpkg/installed/x64-linux/lib/libexpat.a (found version "2.4.1")
-- Found double-conversion: /home/usr/work/20237/vcpkg/installed/x64-linux/debug/lib/libdouble-conversion.a
-- Found LZMA: /home/usr/work/20237/vcpkg/installed/x64-linux/lib/liblzma.a (found version "5.2.5")
-- Found utf8cpp: /home/usr/work/20237/vcpkg/installed/x64-linux/include/utf8cpp
-- Found JPEG: /home/usr/work/20237/vcpkg/installed/x64-linux/lib/libjpeg.a (found version "62")
-- Found TIFF: /home/usr/work/20237/vcpkg/installed/x64-linux/lib/libtiff.a (found version "4.3.0")
-- Found Freetype: /home/usr/work/20237/vcpkg/installed/x64-linux/lib/libfreetype.a (found version "2.11.0")
-- Configuring done
CMake Warning (dev) in CMakeLists.txt:
  Policy CMP0111 is not set: An imported target missing its location property
  fails during generation.  Run "cmake --help-policy CMP0111" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  IMPORTED_LOCATION not set for imported target "EXPAT::EXPAT".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done
-- Build files have been written to: /home/usr/work/test
root@usrUb:/home/usr/work/test# make
CMakeFiles/sample.dir/build.make:247: *** target pattern contains no '%'.  Stop.
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/sample.dir/all' failed
make[1]: *** [CMakeFiles/sample.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2

Oh, it's a warning message in my side.

@JackBoosY JackBoosY removed the requires:repro The issue is not currently repro-able label Sep 26, 2021
@JackBoosY
Copy link
Contributor

Okay, the related issues are #19035 #9947.
I wish to fix them completely.

@dg0yt
Copy link
Contributor

dg0yt commented Sep 26, 2021

The expat wrapper sets IMPORTED_LOCATION_RELEASE and IMPORTED_LOCATION_DEBUG, but not IMPORTED_LOCATION.

Policy CMP0111 is not set

This policy is set as soon as you use cmake_minimum_required(3.19) or higher, and then it will become an error to not have an IMPORTED_LOCATION... matching the CMAKE_BUILD_TYPE. All ports in vcpkg build with either Release or Debug type. But user projects may leave CMAKE_BUILD_TYPE uninitialized. This is what is reported here.
(AFAICT there are some other quirks when you don't set CMAKE_BUILD_TYPE.)

@JackBoosY
Copy link
Contributor

In installed/x64-linux/share/vtk/VTK-vtk-module-find-packages.cmake:
find_package(EXPAT
VTK will call the installed FindEXPAT.cmake first.

Remove the internal FindEXPAT.cmake can fix this issue.

@dg0yt
Copy link
Contributor

dg0yt commented Sep 26, 2021

VTK will call the installed FindEXPAT.cmake first.

But even then, vcpkg will use the expat wrapper.

@JackBoosY
Copy link
Contributor

@dg0yt vtk will use them both: call vcpkg-cmake-wrapper in share/expat first, then call FindEXPAT.cmake in share/vtk at last.
That because:

_find_package(${ARGS})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:port-bug The issue is with a library, which is something the port should already support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants