removing a bad include from pkg-config package

Library curlpp in it’s pkg-config --cflags has:
-Iinclude -I/usr/include/x86_64-linux-gnu
cmake rejects relative -Iinclude:

CMake Error in src/CMakeLists.txt:                                       
  Target "PkgConfig::CURLPP" contains relative path in its               
  INTERFACE_INCLUDE_DIRECTORIES:                                         
                                                                         
    "include"

I tried to remove all single include and print all the vars but still getting the same error.

How to get rid of -Iinclude?

Minimal project:

project(test)
cmake_minimum_required(VERSION 3.10)

include(FindPkgConfig)
pkg_check_modules(CURLPP REQUIRED IMPORTED_TARGET curlpp)

set(mylibs)

list(APPEND mylibs PkgConfig::CURLPP)

list(REMOVE_ITEM CURLPP_CFLAGS "-Iinclude")
list(REMOVE_ITEM CURLPP_STATIC_INCLUDE_DIRS "-Iinclude")
list(POP_FRONT CURLPP_STATIC_CFLAGS)
list(POP_FRONT CURLPP_STATIC_INCLUDE_DIRS)
list(REMOVE_ITEM CURLPP_INCLUDE_DIRS include)
list(REMOVE_ITEM CURLPP_INCLUDEDIR include)

get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
    message(STATUS "${_variableName}=${${_variableName}}")
endforeach()

add_executable(test test.c)
target_link_libraries(test ${mylibs})

You’ve removed it from the variables, not the target. I would file an issue against curlpp to not generate that flag in the first place (it is very not-well-specified). It’s probably missing ${prefix}/ on there.

Thanks. I raised a ticket to them. However, in the mean time - is there a way to solve my problem?

You can perform the logic on the PkgConfig::CURLPP’s INTERFACE_INCLUDE_DIRECTORIES property instead.

Thanks, this worked:

get_property(__curlpp_includes TARGET PkgConfig::CURLPP PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
list(POP_FRONT __curlpp_includes)
set_property(TARGET PkgConfig::CURLPP PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${__curlpp_includes})


A safer alternative might be to remove the item you expect to be there rather than assuming a particular order as well:

list(REMOVE_ITEM __curlpp_includes include)

Thanks!