Skip to content

Commit 08360a8

Browse files
committed
Unset blank cache variables, because they can harmfully collide with other parts of a build system
1 parent d47f9e0 commit 08360a8

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

cmake/IgnPkgConfig.cmake

+21-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,26 @@ macro(ign_pkg_check_modules_quiet package signature)
114114
# here.
115115
if(${package}_FOUND AND NOT TARGET ${ign_pkg_check_modules_TARGET_NAME})
116116

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+
117137
# pkg_check_modules will put ${package}_FOUND into the CACHE, which would
118138
# prevent our FindXXX.cmake script from being entered the next time cmake
119139
# 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)
124144
# problem. Perhaps the cmake-3.6 version of pkg_check_modules has a
125145
# better solution.
126146
unset(${package}_FOUND CACHE)
127-
set(${package}_FOUND true)
147+
set(${package}_FOUND TRUE)
128148

129149
# For some reason, pkg_check_modules does not provide complete paths to the
130150
# libraries it returns, even though find_package is conventionally supposed

0 commit comments

Comments
 (0)