CPMFindPackage() unable to import namespaced targets
jonasbhjulstad opened this issue · comments
I fetch a package from Git:
CPMFindPackage(NAME Pixman
GITHUB_REPOSITORY jonasbhjulstad/pixman-CMake
GIT_TAG master
)
With the following exported PixmanConfig.cmake (found in Pixman_BINARY_DIR):
include(CMakeFindDependencyMacro)
include(${CMAKE_CURRENT_LIST_DIR}/PixmanTargets.cmake)
add_library(Pixman::Pixman STATIC IMPORTED)
And the following PixmanTargets.cmake (found in Pixman_BINARY_DIR):
# Generated by CMake
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.8)
message(FATAL_ERROR "CMake >= 2.8.0 required")
endif()
if(CMAKE_VERSION VERSION_LESS "2.8.3")
message(FATAL_ERROR "CMake >= 2.8.3 required")
endif()
cmake_policy(PUSH)
cmake_policy(VERSION 2.8.3...3.23)
#----------------------------------------------------------------
# Generated CMake target import file.
#----------------------------------------------------------------
# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)
# Protect against multiple inclusion, which would fail when already imported targets are added once more.
set(_cmake_targets_defined "")
set(_cmake_targets_not_defined "")
set(_cmake_expected_targets "")
foreach(_cmake_expected_target IN ITEMS Pixman::Pixman)
list(APPEND _cmake_expected_targets "${_cmake_expected_target}")
if(TARGET "${_cmake_expected_target}")
list(APPEND _cmake_targets_defined "${_cmake_expected_target}")
else()
list(APPEND _cmake_targets_not_defined "${_cmake_expected_target}")
endif()
endforeach()
unset(_cmake_expected_target)
if(_cmake_targets_defined STREQUAL _cmake_expected_targets)
unset(_cmake_targets_defined)
unset(_cmake_targets_not_defined)
unset(_cmake_expected_targets)
unset(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)
return()
endif()
if(NOT _cmake_targets_defined STREQUAL "")
string(REPLACE ";" ", " _cmake_targets_defined_text "${_cmake_targets_defined}")
string(REPLACE ";" ", " _cmake_targets_not_defined_text "${_cmake_targets_not_defined}")
message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_cmake_targets_defined_text}\nTargets not yet defined: ${_cmake_targets_not_defined_text}\n")
endif()
unset(_cmake_targets_defined)
unset(_cmake_targets_not_defined)
unset(_cmake_expected_targets)
# Create imported target Pixman::Pixman
add_library(Pixman::Pixman STATIC IMPORTED)
set_target_properties(Pixman::Pixman PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "/home/man/cairo-cmake/build/_deps/pixman_repo-build/pixman;/home/man/cairo-cmake/build/_deps/pixman_repo-src/pixman"
)
# Import target "Pixman::Pixman" for configuration ""
set_property(TARGET Pixman::Pixman APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG)
set_target_properties(Pixman::Pixman PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_NOCONFIG "C"
IMPORTED_LOCATION_NOCONFIG "/home/man/cairo-cmake/build/_deps/pixman_repo-build/pixman/libPixman.a"
)
# This file does not depend on other imported targets which have
# been exported from the same project but in a separate export set.
# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)
When I try to `target_link_libraries( Pixman::Pixman) the target is not found:
CMake Error at src/CMakeLists.txt:648 (target_link_libraries):
Target "<target>" links to:
Pixman::Pixman
IMHO: It seems that the PixmanConfig.cmake
is wrong?
CMake Error at stagedir/lib/cmake/Pixman/PixmanConfig.cmake:4 (add_library):
add_library cannot create imported target "Pixman::Pixman" because another
target with the same name already exists.
Call Stack (most recent call first):
cmake/CPM.cmake:243 (find_package)
cmake/CPM.cmake:652 (cpm_find_package)
CMakeLists.txt:48 (CPMAddPackage)
This is not a CPM.cmake
problem!
Also it is not usable with CPM.cmake
:
bash-3.2$ git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4392ff9..000254b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -45,6 +45,11 @@ include(cmake/options.cmake)
# PackageProject.cmake will be used to make our target installable
CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.10.0")
+CPMAddPackage(NAME Pixman
+ GITHUB_REPOSITORY jonasbhjulstad/pixman-CMake
+ GIT_TAG master
+)
+
# NOTE: The fmt library must be installed if not found! BUT either clang-tidy checks nor compiler
# warnings are wanted!
@@ -103,7 +108,7 @@ target_compile_options(${PROJECT_NAME} PRIVATE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) # mimimum requierd for package user
# Link dependencies
-target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt)
+target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt Pixman::Pixman)
# target_include_directories with the SYSTEM modifier will request the compiler to omit warnings
# from the provided paths, if the compiler supports that
@@ -132,7 +137,7 @@ packageProject(
INCLUDE_DESTINATION include/${PROJECT_NAME}
VERSION_HEADER ${VERSION_HEADER_LOCATION} DISABLE_VERSION_SUFFIX YES
COMPATIBILITY SameMajorVersion
- DEPENDENCIES "fmt 9.1.0"
+ DEPENDENCIES "fmt 9.1.0; Pixman"
)
include(CPack)
bash-3.2$
-- Configuring done
CMake Error at CMakeLists.txt:111 (target_link_libraries):
Target "greeter" links to:
Pixman::Pixman
but the target was not found. Possible reasons include:
* There is a typo in the target name.
* A find_package call is missing for an IMPORTED target.
* An ALIAS target is missing.
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
make: *** [install] Error 1
bash-3.2$
PixmanConfig.cmake
is the issue, sorry for the inconvenience.