In my CMake project, I provide a default path to Boost editable by the user.
set(PATH_BOOST_DEFAULT "/softs/boost/${BOOST_VER}/${ARCH}/gcc/${GCCVER}")
set(PATH_BOOST "${PATH_BOOST_DEFAULT}" CACHE PATH "Default path to Boost")
After that, I try to find the libs with :
set(BOOST_ROOT "${PATH_BOOST}")
set(Boost_USE_MULTITHREAD ON)
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost 1.53.0 REQUIRED COMPONENTS thread system)
This works fine and a lot of cache variables like Boost_INCLUDE_DIR
, Boost_LIBRARY_DIRS
or Boost_THREAD_LIBRARY_DEBUG
are generated.
My problem comes when I try to modify the cache variable PATH_BOOST
: the cache variables generated by FindBoost.cmake
aren't updated. The script FindBoost.cmake
seems to be called again (it print messages about found components). I think the variables like Boost_INCLUDE_DIR
are not updated because they are in cache.
Is there a way to say to cmake "if the path is modified by the user, refind the package by forcing the cache variables" ?
Also, is there a nicer way to detect a cache variable was just modified than the following ugly idea ? :-/
set(MY_VAR ${MY_VAR_DEFAULT} CACHE TYPE "")
if(NOT DEFINED MY_VAR_copy)
set(MY_VAR_copy ${MY_VAR} CACHE INTERNAL "")
mark_as_advanced(FORCE MY_VAR_copy)
endif()
if(NOT "${MY_VAR}" STREQUAL "${MY_VAR_copy}")
# my_var is modified : do something
set(MY_VAR_copy ${MY_VAR} CACHE INTERNAL "")
endif()