赞
踩
set(CMAKE_INCLUDE_CURRENT_DIR ON) #包含编译目录
AUX_SOURCE_DIRECTORY(Dlg Dlg_cpp) #查找指定目录下的所有源文件,然后将结果存进指定变量名
FILE(GLOB file_h ./**) #加载文件夹下的所有文件
FILE(GLOB Dlg_file Dlg/**) #以当前CMakeLists路径作为相对路径
file(GLOB Dlg_h "Dlg/*.h") #可按路径增加子目录,但在vs中暂只显示一级目录
LIST(APPEND Dlg_file ${Dlg_h} ${Dlg_cpp} ${Dlg_ui}) #变量合并
set(CMAKE_PREFIX_PATH $ENV{Qt5}) #系统路径建议直接包含../lib/Qt5/.cmake文件
find_package(Qt5 COMPONENTS Core Gui Widgets Charts REQUIRED) # Qml Quick Network Xml
set(Qt5_DIR "${PROJECT_SOURCE_DIR}/Extern/Qt512/lib/cmake/Qt5") set(Qt5Core_DIR "${PROJECT_SOURCE_DIR}/Extern/Qt512/lib/cmake/Qt5Core") set(Qt5Gui_DIR "${PROJECT_SOURCE_DIR}/Extern/Qt512/lib/cmake/Qt5Gui") set(Qt5Widgets_DIR "${PROJECT_SOURCE_DIR}/Extern/Qt512/lib/cmake/Qt5Widgets") set(Qt5Charts_DIR "${PROJECT_SOURCE_DIR}/Extern/Qt512/lib/cmake/Qt5Charts") INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/Extern/Qt512/include/QtCharts") INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/Extern/Qt512/include/QtCore") INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/Extern/Qt512/include/QtGui") INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/Extern/Qt512/include/QtWidgets") INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/Extern/Qt512/include") LINK_DIRECTORIES("${PROJECT_SOURCE_DIR}/Extern/Qt512/lib") find_package(Qt5Core) find_package(Qt5Gui) find_package(Qt5Widgets) find_package(Qt5Charts) SET(file_lib Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Charts )
#set(CMAKE_AUTOMOC ON) #QObject派生的C++类也需要通过moc进行处理 生成目录下有Demo_automoc文件(去掉才能编过)
#set(CMAKE_AUTOUIC ON)
file(GLOB file_ui "./*.ui")
QT5_WRAP_UI(ui_FILES ${file_ui} )
set_property(GLOBAL PROPERTY USE_FOLDERS ON) #打开允许创建文件夹的开关 BUILD、Zero放在CMakePredefinedTargets
#set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets") #给cmake自动创建的工程重新命名(此步骤可以省略)
#set(CMAKE_BUILD_TYPE "Release") #Release需加引号
set(CMAKE_BUILD_TYPE Release CACHE STRING "set build type to Release")
add_compile_options("/utf-8")
set(CMAKE_CXX_STANDARD 11)
project(oeImageCenter) # VERSION 0.1 cmake_minimum_required(VERSION 2.6) set(CMAKE_BUILD_TYPE "Release") #Release需加引号 add_compile_options("/utf-8") INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/oeGraphicsView") #解决ui_MainWindow.h找不到MyGraphicsView INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/Core") INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/Gui") INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/Extern/opencv450/include") LINK_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/Extern/opencv450/lib") INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/Extern/libtiff") LINK_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/Extern/libtiff") INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/Extern/ImageShop/include") LINK_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/Extern/ImageShop/lib") INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/Extern/oeBase/include") LINK_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/Extern/oeBase/lib") include_directories(${PROJECT_BINARY_DIR}/Gui) #解决找不到ui_oeImageCenter.h set(CMAKE_CXX_STANDARD 11) set(CMAKE_AUTOMOC ON) #QObject派生的C++类也需要通过moc进行处理 生成目录下有Demo_automoc文件(去掉才能编过) set(CMAKE_AUTOUIC ON) set(CMAKE_PREFIX_PATH $ENV{Qt5}) #Qt5为系统环境变量名 Qt512 find_package(Qt5 COMPONENTS Core Gui Widgets Charts REQUIRED) # Qml Quick Network Xml add_subdirectory(Core) add_subdirectory(oeGraphicsView) add_subdirectory(Gui) SET(file_lib Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Charts #Qt5::Network #Qt5::Xml #CTKCore #CTKWidgets libtiff_64 opencv_world450#d ImageShop oeBase Core/Release/Core#Debug Gui/Release/Gui oeGraphicsView/Release/oeGraphicsView #bin目录下 ) #file(GLOB file_qrc "./*.qrc") oeImageCenter.qrc add_executable(${PROJECT_NAME} main.cpp ${Core} ${Gui} ${MyGraphicsView})# main.cpp ${file_} ${HEADERS} ${SOURCES} ${RESOURCES} ${QMLS} target_link_libraries(${PROJECT_NAME} ${file_lib}) #${PROJECT_NAME}
1.编译失败,需重新cmake、手动删除moc文件。
2.调用tianya,openssl报错。
Could NOT find OpenSSL
3.cmake工程不建议手动添加文件到项目。
VS工程右键添加类文件,声明不调用编译正常,new调用LNK2001报错(猜测cmake会将每个文件记录到工程文件,并按此演绎)。
需重新cmake。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。