Skip to content

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

@jasjuang

Description

@jasjuang

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.

Metadata

Metadata

Assignees

Labels

category:port-bugThe issue is with a library, which is something the port should already support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions