[CMake] Add missing find_package for LibEdit
authorPetr Hosek <phosek@google.com>
Fri, 21 Apr 2023 22:34:11 +0000 (22:34 +0000)
committerPetr Hosek <phosek@google.com>
Fri, 21 Apr 2023 22:34:11 +0000 (22:34 +0000)
After building and installing LLVM with LibEdit as a dependency, it is
necessary to find it again when LLVM is consumed by another CMake
project, otherwise CMake will report an error about a missing target.

Note that the FindLibEdit.cmake file is in the "LLVM Common CMake
Utils" directory, outside of the LLVM sub-project source directory, so
the installed LLVMConfig.cmake relies on the user having installed the
LLVM common CMake modules or make available their own Find module.

Also note that the controlling HAVE_LIBEDIT CMake variable in
LLVMConfig.cmake.in has a different naming convention compared to
other similar variables like 'LLVM_ENABLE_TERMINFO'. Refactoring this
name would involve touching additional files and should be a follow-up
commit.

Patch By: ekilmer

Differential Revision: https://reviews.llvm.org/D147153

llvm/cmake/config-ix.cmake
llvm/cmake/modules/LLVMConfig.cmake.in

index 752ca33..2c81543 100644 (file)
@@ -220,8 +220,12 @@ if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
   if (NOT PURE_WINDOWS)
     # Skip libedit if using ASan as it contains memory leaks.
     if (LLVM_ENABLE_LIBEDIT AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*")
-      find_package(LibEdit)
-      set(HAVE_LIBEDIT ${LibEdit_FOUND})
+      if(LLVM_ENABLE_LIBEDIT STREQUAL FORCE_ON)
+        find_package(LibEdit REQUIRED)
+      else()
+        find_package(LibEdit)
+      endif()
+      set(HAVE_LIBEDIT "${LibEdit_FOUND}")
     else()
       set(HAVE_LIBEDIT 0)
     endif()
@@ -234,9 +238,11 @@ if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
       set(LLVM_ENABLE_TERMINFO "${Terminfo_FOUND}")
     endif()
   else()
+    set(HAVE_LIBEDIT 0)
     set(LLVM_ENABLE_TERMINFO 0)
   endif()
 else()
+  set(HAVE_LIBEDIT 0)
   set(LLVM_ENABLE_TERMINFO 0)
 endif()
 
index 2d90512..42dfd60 100644 (file)
@@ -58,6 +58,11 @@ endif()
 
 set(LLVM_ENABLE_RTTI @LLVM_ENABLE_RTTI@)
 
+set(LLVM_ENABLE_LIBEDIT @HAVE_LIBEDIT@)
+if(LLVM_ENABLE_LIBEDIT)
+  find_package(LibEdit)
+endif()
+
 set(LLVM_ENABLE_TERMINFO @LLVM_ENABLE_TERMINFO@)
 if(LLVM_ENABLE_TERMINFO)
   find_package(Terminfo)