Last active
October 4, 2018 05:12
-
-
Save Yihao-G/63203d36e45a890478fefdd1763b39c9 to your computer and use it in GitHub Desktop.
CMakeLists.txt for Qt 5 Projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TESTED ONLY ON WINDOWS PLATFORM WITH CLION IDE | |
# | |
# IF SUCCEEDED ON BUILDING BUT FAILED ON RUNNING WITH EXIT CODE 1073741515 (0xC0000135), TRY ADDING | |
# X:\Qt\5.9.2\mingw53_32\bin (CHANGE THIS TO YOUR CORRESPONDING DIRECTORY) TO PATH ENVIRONMENT VARIABLE AND REBOOT YOUR COMPUTER. | |
# | |
# THIS FILE WAS MODIFIED FROM https://github.com/jasondegraw/Qt-CMake-HelloWorld/blob/master/CMakeLists.txt | |
cmake_minimum_required(VERSION 3.8.2) | |
project(p2p_chat) # CHANGE THE PROJECT NAME HERE IF NECESSARY, DON'T FORGET TO CHANGE ANY OTHER APPEARANCES AS WELL | |
# Find includes in the build directories | |
set(CMAKE_INCLUDE_CURRENT_DIR ON) | |
# Turn on automatic invocation of the MOC | |
set(CMAKE_AUTOMOC ON) | |
set(CMAKE_PREFIX_PATH X:/Qt/5.9.2/mingw53_32/lib/cmake) # CHANGE TO YOUR CORRESPONDING DIRECTORY | |
# Add a compiler flag | |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") | |
# Make this a GUI application on Windows | |
if(WIN32) | |
set(CMAKE_WIN32_EXECUTABLE ON) | |
endif() | |
# Find the QtWidgets library | |
find_package(Qt5Widgets REQUIRED) | |
# NOTE: as our assignment needs Qt Network model, find QtNetwork lib as well | |
# IF USE THIS NOT FOR THIS PROJECT, REMOVE IT FOR FASTER INDEXING | |
find_package(Qt5Network REQUIRED) | |
# If you need any other models, import them here and also add them to target_link_libraries (the last line) | |
#find_package(Qt5ModelName REQUIRED) | |
# Generate code from ui files | |
qt5_wrap_ui(UI_HEADERS chatwindow.ui) # MORE .ui FILES ADD INTO IT, SEPARATED BY A SPACE | |
# Generate rules for building source files from the resources | |
qt5_add_resources(QRCS resources.qrc) # MORE .qrc FILES ADD INTO IT, SEPARATED BY A SPACE | |
set(SOURCE_FILES | |
Networking/client.cpp | |
Networking/client.h | |
Networking/connection.cpp | |
Networking/connection.h | |
Networking/peermanager.cpp | |
Networking/peermanager.h | |
Networking/server.cpp | |
Networking/server.h | |
chatwindow.cpp | |
chatwindow.h | |
htmldelegate.cpp | |
htmldelegate.h | |
main.cpp | |
message.cpp | |
message.h | |
messagefactory.cpp | |
messagefactory.h | |
textmessage.cpp | |
textmessage.h) # ADD ALL .h AND .cpp FILES HERE, NO NEED TO ADD .ui OR .qrc FILES HERE | |
# Tell CMake to create the executable | |
add_executable(p2p_chat ${SOURCE_FILES} ${UI_HEADERS} ${QRCS}) | |
# Add the Qt5 Widgets, as well as Qt5 Network for linking | |
target_link_libraries(p2p_chat Qt5::Widgets Qt5::Network Qt5::WinMain) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment