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
25 stars 30 forks source link

IGNITION_CMAKE_VERSION_MAJOR changes after finding packages that use newer version of ign-cmake #61

Open osrf-migration opened 5 years ago

osrf-migration commented 5 years ago

Original report (archived issue) by Brian Marchi (Bitbucket: BEMarchi).

The original report had attachments: CMakeLists.txt, example.cc


Prerequisites

* [X] Put an X between the brackets on this line if you have done all of the following:
* Checked the QA board for common solutions: http://answers.gazebosim.org
* Checked that your issue isn't already filed.
* Checked that there is not already an Ignition package that provides the described functionality: https://ignitionrobotics.org/libs

Description

When trying to use a package that links against cmake2 and another one that links against cmake1, I get the following:

CMake Error at CMakeLists.txt:13 (add_library):
Target example links to target ignition-cmake1::utilities; but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?

Steps to Reproduce

1. Clone ign-cmake1
2. Clone ign-cmake2
3. Clone ign-common3
4. Clone ign-math6
5. Clone ign-msgs2 branch https://osrf-migration.github.io/ignition-gh-pages/#!/ignitionrobotics/ign-msgs/pull-requests/138/use-math6
6. Clone ign-transport5
7. Create a project with a CMakeLists.txt like this:

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(example_project LANGUAGES C CXX VERSION 3.0.0)
find_package(ignition-common3 REQUIRED COMPONENTS graphics)
find_package(ignition-math6 REQUIRED)
find_package(ignition-msgs2 REQUIRED)
find_package(ignition-transport5 REQUIRED COMPONENTS log)

add_library(example
  example.cc)
target_link_libraries(example
    ignition-common3::ignition-common3
    ignition-transport5::core
    ignition-transport5::log
    ignition-msgs2::ignition-msgs2)
install(TARGETS example
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

8. Create an empty example.cc file living in the same dir as the above CMakeLists.txt

9. Build and install all projects

Expected behavior:

Library example should build normally

Actual behavior:

Library example doesn’t build

Reproduces how often:

Always

Versions

ign-cmake2, ign-cmake1, ign-transport5, ign-msgs2 branch msgs2_use_math6, ign-common3.
OS: Ubuntu 18.04

osrf-migration commented 5 years ago

Original comment by Brian Marchi (Bitbucket: BEMarchi).


osrf-migration commented 5 years ago

Original comment by Brian Marchi (Bitbucket: BEMarchi).


osrf-migration commented 5 years ago

Original comment by Steve Peters (Bitbucket: Steven Peters, GitHub: scpeters).


are you cloning ign-cmake into separate folders? For example, the following repos file does this with separate folder names:

osrf-migration commented 5 years ago

Original comment by Steve Peters (Bitbucket: Steven Peters, GitHub: scpeters).


I'll try to reproduce this error

osrf-migration commented 5 years ago

Original comment by John Shepherd (Bitbucket: John Shepherd, GitHub: jshep1).


I've followed your steps to reproduce the error only needing to also install ign-tools, and ign-msgs2 builds; however, I get similar but different error messages upon ign-transport5 being built:

CMake Error at /root/ws/install/ignition-cmake1/share/cmake/ignition-cmake1/cmake1/IgnUtils.cmake:1554 (add_executable):
  Target "UNIT_TopicStorage_TEST" links to target "ignition-math6::requested"
  but the target was not found.  Perhaps a find_package() call is missing for
  an IMPORTED target, or an ALIAS target is missing?
osrf-migration commented 5 years ago

Original comment by John Shepherd (Bitbucket: John Shepherd, GitHub: jshep1).


@scpeters

root@67a4c36dc81e:/app/ws# vcs export
repositories:
  src/ign-cmake1:
    type: hg
    url: https://jshep1@bitbucket.org/ignitionrobotics/ign-cmake
    version: ign-cmake1
  src/ign-cmake2:
    type: hg
    url: https://jshep1@bitbucket.org/ignitionrobotics/ign-cmake
    version: ign-cmake2
  src/ign-common:
    type: hg
    url: https://jshep1@bitbucket.org/ignitionrobotics/ign-common
    version: ign-common3
  src/ign-math:
    type: hg
    url: https://jshep1@bitbucket.org/ignitionrobotics/ign-math
    version: ign-math6
  src/ign-msgs:
    type: hg
    url: https://jshep1@bitbucket.org/ignitionrobotics/ign-msgs
    version: msgs2_use_math6
  src/ign-transport:
    type: hg
    url: https://jshep1@bitbucket.org/ignitionrobotics/ign-transport
    version: ign-transport5
osrf-migration commented 5 years ago

Original comment by Brian Marchi (Bitbucket: BEMarchi).


@scpeters , yes, you need to have one directory for each ign-cmake version.
About ign-tools, I didn't need it. I saw the warning when building ign-msgs and ign-transport but I just ignore it. I installed every package as the README says in every ignition repository. I will specify that in the issue.

osrf-migration commented 5 years ago

Original comment by Brian Marchi (Bitbucket: BEMarchi).


osrf-migration commented 5 years ago

Original comment by Steve Peters (Bitbucket: Steven Peters, GitHub: scpeters).


thanks for reporting this

I think the issue is caused by a change in the ign-msgs pull request that searches for ignition-math6 without REQUIRED, which keeps that dependency from being properly exported. I've updated the pull request in the following commit, which I think fixes the problem.

osrf-migration commented 5 years ago

Original comment by Steve Peters (Bitbucket: Steven Peters, GitHub: scpeters).


actually, that just fixes the problem that John noticed

I still see the issue with ignition-cmake1::utilities

osrf-migration commented 5 years ago

Original comment by Steve Peters (Bitbucket: Steven Peters, GitHub: scpeters).


I can reproduce the issue with this workspace:

repositories:
  ign-cmake1:
    type: hg
    url: #!/ignitionrobotics/ign-cmake
    version: 3bc7304a06fd3c569bd653db5dd8702375a48774
  ign-cmake2:
    type: hg
    url: #!/ignitionrobotics/ign-cmake
    version: f23390ce62cce6033412e8b52735de9bc868ebe9
  ign-common:
    type: hg
    url: #!/ignitionrobotics/ign-common
    version: ignitionrobotics/ign-common@fa15e9eb736e54b8ab1a082df3f2155ef9a5e42c
  ign-math:
    type: hg
    url: #!/ignitionrobotics/ign-math
    version: ignitionrobotics/ign-math@05a3a56d85b91833bd6a0ee1b1b082040216a8f6
  ign-msgs:
    type: hg
    url: #!/ignitionrobotics/ign-msgs
    version: ignitionrobotics/ign-msgs@4683ad50e9a548b7cf4ba7c5b590d86c67e4ce51
  ign-transport:
    type: hg
    url: #!/ignitionrobotics/ign-transport
    version: ignitionrobotics/ign-transport@01bd624bb65f816ea07f5f32db8d2083ca5a8a1b

I believe it happens in this example because ign-transport's core library exports a dependency on ignition-cmake1::utilities, but since it depends on a version of ign-msgs2 that uses ignition-math6 and ignition-cmake2, something gets a bit mixed up. When I grep for ignition-cmake in the installed cmake config files, I see ignition-cmake1::utilities in ignition-transport5-targets.cmake and find_dependency(ignition-cmake2) in ignition-transport5-config.cmake.

ignition-transport5-targets.cmake:59:  INTERFACE_LINK_LIBRARIES "ignition-cmake1::utilities;ignition-msgs2::ignition-msgs2;UUID::UUID"
ignition-transport5-config.cmake:61:# Find ignition-cmake, because we need its modules in order to find the rest of
ignition-transport5-config.cmake:63:find_dependency(ignition-cmake2)

The IGNITION_CMAKE_VERSION_MAJOR is 1 when find_package(ignition-cmake1) is first called, but it changes to 2 after ign_find_package(ignition-msgs2).

osrf-migration commented 5 years ago

Original comment by Steve Peters (Bitbucket: Steven Peters, GitHub: scpeters).


It looks like the IGNITION_CMAKE_VERSION_MAJOR variable is increased when finding a newer version of ignition-cmake:

The problem, which wasn't noticed until now, is that the cmake config files that get generated for a package like ignition-transport5 will be generated to use the newer ign-cmake version.

osrf-migration commented 5 years ago

Original comment by Steve Peters (Bitbucket: Steven Peters, GitHub: scpeters).


This causes a package that ostensibly uses ignition-cmake1 to export a dependency on ignition-cmake2 in its cmake config files if it uses anything that depends on ignition-cmake2, as the example of ign-transport5 with that ign-msgs branch shows.