@@ -114,6 +114,26 @@ macro(ign_pkg_check_modules_quiet package signature)
114
114
# here.
115
115
if (${package} _FOUND AND NOT TARGET ${ign_pkg_check_modules_TARGET_NAME} )
116
116
117
+ # Because of some idiosyncrasies of pkg-config, pkg_check_modules does not
118
+ # put /usr/include in the <prefix>_INCLUDE_DIRS variable. E.g. try running
119
+ # $ pkg-config --cflags-only-I tinyxml2
120
+ # and you'll find that it comes out blank. This blank value gets cached
121
+ # into the <prefix>_INCLUDE_DIRS variable even though it's a bad value. If
122
+ # other packages then try to call find_path(<prefix>_INCLUDE_DIRS ...) in
123
+ # their own find-module or config-files, the find_path will quit early
124
+ # because a CACHE entry exists for <prefix>_INCLUDE_DIRS. However, that
125
+ # CACHE entry is blank, and so it will typically be interpreted as a
126
+ # failed attempt to find the path. So if this <prefix>_INCLUDE_DIRS
127
+ # variable is blank, then we'll unset it from the CACHE to avoid
128
+ # conflicts and confusion.
129
+ #
130
+ # TODO(MXG): Consider giving a different prefix (e.g. IGN_PC_${package})
131
+ # to pkg_check_modules(~) so that the cached variables don't collide. That
132
+ # would also help with the next TODO below.
133
+ if (NOT ${package} _INCLUDE_DIRS)
134
+ unset (${package} _INCLUDE_DIRS CACHE )
135
+ endif ()
136
+
117
137
# pkg_check_modules will put ${package}_FOUND into the CACHE, which would
118
138
# prevent our FindXXX.cmake script from being entered the next time cmake
119
139
# is run by a dependent project. This is a problem for us because we
@@ -124,7 +144,7 @@ macro(ign_pkg_check_modules_quiet package signature)
124
144
# problem. Perhaps the cmake-3.6 version of pkg_check_modules has a
125
145
# better solution.
126
146
unset (${package} _FOUND CACHE )
127
- set (${package} _FOUND true )
147
+ set (${package} _FOUND TRUE )
128
148
129
149
# For some reason, pkg_check_modules does not provide complete paths to the
130
150
# libraries it returns, even though find_package is conventionally supposed
0 commit comments