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

时间:2018-09-20 11:20:50

标签: c++ qt cmake

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

  

此文件不属于任何项目

我知道它一定是CMakeLists.txt的内容,但是我不知道该怎么做,或者为什么它不自动包含在内。

cmake_minimum_required(VERSION 2.8)

project(S13V140_implementing_member_method)
add_executable(${PROJECT_NAME} "main.cpp")

???

2 个答案:

答案 0 :(得分:0)

以下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})

答案 1 :(得分:0)

要使CMake和Qt一起使用,请确保将 all 标头添加到源文件列表中。

set(sources "main.cpp" "my_header.h")
add_executable(${PROJECT_NAME} ${sources})
相关问题