如何在 CMakeLists.txt Qt Creator 中包含头文件?

How to include header files in CMakeLists.txt in Qt Creator?

本文关键字:包含头 文件 Creator Qt CMakeLists txt      更新时间:2023-10-16

我正在使用Qt Creator来学习C++,没有使用Qt库的任何内容,我只是使用IDE。我创建了一个头文件,但它一直说

此文件不是任何项目的一部分

我知道它一定是CMakeList的东西.txt但是我不知道该怎么做,或者为什么它没有自动包含。

cmake_minimum_required(VERSION 2.8)
project(S13V140_implementing_member_method)
add_executable(${PROJECT_NAME} "main.cpp")
???

为了使 CMake 和 Qt 协同工作,请确保将所有标头添加到源文件列表中。

set(sources "main.cpp" "my_header.h")
add_executable(${PROJECT_NAME} ${sources})

以下CMakeLists.txt应该适合您:

cmake_minimum_required(VERSION 2.8)
# define the project name
project(S13V140_implementing_member_method)
# find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# C++11 support - else we run into issues with the non-static nullptr-assignment
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# put all sources into one variable: no distinction between h, cpp and ui (or qrc)
set(SOURCES
main.cpp
)
# create the final result
add_executable(S13V140_implementing_member_method ${SOURCES})