Opened 12 years ago

Closed 12 years ago

#36872 closed enhancement (fixed)

qt4-mac c++11 variant request

Reported by: patlaborforce@… Owned by: michaelld (Michael Dickens)
Priority: Normal Milestone:
Component: ports Version: 2.1.2
Keywords: Cc:
Port: qt4-mac

Description

Is it possible to get a qt4-mac variant that will compile for c++11?

Change History (17)

comment:1 Changed 12 years ago by ryandesign (Ryan Carsten Schmidt)

Keywords: qt4-mac c++11 removed
Owner: changed from macports-tickets@… to michaelld@…

I don't understand the request. Are you saying that qt4-mac, as we distribute it now, cannot be used from c++11 code? If so, what is the error message that you encounter? Can you post a reproduction recipe for the problem?

comment:2 Changed 12 years ago by patlaborforce@…

In order to use features like initializer lists with Qt containers, Qt must be compiled as C+11. So I need to be able to get a version that compiles with the requisite options such as "-std=c++11". I am unable, or don't know how, to pass this option to the compiler. It just compiles as C++98.

comment:3 Changed 12 years ago by michaelld (Michael Dickens)

This won't work with Apple's GCC since it's too old to accept that flag, but I believe MacPorts' gcc 4.7 and newer should work with the flag. It looks like it might work with the latest Apple clang, and maybe also MacPorts' latest clang. I've never tested Qt using MacPorts gcc or clang; I really don't know if it would work. I think your primary option is to use the latest Apple clang, which is available on 10.7 and 10.8 only if I remember correctly.

Qt's "configure" script (as of 4.8.3) does not provide an explicit option to choose the C++ compiling version. The Qt 5.0 beta does provide a flag ("-c++11" or "-no-c++-11") but I haven't figure out how to get it to compile yet (with or without this flag) and hence it is not in qt4-mac-devel yet.

If you have the latest Apple clang, I would advise you to add "-D -std=c++11" after "-no-phonon-backend" in the current qt4-mac Portfile and see if that works; if it does, then I'll add that as a variant. If it does not, then I won't and I'm really not interested in hacking in support for c++11 in any other way.

comment:4 Changed 12 years ago by patlaborforce@…

On my system, at least, it is using the latest clang to compile which supports the option. The way I get it to work when compiling it on Windows is passing that option as part of the QMAKE_CXXFLAGS, but I didn't know where to modify the portfile to get that to pass through. I'll try what you recommend to see if that works and then post a followup if it works. Thanks.

comment:5 Changed 12 years ago by patlaborforce@…

Okay that didn't work. Fails on the configure as an invalid switch.

comment:6 Changed 12 years ago by michaelld (Michael Dickens)

Hmm ... I can't try the flag right now, but let me play with it and I'll see if I can work it out.

comment:7 Changed 12 years ago by patlaborforce@…

Okay. Thanks.

comment:8 Changed 12 years ago by patlaborforce@…

Any updates? Thanks.

comment:9 Changed 12 years ago by michaelld (Michael Dickens)

No updates. I have other ports higher on my queue right now as well as a much looking-forward-to vacation over the upcoming weekend / US Vet's day. No promises, but I should be able to get to it by the end of next week.

comment:10 Changed 12 years ago by michaelld (Michael Dickens)

Well, after a LOT of hacking, I think I can convince QMake and Qt 4.8 to compile using C++11. Then, of course, I deleted all of the patches. So, a weekend's worth of work almost entirely gone; sigh. That said, I know which files have to be changed, and roughly what the changes are, and thus I can redo the patches. So, hang on for a while longer.

comment:11 Changed 12 years ago by michaelld (Michael Dickens)

I'm back working on this ticket again, and have a question. I can pretty easily add the option for compiling with c++11 to qt4-mac, by following how Qt5 does it. But do you know if Qt4 actually has to be compiled (internally) using c++11 for everything to work? That's what my prior "hacking" comment was about: getting Qt4 to compile using c++11 as the default for c++ and objc++ files and during linking. I'm most of the way back to having Qt4 compile using c++11, when this thought occurred to me -- could save me a bit of time if what you want is just the option, but not requiring compiling of. Either way, I've learned a bit about c++11 during this journey, which has been both fascinating (e.g., learning about the default constructor = delete syntax and meaning) and frustrating (having to determine what the issue is in the first place given the error message, then figuring out ways to hack around issue).

comment:12 Changed 12 years ago by patlaborforce@…

But do you know if Qt4 actually has to be compiled (internally) using c++11 for everything to work?

Yes, to get support for things like initializer lists using the Qt containers, Qt itself needs to be compiled with the -std=c++11 option.

comment:13 Changed 12 years ago by michaelld (Michael Dickens)

OK; thanks for the quick reply! I'll keep pushing. Should be done in the next few days if all goes well and I don't delete the patches again. I'm -really- trying to not do that again; was quite frustrating.

Not sure if you know the answer to this, but does the Qt project provide a binary distribution of Qt (4 or 5) that has c++11 enabled? I see from the Qt5 source that c++11 is a configuration option, but, at least in a quick search through the configure script, this option does not seem to make the source compile using it; it just seems to provide using c++11 as an option. I might be wrong; I haven't spent a lot of time on Qt5 yet. That's on my queue once i get a few other tickets out of the way (including this one).

comment:14 Changed 12 years ago by patlaborforce@…

Not sure if you know the answer to this, but does the Qt project provide a binary distribution of Qt (4 or 5) that has c++11 enabled?

Unfortunately, they don't. Which is a real shame. Thanks for all your work on this, though. I really really appreciate it. :)

comment:15 Changed 12 years ago by michaelld (Michael Dickens)

Yes, quite a shame. One last item to overcome, and I'm good to go. My question of the day is: Do you believe c++11 should be enabled in CONFIG by default or not when this variant is select? I'm believing "not" since that would impact a lot of other ports and projects. For those wishing to add it, it's a simple like of code in a QMake build file (I think this will work):

contains(QT_CONFIG,c++11): CONFIG += c++11

which then will work with any Qt (4 or 5, with or without support for c++11). I'll have to check, but I believe this is the way Qt5 does c++11 support: compile using c++11, but do not enable it in CONFIG by default; again, I might be wrong. Anyway, your thoughts?

comment:16 Changed 12 years ago by patlaborforce@…

Yeah, I think your idea sounds perfectly reasonable. Definitely don't want other things being impacted and possibly broken because of this.

Last edited 12 years ago by patlaborforce@… (previous) (diff)

comment:17 Changed 12 years ago by michaelld (Michael Dickens)

Resolution: fixed
Status: newclosed

Done in r102010. I used Apple's latest clang for testing; I did not try MacPorts' gcc 4.6 or newer though I think they should work (I will be trying them today). If you have an issue with the c++11 support, please open another ticket with the specifics.

Note: See TracTickets for help on using tickets.