[PATCH] D103044: [docs] [CMake] Change recommendations for how to use LLVM_DEFINITIONS
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 24 13:28:12 PDT 2021
mstorsjo created this revision.
mstorsjo added reviewers: phosek, beanz, smeenai.
Herald added a subscriber: mgorny.
mstorsjo requested review of this revision.
Herald added a project: LLVM.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D103044
Files:
llvm/docs/CMake.rst
Index: llvm/docs/CMake.rst
===================================================================
--- llvm/docs/CMake.rst
+++ llvm/docs/CMake.rst
@@ -770,7 +770,8 @@
# 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 @@
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>)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103044.347487.patch
Type: text/x-patch
Size: 773 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210524/89a608f8/attachment.bin>
More information about the llvm-commits
mailing list