[llvm] Updated CMake documentation (PR #121083)

The Linux Fox🌸 via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 24 20:33:15 PST 2024


https://github.com/TheoW03 created https://github.com/llvm/llvm-project/pull/121083

I updated the CMake sample file to instead use 

```cmake
  add_llvm_executable(simple-tool tool.cpp)
```

instead of 
```cmake
# Now build our tools
add_executable(simple-tool tool.cpp)

# Find the libraries that correspond to the LLVM components
# that we wish to use
llvm_map_components_to_libnames(llvm_libs support core irreader)

# Link against LLVM libraries
target_link_libraries(simple-tool ${llvm_libs})
```
which according to multiple sources. and the next page of the docs is out of date 

>From 511c875a4ff5c2ab5f117781e17854e018c7294f Mon Sep 17 00:00:00 2001
From: TheoW03 <21theowillis at gmail.com>
Date: Tue, 24 Dec 2024 23:27:16 -0500
Subject: [PATCH] feat: made a small patch with CMake documentation

---
 llvm/docs/CMake.rst | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/llvm/docs/CMake.rst b/llvm/docs/CMake.rst
index 91e34781ef307e..d6bc1e3544948d 100644
--- a/llvm/docs/CMake.rst
+++ b/llvm/docs/CMake.rst
@@ -1021,6 +1021,7 @@ and uses them to build a simple application ``simple-tool``.
 
   cmake_minimum_required(VERSION 3.20.0)
   project(SimpleProject)
+  include(AddLLVM)
 
   find_package(LLVM REQUIRED CONFIG)
 
@@ -1036,15 +1037,9 @@ and uses them to build a simple application ``simple-tool``.
   separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
   add_definitions(${LLVM_DEFINITIONS_LIST})
 
-  # Now build our tools
-  add_executable(simple-tool tool.cpp)
-
-  # Find the libraries that correspond to the LLVM components
-  # that we wish to use
-  llvm_map_components_to_libnames(llvm_libs support core irreader)
-
-  # Link against LLVM libraries
-  target_link_libraries(simple-tool ${llvm_libs})
+  
+  # now build and link your tool with the llvm 
+  add_llvm_executable(simple-tool tool.cpp)
 
 The ``find_package(...)`` directive when used in CONFIG mode (as in the above
 example) will look for the ``LLVMConfig.cmake`` file in various locations (see



More information about the llvm-commits mailing list