Skip to content

Commit

Permalink
Fix pkg_config_entry when version number is not specified (#374)
Browse files Browse the repository at this point in the history
When `gz_find_package` is called without a VERSION argument, the
`<package>_FIND_VERSION` variable is empty. But in most of our
`Find*.cmake` modules, we add a pkg-config entry that assumes the
version is there.

Example:
```
gz_pkg_config_entry(GzProtobuf "protobuf >= ${GzProtobuf_FIND_VERSION}")
```

The pkg-config entry will then be "protobuf >= ", which is invalid and
causes the following entry to be treated as a version number.

The fix here removes the operator if the version is empty.

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
  • Loading branch information
azeey authored Aug 3, 2023
1 parent 4f5cfdf commit fdcd50e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmake/GzPkgConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,11 @@ macro(ign_pkg_config_entry package string)
gz_pkg_config_entry(${package} ${string})
endmacro()
macro(gz_pkg_config_entry package string)

set(${package}_PKGCONFIG_ENTRY "${string}")
# The input string may contain an operator without a version,
# e.g "protobuf >= ". But this is not valid pkg-config syntax. This regex
# search/replace will remove the operator if the version is empty.
string(REGEX REPLACE " *[<>=]+ *$" "" entry ${string})
set(${package}_PKGCONFIG_ENTRY "${entry}")
set(${package}_PKGCONFIG_TYPE PKGCONFIG_REQUIRES)

endmacro()
Expand Down

0 comments on commit fdcd50e

Please sign in to comment.