[llvm] Export `LLVM_VERSION_MAJOR` CMake variable to `PARENT_SCOPE` (PR #83346)

Benoit Jacob via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 4 19:24:54 PST 2024


================
@@ -28,6 +28,12 @@ if(NOT DEFINED LLVM_VERSION_SUFFIX)
   set(LLVM_VERSION_SUFFIX git)
 endif()
 
+# Export a few LLVM version identifiers for users who use LLVM as a subdir.
+get_directory_property(_LLVM_HAS_PARENT_DIRECTORY PARENT_DIRECTORY)
+if (_LLVM_HAS_PARENT_DIRECTORY)
+  set(LLVM_VERSION_MAJOR "${LLVM_VERSION_MAJOR}" PARENT_SCOPE)
----------------
bjacob wrote:

Thanks for teaching me better CMake! Now this PR is down to 1 line with no control flow and I have verified that my downstream project is able to read the variable like this,

```
  get_directory_property(LLVM_VERSION_MAJOR DIRECTORY "third_party/llvm-project/llvm" LLVM_VERSION_MAJOR)
```

https://github.com/llvm/llvm-project/pull/83346


More information about the llvm-commits mailing list