CMake CACHE variables heads-up for 3.4

Hello,

You may have noticed CMake-built versions of clang with unusual
executable versions, for example a current TOT clang just got built as
clang-3.2/libclang.3.2.dylib and another machine tracking LLVM SVN head
is getting built under bin/clang-3.3 even after make clean.

This seems to have been causing confusion in LLVM.org bug reports for
some time..

It turns out this happens because CLANG_EXECUTABLE_VERSION is set as a
CACHE variable in CMakeLists.txt. So value gets cached to whatever the
version was the *first time* you built LLVM and arbitrarily persists
through version upgrades -- probably not what anyone wants. Likewise the
libclang shared objects will get installed using whatever this value is
in your cache.

I'm planning to make at least CLANG_EXECUTABLE_VERSION and
LIBCLANG_LIBRARY_VERSION ordinary CMake variables in time for the new
release. This means if you're tracking LLVM 3.4 and relying on (or
shipping!) the binary installed as clang-3.1, clang-3.2 or clang-3.3
it's now going to change to clang-3.4 in line with the configure-based
system.

You'll still be able to tweak all the variables for your custom vendor
distribution as usual using -DCLANG_EXECUTABLE_VERSION etc. or with the
CMake GUI -- this change will just remove the hidden storage, but I
wanted to give a heads up in case anyone is relying on that behaviour.

Incidentally there are various other CACHE variables in LLVM's build
system, but they seem less problematic..

CMakeLists.txt: set(CLANG_PATH_TO_LLVM_SOURCE "" CACHE PATH
CMakeLists.txt- "Path to LLVM source code. Not necessary if using an
installed LLVM.")
CMakeLists.txt: set(CLANG_PATH_TO_LLVM_BUILD "" CACHE PATH
CMakeLists.txt- "Path to the directory where LLVM was built or
installed.")
CMakeLists.txt-

Good catch, Alp! Please do make this change.

So the variable will be updated at every run of cmake, but this will
not cause cmake to run at every ninja/make invocation, right?

So the variable will be updated at every run of cmake, but this will
not cause cmake to run at every ninja/make invocation, right?

No, it'll still be an ordinary configure variable.

The difference is that the value won't get stuck behind when the version
in SVN/git changes, such as when you're doing a rebase locally or when
3.4 gets released.

To see what I mean, try building the previous three stable clang
releases in your ordinary location -- odds are, they'll all be built as
clang-3.4 and libclang.3.4.dylib/so.

The previous behaviour meant that CMake was saving whatever the version
number was the first time you built your SVN checkout, possibly years
ago, and never updating it again which is a foreign concept to say the
least :slight_smile:

Alp.

> So the variable will be updated at every run of cmake, but this will
> not cause cmake to run at every ninja/make invocation, right?

No, it'll still be an ordinary configure variable.

To clarify, do you mean:

If a user never overrides CLANG_EXECUTABLE_VERSION, then changing the
LLVM_VERSION_MAJOR and LLVM_VERSION_MINOR variables in llvm/CMakeLists.txt
will change the version number we use when building clang.

If a user overrides CLANG_EXECUTABLE_VERSION, then their overridden value
will be kept whenever cmake is rerun (for instance, when the LLVM version
number changes).

The difference is that the value won't get stuck behind when the version
in SVN/git changes, such as when you're doing a rebase locally or when
3.4 gets released.

To see what I mean, try building the previous three stable clang
releases in your ordinary location -- odds are, they'll all be built as
clang-3.4 and libclang.3.4.dylib/so.

The previous behaviour meant that CMake was saving whatever the version
number was the first time you built your SVN checkout, possibly years
ago, and never updating it again which is a foreign concept to say the
least :slight_smile:

The previous behavior seems to be a bug to me. Please do fix it!

Update: It turns out this is a CMake bug/limitation.

I've reported it on their tracker at
http://www.cmake.org/Bug/view.php?id=14546 (accepted as a desired
enhancement) and have a patch in the works. Will post here as well as to
cmake.org when it's ready.

In the meantime, keep in mind that values including build flags,
filesystem paths and the clang version number will persist even when
changed in SVN and even if you used defaults.

Alp.