This is an archive of the discontinued LLVM Phabricator instance.

Don't add unnecessary compiler flags to llvm-config output
ClosedPublic

Authored by tstellar on Dec 6 2018, 3:27 PM.

Details

Summary

llvm-config --cxxflags --cflags, should only output the minimal flags
required to link against the llvm libraries. They currently contain
all flags used to compile llvm including flags like -g, -pedantic,
-Wall, etc, which users may not always want.

This changes the llvm-config output to only include flags that have been
explictly added to the COMPILE_FLAGS property of the llvm-config target
by the llvm build system.

llvm.org/PR8220

Output from llvm-config when running cmake with:
cmake -G Ninja .. -DCMAKE_CXX_FLAGS=-funroll-loops

Before:

--cppflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include

-D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS

--cflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include

-fPIC -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings \
-Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough \
-Wno-comment -fdiagnostics-color -g -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS \
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS

--cxxflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include\

-funroll-loops -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall \
-Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers \
-pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized \
-Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment \
-fdiagnostics-color -g  -fno-exceptions -fno-rtti -D_GNU_SOURCE -D_DEBUG \
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"

After:

--cppflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include \

-D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS

--cflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include \

-D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS

--cxxflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include \

-std=c++11   -fno-exceptions -fno-rtti \
-D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS

Diff Detail

Event Timeline

tstellar created this revision.Dec 6 2018, 3:27 PM
sylvestre.ledru accepted this revision.Dec 7 2018, 7:22 AM

Much better. thanks!

This revision is now accepted and ready to land.Dec 7 2018, 7:22 AM
mgorny added a comment.Dec 7 2018, 7:50 AM

Thanks, this is something we've been hacking out in Gentoo for a long time. One nit though.

tools/llvm-config/CMakeLists.txt
37

Shouldn't cxxflags also include -std?

tstellar marked an inline comment as done.Dec 7 2018, 9:01 AM
tstellar added inline comments.
tools/llvm-config/CMakeLists.txt
37

Yes, I think we need to keep -std=c++11.

tstellar updated this revision to Diff 177985.Dec 12 2018, 6:36 PM

Make sure llvm-config reports the c/c++ language standard used.

tstellar edited the summary of this revision. (Show Details)Dec 12 2018, 6:38 PM
mgorny accepted this revision.Dec 13 2018, 12:12 AM

Thanks. Works fine for me.

This revision was automatically updated to reflect the committed changes.
nik added a subscriber: nik.Jun 5 2019, 6:34 AM
nik added inline comments.
llvm/trunk/tools/llvm-config/CMakeLists.txt
35 ↗(On Diff #178091)

I guess -D_GLIBCXX_USE_CXX11_ABI=0 would be such a flag that shouldn't be handled here?

Is there a way to have this shown up in "llvm-config --cxxflags" as in previous versions by modifying the cmake invocation? I've tried several things to get it "into" LLVM_DEFINITIONS or COMPILE_FLAGS, but my cmake foo is too limited as of now :/

Herald added a project: Restricted Project. · View Herald TranscriptJun 5 2019, 6:34 AM
tstellar marked an inline comment as done.Oct 3 2019, 8:32 PM
tstellar added inline comments.
llvm/trunk/tools/llvm-config/CMakeLists.txt
35 ↗(On Diff #178091)

Does the LLVM build system add this flag somewhere, or does the user need to add it manually when configuring?