This is an archive of the discontinued LLVM Phabricator instance.

[cmake] Stop using add_definitions
ClosedPublic

Authored by foad on Jan 23 2023, 7:09 AM.

Details

Summary

Since CMake 3.12 this has been superseded by add_compile_definitions and
other commands.

Diff Detail

Event Timeline

foad created this revision.Jan 23 2023, 7:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2023, 7:09 AM
foad requested review of this revision.Jan 23 2023, 7:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2023, 7:09 AM
foad added a comment.Jan 23 2023, 7:10 AM

llvm/docs/CMake.rst also mentions add_definitions:

include_directories(${LLVM_INCLUDE_DIRS})
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS_LIST})

I'm not sure what this should be changed to. @sepavloff do you know?

barannikov88 accepted this revision.Jan 23 2023, 7:37 AM
barannikov88 added inline comments.
llvm/cmake/modules/HandleLLVMOptions.cmake
71

I wonder if remove_definitions($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:NDEBUG>) works?
It seems it is able to remove previously added DDEBUG from the command line, but otherwise does not pass "-UNDEBUG" to the compiler.

This revision is now accepted and ready to land.Jan 23 2023, 7:37 AM
foad added inline comments.Jan 23 2023, 7:39 AM
llvm/cmake/modules/HandleLLVMOptions.cmake
71

Interesting. I did not know about remove_definitions. But I'd prefer not to do that in this patch, since I have already tested it as-is.

beanz added inline comments.Jan 23 2023, 9:43 AM
llvm/cmake/modules/HandleLLVMOptions.cmake
71

Generator expressions may be a bit convoluted to read, but I think it is better to use add_compile_options with a conditional generator expression than to add the option, then need to remove it from places where it shouldn't be.

I think the code as written is preferable and easier to maintain in the long run.

This revision was landed with ongoing or failed builds.Jan 24 2023, 12:27 AM
This revision was automatically updated to reflect the committed changes.