[llvm] a2a65a5 - [docs] [CMake] Change recommendations for how to use LLVM_DEFINITIONS

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Tue May 25 13:04:44 PDT 2021


Author: Martin Storsjö
Date: 2021-05-25T22:56:51+03:00
New Revision: a2a65a5bae3c503d40c219ef9ba460b1fb34d1bf

URL: https://github.com/llvm/llvm-project/commit/a2a65a5bae3c503d40c219ef9ba460b1fb34d1bf
DIFF: https://github.com/llvm/llvm-project/commit/a2a65a5bae3c503d40c219ef9ba460b1fb34d1bf.diff

LOG: [docs] [CMake] Change recommendations for how to use LLVM_DEFINITIONS

LLVM_DEFINITIONS is a string variable containing a list of arguments
to pass to the compiler. When CMake's add_definitions is passed a
string variable, this is interpreted as one argument. To make it
behave properly, the string variable needs to be split into a list.

Despite the fact that add_definitions isn't supposed to be used like
the LLVM docs recommended, it worked fine in practice in many cases.
If the first argument in LLVM_DEFINITIONS is of the form -DFOO=42
instead of plain -DFOO, the rest of the string is treated as value
to this define. I.e. if LLVM_DEFINITIONS consists of `-DFOO=42 -DBAR`,
CMake ended up passing `-DFOO="42 -DBAR"` to the compiler.

See https://gitlab.kitware.com/cmake/cmakissues/22162
for discussion on the matter.

Changing LLVM_DEFINITIONS to be a list variable would possibly be
more disruptive; instead keep the variable defined as before but
change the recommendation for how to use it. Then projects using it
can gradually be updated to follow the new recommendation.

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

Added: 
    

Modified: 
    llvm/docs/CMake.rst

Removed: 
    


################################################################################
diff  --git a/llvm/docs/CMake.rst b/llvm/docs/CMake.rst
index 589b09f28281..c1d1cd0c7c71 100644
--- a/llvm/docs/CMake.rst
+++ b/llvm/docs/CMake.rst
@@ -770,7 +770,8 @@ and uses them to build a simple application ``simple-tool``.
   # for your compiler.
 
   include_directories(${LLVM_INCLUDE_DIRS})
-  add_definitions(${LLVM_DEFINITIONS})
+  separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
+  add_definitions(${LLVM_DEFINITIONS_LIST})
 
   # Now build our tools
   add_executable(simple-tool tool.cpp)
@@ -870,7 +871,8 @@ Contents of ``<project dir>/CMakeLists.txt``:
 
   find_package(LLVM REQUIRED CONFIG)
 
-  add_definitions(${LLVM_DEFINITIONS})
+  separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
+  add_definitions(${LLVM_DEFINITIONS_LIST})
   include_directories(${LLVM_INCLUDE_DIRS})
 
   add_subdirectory(<pass name>)


        


More information about the llvm-commits mailing list