qmake file define variable
时间: 2023-11-24 21:06:42 浏览: 28
In a qmake (.pro) file, you can define variables using the `VARIABLE_NAME = value` syntax. For example:
```
# Define a variable
MY_PROJECT_NAME = MyAwesomeProject
# Use the variable in other parts of the .pro file
TARGET = $$MY_PROJECT_NAME
```
In the above example, we define a variable `MY_PROJECT_NAME` and set its value to `"MyAwesomeProject"`. We then use this variable in the `TARGET` variable, which is used to set the name of the output binary.
You can also use variables to define paths, compiler flags, and other project-specific settings. For example:
```
# Define a variable for the include directories
INCLUDEPATH += $$PWD/include
# Define a variable for the compiler flags
QMAKE_CXXFLAGS += -Wall -Wextra -pedantic
# Use the variables in other parts of the .pro file
SOURCES += src/main.cpp src/utils.cpp
HEADERS += include/utils.h
LIBS += -L$$PWD/lib -lmylib
```
In the above example, we define a variable for the include directories (`INCLUDEPATH`) and set its value to the `include` directory in the current project directory (`$$PWD/include`). We also define a variable for the compiler flags (`QMAKE_CXXFLAGS`) and set it to some common flags for warnings (`-Wall -Wextra -pedantic`).
We then use these variables in other parts of the .pro file. For example, we add some source files to the `SOURCES` variable, and include some header files in the `HEADERS` variable. We also include a library (`mylib`) in the `LIBS` variable, and specify its location using the `$$PWD` variable.