QMake defineReplace
-
Hi guys!
I'm research into a qmake in current time, I have been taught how to define the self-function by some technical manual from this exmaple. However,there is a strange warning reported by Qt Creator when I had an attempt to write 'defineReplace' funtion, As following tips:
'AddCompilerOptions' is not a recognized test function.
the QMake code is that:defineReplace(AddCompilerOptions){ for(compileOption,ARGS){ QMAKE_CXXFLAGS += $$compileOption message("Insider option $$QMAKE_CXXFLAGS") } QMAKE_CXXFLAGS += $$ARGS return(true) }
Additionally, it seems to not be affected for the above code, even if the key 'defineReplace' was substituted for key 'defineReplace'.
There is nothing to be appended the variable QMAKE_CXXFLAGS When I try to print it in term of qmake function 'message' outside the scope of function AddCompilerOptions.thanks!
-
Hi,
Can you provide a minimal .pro file that can show the behaviour ?
That said, one small difference between the example and your function is that you are not using camelCase for its name.
-
@SGaist Hi, the minimal demo is that:
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++17 QMAKE_CXXFLAGS += /std:c++17 defineReplace(addCompilerOptions){ for(compileOption,ARGS){ QMAKE_CXXFLAGS += $$compileOption message("Insider option $$QMAKE_CXXFLAGS") #(1) } QMAKE_CXXFLAGS += $$ARGS return(true) } AddCompilerOptions(/openmp /fp:fast /diagnostics:caret) message($$quote(The option of compile $$QMAKE_CXXFLAGS)) #(2) # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS include(test_a/test_a.pri) f=quote(I like your) k=quote(like) str_a=$$str_member($$k,0,$$num_add($$str_size($$f),-1)) message("The size of Str: $$k ") # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ dialog.cpp \ main.cpp \ mainwindow.cpp \ test.cpp HEADERS += \ dialog.h \ mainwindow.h \ test.h FORMS += \ dialog.ui \ mainwindow.ui \ test.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target
It seems that my problem is not tremendously relative to camelCase.
In comment (1), It was signaled that these flag have been append the variable "QMAKE_CXX_FLAGS" in term of function message. However, In comment (2), these flags which are appended in function AddCompilerOptions are not printed. -
Update:
The warning 'addCompilerOptions' is not a recognized test function.' has been solved by myself in term of the change to code in following section:QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++17 QMAKE_CXXFLAGS += /std:c++17 defineReplace(addCompilerOptions){ for(compileOption,ARGS){ QMAKE_CXXFLAGS += $$compileOption } QMAKE_CXXFLAGS += $$ARGS return($$ARGS) } <----------------Changes-------------> testFlag=/openmp /fp:fast /diagnostics:care k=$$addCompilerOptions($$testFlag) <----------------Changes-------------> message($$quote(The option of compile $$QMAKE_CXXFLAGS)) # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS include(test_a/test_a.pri) f=quote(I like your) k=quote(like) str_a=$$str_member($$k,0,$$num_add($$str_size($$f),-1)) message("The size of Str: $$k ") # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ dialog.cpp \ main.cpp \ mainwindow.cpp \ test.cpp HEADERS += \ dialog.h \ mainwindow.h \ test.h FORMS += \ dialog.ui \ mainwindow.ui \ test.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target
However, there is no any effect to variable QMAKE_CXXFLAGS outside scope of addCompilerOptions.
-
Because it's not how you should use it. As the documentation explains: "this type of function should be used on the right-hand side of assignments (that is, as an operand)."
QMAKE_CXXFLAGS += /std:c++17 QMAKE_CXXFLAGS = $$addCompilerOptions(your_list_of_options)