How can I overwrite the cflags/cxxflags (rtti and exceptions) in my module? (gn build system)

1,559 views
Skip to first unread message

Samuel Yang

unread,
Oct 20, 2016, 4:44:17 AM10/20/16
to Chromium-dev

Hi, 

I have my own module and have a BUILD.gn , I have added the flags as below. However, there are still  -fno-rtti and -fno-exceptions after -frtti and -fexceptions in the compile log.  

How can I just enable rtti and exception in my module but disable rtti and exceptions the others in chromium(It already did)?  Great thanks.  

   cflags = [
    "-fexceptions",
    "-frtti",
    ]

   cflags_cc = [
    "-fexceptions",
    "-frtti",
    ]
 
 

Thiago Farina

unread,
Oct 20, 2016, 7:07:24 AM10/20/16
to yangxi...@gmail.com, Chromium-dev
In your BUILD.gn try doing:

configs -= [ "//build/config/gcc:no_exceptions" ]


--
Thiago Farina

Thiago Farina

unread,
Oct 20, 2016, 7:08:13 AM10/20/16
to yangxi...@gmail.com, Chromium-dev
For rtti:

  configs -= [ "//build/config/compiler:no_rtti" ] 
configs += [ "//build/config/compiler:rtti" ]
 


--
Thiago Farina

Samuel Yang

unread,
Oct 20, 2016, 7:52:07 AM10/20/16
to Chromium-dev, yangxi...@gmail.com
Thank you. It works. 

在 2016年10月20日星期四 UTC+8下午7:08:13,Thiago Farina写道:

Samuel Yang

unread,
Oct 21, 2016, 3:33:22 AM10/21/16
to Chromium-dev, yangxi...@gmail.com

Is it possible that I only want to particular files enable rtti but not the whole module? 



在 2016年10月20日星期四 UTC+8下午7:08:13,Thiago Farina写道:

Krzysztof Olczyk

unread,
Oct 21, 2016, 4:51:38 AM10/21/16
to yangxi...@gmail.com, Chromium-dev
You may put them in the separate source_set-s.

-- 
Best regards,
Krzysztof Olczyk
Software Developer & Architect
TVSDK Core team

Opera TV
Pl. Teatralny 8, 50-051 Wroclaw, Poland

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.

unclerun...@gmail.com

unread,
Nov 8, 2018, 2:19:23 PM11/8/18
to Chromium-dev
You can modify src/build/config/compiler/BUILD.gn by adding a declare_args :

declare_args(){
     ...
     use_rtti = false
     use_exceptions = false
     ...
}

set to false by default. 

In the same file, add a switch to config("no_rtti")  and config("no_exceptions")

config("no_rtti") {
if (!use_rtti) {
if (is_win) {
cflags_cc = [ "/GR-" ]
} else {
cflags_cc = [ "-fno-rtti" ]
cflags_objcc = cflags_cc
}
}
}

config("no_exceptions") {
if (!use_exceptions){
if (is_win) {
# Disables exceptions in the STL.
# libc++ uses the __has_feature macro to control whether to use exceptions,
# so defining this macro is unnecessary. Defining _HAS_EXCEPTIONS to 0 also
# breaks libc++ because it depends on MSVC headers that only provide certain
# declarations if _HAS_EXCEPTIONS is 1. Those MSVC headers do not use
# exceptions, despite being conditional on _HAS_EXCEPTIONS.
if (!use_custom_libcxx) {
defines = [ "_HAS_EXCEPTIONS=0" ]
}
} else {
cflags_cc = [ "-fno-exceptions" ]
cflags_objcc = cflags_cc
}
}
}

Then run gn gen with agrs:

gn gen out/default --args='use_rtti=true use_exceptions=true'



在 2016年10月20日星期四 UTC+8下午4:44:17,Samuel Yang写道:

David Turner

unread,
Nov 9, 2018, 5:49:45 AM11/9/18
to unclerun...@gmail.com, chromi...@chromium.org
What you propose would turn on exceptions and RTTI for _all_ code compiled, which is not desirable, nor what the initial question was about.

An answer closer to being correct would be to remove the "no_rtti" and "no_exceptions"  configs the specific module, and replace them with "rtti" and "exceptions", e.g. something like:


source_set("foo_module") {
  sources = [ ... ]
  ...
  configs -= [ "//build/config/compiler:no_rtti" ]
  configs += [ "//build/config/compiler:rtti" ]
  configs -= [ "//build/config/compiler:no_exceptions" ]
  configs += [ "//build/config/compiler:exceptions" ]
}


--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/494ebd19-0cb2-4087-af39-385d059a42af%40chromium.org.
Reply all
Reply to author
Forward
0 new messages