gazebosim / gz-cmake

A set of CMake modules that are used by the C++-based Gazebo projects.
https://gazebosim.org/libs/cmake
Apache License 2.0
22 stars 28 forks source link

Error evaluating generator expression: $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES> Target "protobuf::libprotobuf" not found. #60

Open osrf-migration opened 5 years ago

osrf-migration commented 5 years ago

Original report (archived issue) by Alex Biddulph (Bitbucket: Bidski).


I am having a very similar issue to Issue#55 (#55).

I am building a program using cmake (not using catkin) that depends on ignition-transport4. When creating my library and listing ${IGNITION-TRANSPORT_LIBRARIES} as target link libraries I get

CMake Error:
  Error evaluating generator expression:

    $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES>

  Target "protobuf::libprotobuf" not found.

appearing about 10 times while cmake is creating the build files.

I have tried adding

find_package(ignition-math4 REQUIRED)
find_package(ignition-cmake0 REQUIRED)
find_package(IgnProtobuf REQUIRED)

both before and after my call to find_package(ignition-transport4 REQUIRED) but to no avail.

My guess is that the rest of my program also has a dependency on protobuf (included at the top-level directory) and that this is somehow clashing with FindIgnProtobuf.cmake in a strange way. Unfortunately, I can't figure out how to test this theory properly.

How can I resolve this?

osrf-migration commented 5 years ago

Original comment by Michael Grey (Bitbucket: mxgrey, GitHub: mxgrey).


Does this happen even with a totally fresh configuration of cmake? The first thing I’d recommend is to delete your entire build folder and try to configuring cmake freshly. This kind of error is most common when the CMakeCache.txt is in a confused state.

In theory there shouldn't be a reason that multiple uses of Protobuf should cause this error. If this error always happens, even with a fresh configuration, then maybe the FindIgnProtobuf.cmake script can be patched somehow to deal with it.

osrf-migration commented 5 years ago

Original comment by Alex Biddulph (Bitbucket: Bidski).


This error always happens, even with a fresh configuration.

osrf-migration commented 5 years ago

Original comment by Michael Grey (Bitbucket: mxgrey, GitHub: mxgrey).


What version of protobuf does the rest of your project depend on?

osrf-migration commented 5 years ago

Original comment by Alex Biddulph (Bitbucket: Bidski).


3.5.0, but I may be updating it to the latest (or a newer version) soon.

osrf-migration commented 5 years ago

Original comment by Michael Grey (Bitbucket: mxgrey, GitHub: mxgrey).


Thanks, a few more questions:

osrf-migration commented 5 years ago

Original comment by Alex Biddulph (Bitbucket: Bidski).


Currently running 16.04.
Protobuf is compiled from source
CMake 3.5

osrf-migration commented 5 years ago

Original comment by Michael Grey (Bitbucket: mxgrey, GitHub: mxgrey).


Thanks for the info!

Could you try out the change in this pull request?

osrf-migration commented 5 years ago

Original comment by Alex Biddulph (Bitbucket: Bidski).


No change

osrf-migration commented 5 years ago

Original comment by Michael Grey (Bitbucket: mxgrey, GitHub: mxgrey).


I've run out of theories for why it wouldn't be working. To help debug you could try adding this to your CMakeLists.txt:

message("PROTOBUF_FOUND Before:${PROTOBUF_FOUND}")
message("Protobuf_FOUND Before:${Protobuf_FOUND}")
find_package(IgnProtobuf REQUIRED)
message("PROTOBUF_FOUND After:${PROTOBUF_FOUND}")
message("Protobuf_FOUND After:${Protobuf_FOUND}")

I don’t know if that will tell me anything helpful, but it’s the next thing I would look at if I needed to debug this.

If you're able to share your project's CMakeLists.txt structure with us, that might be insightful. Otherwise, I don’t know what would be causing this.

osrf-migration commented 5 years ago

Original comment by Alex Biddulph (Bitbucket: Bidski).


I added the following before find_package(ignition-transport4 REQUIRED)

FIND_PACKAGE(ignition-cmake0 REQUIRED)

message("PROTOBUF_FOUND Before:${PROTOBUF_FOUND}")
message("Protobuf_FOUND Before:${Protobuf_FOUND}")
find_package(IgnProtobuf REQUIRED)
message("PROTOBUF_FOUND After:${PROTOBUF_FOUND}")
message("Protobuf_FOUND After:${Protobuf_FOUND}"

Results are:

PROTOBUF_FOUND Before:TRUE
Protobuf_FOUND Before:TRUE
PROTOBUF_FOUND After:TRUE
Protobuf_FOUND After:0

My projects CMakeLists.txt is available on github. It’s not a simple structure though and cutting it down to a MWE is a non-trivial matter, so I am not sure how much help it would be. The module where we are finding ignition-transport4 is here. The point where we find protobuf is in the top-level file, via this module.

I can confirm that there is some sort of clash between the two detections of protobuf. If I edit this file to first find ignition-cmake0 and then IgnProtobuf (instead of finding Protobuf), everything works as expected. Not sure what could be happening though. (I need to revert your suggested PR to make this work though).

osrf-migration commented 4 years ago

Original comment by Alex Biddulph (Bitbucket: Bidski).


Is there any update on this?

osrf-migration commented 4 years ago

Original comment by Michael Grey (Bitbucket: mxgrey, GitHub: mxgrey).


Honestly I’ve run out of theories on what could be causing this.

I think I’d have to have a trace of the cmake run history to have any hope of making sense of this behavior.

You could add the --trace flag to your invocation of cmake and then dump the output into a gist. I don’t know if I’ll be able to make sense out of it, but I can try looking it over when I have time.

osrf-migration commented 4 years ago

Original comment by Alex Biddulph (Bitbucket: Bidski).


CMake Trace output
I hope this helps, I tried to limit the output as much as I could, but trace outputs a lot of information :disappointed: