标签:cmakefile.txt qt5.3 static link
project(ovw)
cmake_minimum_required(VERSION 2.8)
# turn on show compile cmd line
SET( CMAKE_VERBOSE_MAKEFILE on )
SET(CMAKE_PREFIX_PATH "F:/Qt5.3.1/win32_static_2013")
# Set source dir of cpp
SET(SRC_DIR ${PROJECT_SOURCE_DIR}/..)
SET(QTLIB_DIR "F:/Qt5.3.1/win32_static_2013")
#to set compiler flag
if(WIN32)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
else()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -D_OS_LINUX_")
#to link static
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall")
endif()
#create qtplugin file
SET(plugin_cpp "${CMAKE_BINARY_DIR}/qt_plugin_moc.cpp")
FILE(WRITE ${plugin_cpp} " #include <QtPlugin>\n")
FILE(APPEND ${plugin_cpp} "Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)\n")
#FILE(APPEND ${plugin_cpp} "Q_IMPORT_PLUGIN(AccessibleFactory)\n")
#FILE(APPEND ${plugin_cpp} "Q_IMPORT_PLUGIN(QDDSPlugin)\n")
#FILE(APPEND ${plugin_cpp} "Q_IMPORT_PLUGIN(QICNSPlugin)\n")
#FILE(APPEND ${plugin_cpp} "Q_IMPORT_PLUGIN(QICOPlugin)\n")
#FILE(APPEND ${plugin_cpp} "Q_IMPORT_PLUGIN(QJp2Plugin)\n")
#FILE(APPEND ${plugin_cpp} "Q_IMPORT_PLUGIN(QMngPlugin)\n")
#FILE(APPEND ${plugin_cpp} "Q_IMPORT_PLUGIN(QTgaPlugin)\n")
#FILE(APPEND ${plugin_cpp} "Q_IMPORT_PLUGIN(QTiffPlugin)\n")
#FILE(APPEND ${plugin_cpp} "Q_IMPORT_PLUGIN(QWbmpPlugin)\n")
#FILE(APPEND ${plugin_cpp} "Q_IMPORT_PLUGIN(QWebpPlugin)\n")
#Set Output dir
SET(EXECUTABLE_OUTPUT_PATH ${SRC_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${SRC_DIR}/bin)
#Set Include dir
INCLUDE_DIRECTORIES(
${SRC_DIR}
# ${SRC_DIR}/Controls
# ${SRC_DIR}/rapidxml
)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
cmake_policy(SET CMP0020 NEW) # no need to set link to qtmain.lib
find_package(Qt5Widgets REQUIRED)
# The Qt5Widgets_INCLUDES also includes the include directories for
# dependencies QtCore and QtGui
include_directories(${Qt5Widgets_INCLUDES})
# We need add -DQT_WIDGETS_LIB when using QtWidgets in Qt 5.
add_definitions(${Qt5Widgets_DEFINITIONS})
# Executables fail to build with Qt 5 in the default configuration
# without -fPIE. We add that here.
set(CMAKE_CXX_FLAGS "${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
aux_source_directory(${SRC_DIR} SRC_LIST)
#aux_source_directory(${SRC_DIR}/Controls Control_LIST)
qt5_wrap_ui(ui_FILES ${SRC_DIR}/MainWindow.ui)
#QT5_ADD_RESOURCES(RESOURCES ${SRC_DIR}/pic.qrc)
#LINK_DIRECTORIES(${QTLIB_DIR}/lib)
LINK_DIRECTORIES(${QTLIB_DIR}/plugins/platforms)
LINK_DIRECTORIES(${QTLIB_DIR}/lib)
LINK_DIRECTORIES(${QTLIB_DIR}/plugins/imageformats)
LINK_DIRECTORIES(${QTLIB_DIR}/plugins/accessible)
#add_executable(${PROJECT_NAME} ${SRC_LIST} ${Control_LIST} ${RESOURCES})
add_executable(${PROJECT_NAME} WIN32 ${SRC_LIST} ${plugin_cpp} ${ui_FILES} )
# Use the Widgets module from Qt 5
qt5_use_modules(${PROJECT_NAME} Widgets)
set(QT5_LIBS Ws2_32 opengl32 imm32 winmm Qt5PlatformSupportd qwindowsd qtaccessiblewidgetsd)
target_link_libraries(${PROJECT_NAME} ${QT5_LIBS})
QT static link App cmake CMakeLists.txt,布布扣,bubuko.com
QT static link App cmake CMakeLists.txt
标签:cmakefile.txt qt5.3 static link
原文地址:http://sam19531.blog.51cto.com/8860634/1532837