[llvm] Export `LLVM_VERSION_*` CMake variables to `PARENT_SCOPE` (PR #83346)

Benoit Jacob via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 28 14:06:52 PST 2024


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

This allows users who include `llvm-project` as a subrepository to access `LLVM_VERSION_*` variables on par with if they were relying on an intalled LLVM and `FindLLVM.cmake`.

My particular need here is limited to `LLVM_VERSION_MAJOR` as I need to construct custom `clang` command lines that point to the path for clang built-in headers, e.g. `${build_dir}/llvm-project/lib/clang/19/include/immintrin.h`. So I'm OK with restricting this PR to just `LLVM_VERSION_MAJOR` if you prefer, or with any alternative way to construct `clang` command lines that find the path to built-in headers (I have to build with flags like `-nostdinc` and `-ffreestanding` that make me fall off of the normal path where things just work).

Context: https://github.com/openxla/iree/pull/16606 -- like other projects with similar needs that I found by some googling, our work-around had been to rely on the CMake cached variable `CLANG_EXECUTABLE_VERSION`. Being cached, it over time inevitably ended up having a wrong value.

>From 0aabc92a1836c18ed4b01cac9e5f3bde68d6ef35 Mon Sep 17 00:00:00 2001
From: Benoit Jacob <jacob.benoit.1 at gmail.com>
Date: Wed, 28 Feb 2024 17:00:28 -0500
Subject: [PATCH] llvm-version-major

---
 llvm/CMakeLists.txt | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 651f17879fad24..c73e0594fecef2 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -16,16 +16,16 @@ if(NOT LLVM_NO_INSTALL_NAME_DIR_FOR_BUILD_TREE)
 endif()
 
 if(NOT DEFINED LLVM_VERSION_MAJOR)
-  set(LLVM_VERSION_MAJOR 19)
+  set(LLVM_VERSION_MAJOR 19 PARENT_SCOPE)
 endif()
 if(NOT DEFINED LLVM_VERSION_MINOR)
-  set(LLVM_VERSION_MINOR 0)
+  set(LLVM_VERSION_MINOR 0 PARENT_SCOPE)
 endif()
 if(NOT DEFINED LLVM_VERSION_PATCH)
-  set(LLVM_VERSION_PATCH 0)
+  set(LLVM_VERSION_PATCH 0 PARENT_SCOPE)
 endif()
 if(NOT DEFINED LLVM_VERSION_SUFFIX)
-  set(LLVM_VERSION_SUFFIX git)
+  set(LLVM_VERSION_SUFFIX git PARENT_SCOPE)
 endif()
 
 if (NOT PACKAGE_VERSION)



More information about the llvm-commits mailing list