[solved] qmake - possible to add header files based on a define?
-
Currently I am working on a app that will need specific headers for specific linux distros, am curious to know how (if possible) to add headers and source based on the distro.
In my pro file i am checking a environment variable to see if it is Ubuntu with Unity
@linux{
CURRENT_DESKTOP = $$(XDG_CURRENT_DESKTOP)
equals($${CURRENT_DESKTOP}, "Unity")
{
DEFINES += "IS_UNITY=YES"
}
}@How do i add files based on the define?
I tried:@contains(DEFINES, IS_UNITY)
{
headers += unity.h
} else {
headers += notunity.h
}@But when the pro file is evaluated, both files are added, or i get "expected else"
Thoughts? -
Hi,
IIRC
@
contains(DEFINES, IS_UNITY) { <- bracket position
headers += unity.h
} else {
headers += notunity.h
}@But are you sure you want to use two separate headers for that ? You could #ifdef the code
-
What is generally done is a common header file and if needed (as in: there is a lot of code), separate the implementation is several files e.g.
myclass.h
myclass.cpp
myclass_win.cpp
myclass_unix.cpp
etc. -
SGalst -
How do you go about loading the different source file...I mean for win vs Linux it is easy, but to get it on environment variable:
@
contains(DEFINES, IS_UNITY) {
SOURCE += ubuntu.cpp
} else {
SOUECE += linux.cpp
}@
When i do the above it always adds both files, I fear I am doing it wrong :)
-
@
DEFINES += IS_UNITY <- this is enough
contains(DEFINES, IS_UNITY) {
SOURCES += ubuntu.cpp
} else {
SOURCES += linux.cpp
}@works for me. Well I replaced SOURCES with message for the test
-
[quote author="SGaist" date="1396552163"]@
DEFINES += IS_UNITY <- this is enough
contains(DEFINES, IS_UNITY) {
SOURCES += ubuntu.cpp
} else {
SOURCES += linux.cpp
}@works for me. Well I replaced SOURCES with message for the test[/quote]
Hmmm odd.....I get both the files no matter what, i switched it to message and got both messages as well. (Ubuntu 13.10 32 bit with Qt.5.2)
@
DEFINES += IS_UNITY
contains(DEFINES, IS_UNITY) {
message("Is unity")
} else {
message("Is not unity")
}
@Prints out:
message: Is unity
message Is not unityI did end up just putting #ifdef at the start of the code file and it worked that way but adding it in the pro file fires off both true and false.
-
You seem to have qmake running twice. Can you print what XDG_CURRENT_DESKTOP contains ?