In my cmake configuration several variables depend on an environment variable in order to be set correctly. This environment variable can change and it means that the cache for cmake should be rebuilt.
My configuration can detect the need for this reconfigure and update the appropriate cache entries when either another call to “cmake ” is called or “make rebuild_cache” is called.
However, I would like whenever I run make it to be checked automatically for changes and have the rebuild_cache target run if necessary.
Is this possible?
Make does not have a memory. There is no way for make to “remember” what a given environment variable was set to the last time make was run.
Unless you write the environment variable to a file.
I’ve never used CMake, so I don’t know how to best implement it. But on the “raw” make level, the general idea would be to:
1) write a rule (say,
envir_cache) which writes the environment variable to file (named, not so coincidentially,envir_cache), if that file does not yet exist, or the file exists but its contents are different from the value of the environment variable. (Something along the lines ofif [ -f envir_cache ]andread cached_var < envir_cacheandif [ "${myvar}" != "${cached_var}" ].)2) make the target
rebuild_cachedepend onenvir_cache.That way, the
rebuild_cacherule will be executed on the first run, and whenever the variable changed between runs.