-
-
Save AnthoniG/a4c28ad8b151f8d4753ed505c4d0d1e2 to your computer and use it in GitHub Desktop.
Sample CMake Qt Project for CLion
This file contains hidden or 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
# | |
# sample CMakeLists.txt for a simple Qt project using CLion IDE | |
# shows how to use AUTOMOC, AUTOUIC | |
# | |
# sources are expected in source/ | |
# includes in include/ | |
# | |
cmake_minimum_required(VERSION 3.0) | |
set(TARGET_NAME Qttest) | |
project(${TARGET_NAME}) | |
# Instruct CMake to run moc automatically when needed | |
set(CMAKE_AUTOMOC ON) | |
set(CMAKE_AUTOUIC ON) | |
set(CMAKE_AUTORCC ON) | |
set(CMAKE_INCLUDE_CURRENT_DIR ON) | |
# Check the build type and ask the user to set concrete one | |
if(NOT CMAKE_BUILD_TYPE) | |
set(CMAKE_BUILD_TYPE RelWithDebInfo) | |
message(WARNING "CMAKE_BUILD_TYPE is not set, forcing to RelWithDebInfo") | |
endif() | |
# Set compiler flags | |
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU" OR ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") | |
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra") | |
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3") | |
set(CMAKE_CXX_FLAGS_RELEASE "-O3") | |
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g3") | |
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os") | |
endif() | |
set (CMAKE_EXE_LINKER_FLAGS=-fuse-ld=gold) | |
find_package(Qt5Core REQUIRED) | |
find_package(Qt5Widgets REQUIRED) | |
find_package(Qt5Network REQUIRED) | |
include_directories( | |
${CMAKE_CURRENT_BINARY_DIR} | |
${CMAKE_CURRENT_SOURCE_DIR} | |
"./include" | |
) | |
# Source files | |
set(SOURCES | |
src/main.cpp | |
src/mainwindow.cpp | |
src/playground.cpp | |
src/appcontext.cpp | |
) | |
# User interface files | |
set(FORMS | |
include/mainwindow.ui | |
include/aboutdialog.ui | |
) | |
# Resource files | |
#set(RESOURCES | |
# resources.qrc | |
# ) | |
# Shared libraries | |
set(LIBRARIES | |
Qt5::Core | |
Qt5::Widgets | |
Qt5::Network | |
) | |
# Generate additional sources with MOC and UIC | |
qt5_wrap_ui(UIC_SOURCES ${FORMS}) | |
#qt5_add_resources(RCC_SOURCES ${RESOURCES}) | |
# Set target | |
add_executable(${TARGET_NAME} ${SOURCES} ${HEADERS} ${UIC_SOURCES} ${RCC_SOURCES}) | |
# Link with libraries | |
target_link_libraries(${TARGET_NAME} ${LIBRARIES}) | |
# Installation | |
install(TARGETS ${TARGET_NAME} RUNTIME DESTINATION bin) | |
install(FILES resources/${TARGET_NAME}.png DESTINATION share/icons/hicolor/48x48/apps) | |
install(FILES ${TARGET_NAME}.desktop DESTINATION share/applications) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment