Skip to content

Commit 851fac5

Browse files
committed
Handle directory contents that change (without the directory changing) better
1 parent 2b895ab commit 851fac5

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

cmake/FindJsonCpp.cmake

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,39 @@ set(JSONCPP_FOUND FALSE)
6363
# and we need to call it at least once every CMake invocation to create the original
6464
# imported targets, since those don't stick around like cache variables.
6565
find_package(jsoncpp QUIET NO_MODULE)
66-
#message("Searching for config file result: jsoncpp_FOUND ${jsoncpp_FOUND}")
67-
68-
if(jsoncpp_FOUND AND NOT "[${jsoncpp_DIR}]" STREQUAL "${JSONCPP_CACHED_JSONCPP_DIR_DETAILS}")
69-
# If we found something, and it's not the exact same as what we've found before...
70-
# NOTE: The contents of this "if" block update only (internal) cache variables!
71-
# (since this will only get run the first CMake pass that finds jsoncpp or that finds a different install)
72-
#message("Updating jsoncpp cache variables!")
73-
set(JSONCPP_CACHED_JSONCPP_DIR_DETAILS "[${jsoncpp_DIR}]" CACHE INTERNAL "" FORCE)
66+
67+
if(jsoncpp_FOUND)
68+
# Build a string to help us figure out when to invalidate our cache variables.
69+
# start with where we found jsoncpp
70+
set(__jsoncpp_info_string "[${jsoncpp_DIR}]")
71+
72+
# part of the string to indicate if we found a real jsoncpp_lib (and what kind)
73+
_jsoncpp_check_for_real_jsoncpplib()
74+
if(__jsoncpp_have_jsoncpplib)
75+
list(APPEND __jsoncpp_info_string "[${__jsoncpp_lib_type}]")
76+
else()
77+
list(APPEND __jsoncpp_info_string "[]")
78+
endif()
79+
# part of the string to indicate if we found jsoncpp_lib_static
80+
if(TARGET jsoncpp_lib_static)
81+
list(APPEND __jsoncpp_info_string "[T]")
82+
else()
83+
list(APPEND __jsoncpp_info_string "[]")
84+
endif()
85+
endif()
86+
87+
88+
# If we found something, and it's not the exact same as what we've found before...
89+
# NOTE: The contents of this "if" block update only (internal) cache variables!
90+
# (since this will only get run the first CMake pass that finds jsoncpp or that finds a different/updated install)
91+
if(jsoncpp_FOUND AND NOT __jsoncpp_info_string STREQUAL "${JSONCPP_CACHED_JSONCPP_DIR_DETAILS}")
92+
#message("Updating jsoncpp cache variables! ${__jsoncpp_info_string}")
93+
set(JSONCPP_CACHED_JSONCPP_DIR_DETAILS "${__jsoncpp_info_string}" CACHE INTERNAL "" FORCE)
7494
unset(JSONCPP_IMPORTED_LIBRARY_SHARED)
7595
unset(JSONCPP_IMPORTED_LIBRARY_STATIC)
7696
unset(JSONCPP_IMPORTED_LIBRARY)
7797
unset(JSONCPP_IMPORTED_INCLUDE_DIRS)
7898
unset(JSONCPP_IMPORTED_LIBRARY_IS_SHARED)
79-
_jsoncpp_check_for_real_jsoncpplib()
8099

81100
# if(__jsoncpp_have_jsoncpplib) is equivalent to if(TARGET jsoncpp_lib) except it excludes our
82101
# "invented" jsoncpp_lib interface targets, made for convenience purposes after this block.

0 commit comments

Comments
 (0)