问题描述
我试图使用Clion IDE编译一个简单的程序使用Qt库,但我不知道如何配置 CMakeLists.txt
文件。 (我不熟悉cmake和工具链)
这是我当前的 CMakeLists.txt
文件:
I'm trying to use Clion IDE to compile a simple program using Qt library, but I can't figure out how to configure CMakeLists.txt
file. (I'm not familiar with cmake and toolchain)this is my current CMakeLists.txt
file:
cmake_minimum_required(VERSION 3.2)
project(MyTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(MyTest ${SOURCE_FILES})
# Define sources and executable
set(EXECUTABLE_NAME "MySFML")
add_executable(${EXECUTABLE_NAME} main.cpp)
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
endif()
配置为使用SFML库与FindSFML .cmake文件,它工作正常。 (我已经从一些教程复制这些文件)现在我想要一些帮助关于正确的 CMakeLists.txt
配置编译使用Qt库的程序(更有助于如果文件和
It's configured to use SFML library with a "FindSFML.cmake" file and it works fine. (I have copied these files from some tutorial) now I want some help regarding proper CMakeLists.txt
configuration to compile programs that are using Qt library (it's more helpful if the files and explanations are provided).
推荐答案
CMake
项目文件缺少Qt包。您必须添加:
Your CMake
project file is missing the Qt packages. You have to add:
find_package( Qt5Core REQUIRED )
find_package( Qt5Widgets REQUIRED )
find_package( Qt5Gui REQUIRED )
,然后
qt5_use_modules( MyTest Core Widgets Gui )
这篇关于在Clion中使用Qt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!