Details
Description
We have a CMake config package for our libraries that tries to load Xerces support like so:
find_package(XercesC PATHS "${OPENDDS_XERCES3}" NO_DEFAULT_PATH) if (NOT XercesC_FOUND) find_package(XercesC) endif()
Where OPENDDS_XERCES3 is the path to the Xerces our libraries were built with. This works on Windows and Linux when using system-provided package. When building and installing from source on Linux it seem this doesn't work. In this case it's trying to use the CMake package provided by Xerces instead of the one builtin to CMake.
I've created an example to demonstrate this. Xerces is built and installed to a location on Linux using CMake. Then we create a CMakeLists.txt:
cmake_minimum_required(VERSION 3.12.0)
project(xerces_cmake_config_pkg_test)
find_package(XercesC PATHS "${THE_XERCES_ROOT}" NO_DEFAULT_PATH)
add_executable(testexe test.cpp)
target_link_libraries(testexe XercesC::XercesC)
test.cpp has to be created, but it doesn't matter what it contains because CMake doesn't get far enough to allow us to attempt to build. When configuring, setting THE_XERCES_ROOT to the installed Xerces, CMake gives these errors:
CMake Error at CMakeLists.txt:10 (add_executable): Target "testexe" links to target "ICU::uc" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? CMake Error at CMakeLists.txt:10 (add_executable): Target "testexe" links to target "ICU::data" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? CMake Error at CMakeLists.txt:10 (add_executable): Target "testexe" links to target "Threads::Threads" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
This seems to be caused by the packages being specified by Xerces during its configure (like ICU) being referenced in the Config package, but not being loaded for the using find_package or equivalent. CMake documenation suggests that this should be done in somewhere in the config file.