我的项目中有一个.pro
文件,但是现在我想将其移植到CMakeLists.txt
文件中。我怎样才能做到这一点?
QT += core
QT -= gui
CONFIG += c++11
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
QT += network
SOURCES += main.cpp \
test_interface.cpp \
motomanlibrary.cpp \
processing.cpp
SOURCES += main.cpp \
test_interface.h \
motomanlibrary.h \
processing.h
最佳答案
QMake:必需的库。
QT += core
QT -= gui
QT += network
CMake:只需要添加。不需要排除(QT-= gui)。
find_package(Qt5Core REQUIRED)
find_package(Qt5Network REQUIRED)
QMake:其他编译器标志:
CONFIG += c++11
CMake:根据需要扩展编译器标志的列表。
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
QMake:源文件
SOURCES += main.cpp \
test_interface.cpp \
motomanlibrary.cpp \
processing.cpp
CMake:创建源文件列表
set(SOURCES
main.cpp
test_interface.cpp
motomanlibrary.cpp
processing.cpp
)
QMake:要包含的 header :
SOURCES += main.cpp \
test_interface.h \
motomanlibrary.h \
processing.h
CMake:只显示头文件在哪里。
include_directory(.) # or include_directory(${CMAKE_CURRENT_SOURCE_DIR})
include_directory(some/where/else)
QMake:要建立的目标:
TARGET = test
CMake:设置目标名称,添加源,链接所需的库。
add_executable(test ${SOURCES} )
qt5_use_modules(test Core Network) # This macro depends from the Qt version
# Should not be necessary
#CONFIG += console
#CONFIG -= app_bundle
#TEMPLATE = app
查看有关Convert qmake to cmake的更多详细信息
关于qt - 如何将qmake转换为cmake?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43763416/