如何在显示包含文件夹的同时让 CMake 构建我的项目?

How can I get CMake to build my project while showing the include folder?

举例来说,我的项目层次结构是这样布置的...

CMAKE_PROJECT/
|
   |-build/
   |-include/
       |-Entity.hpp
       |-Scene.hpp
   |-src/
       |-Entity.cpp
       |-Scene.cpp
   CMakeLists.txt

如何让我的包含文件显示在我的 CodeLite 项目中。它显示我的 src 文件非常好,但 include 文件夹是空的。 IDE 中的所有内容都可以正常编译和构建,只是 header 包含在项目中不可见。我可以对我的 CMakeLists 做些什么来解决这个问题?

cmake_minimum_required(VERSION 3.13.4)

project(CMake_Project)
set(EXECUTABLE_NAME "CMake_Project")

set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD_REQUIRED YES)
set (CMAKE_CXX_EXTENSIONS OFF)
set (CMAKE_BUILD_TYPE Debug)

set(SOURCES src/Entity.cpp 
            src/Scene.cpp)

include_directories(include)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../")

set(SFML_DIR "C:\libs\SFML-2.5.1\lib\cmake\SFML")
set(SFML_STATIC_LIBRARIES TRUE)

find_package(SFML 2.5 COMPONENTS  audio network graphics window system REQUIRED)
add_executable(${EXECUTABLE_NAME} ${SOURCES})
target_link_libraries(${EXECUTABLE_NAME} sfml-audio sfml-network sfml-graphics sfml-window sfml-system)

我在网上搜索了一下,发现了这个,

它有效,但 GLOB_RECURSE 被认为是一种不好的做法。有替代方案吗?

在项目中同时包含头文件的通常方法是在 add_executable 命令中也列出它们。

也许像

set(SOURCES src/Entity.cpp 
            src/Scene.cpp)

set(HEADERS include/Entity.hpp 
            include/Scene.hpp)

add_executable(${EXECUTABLE_NAME} ${SOURCES} ${HEADERS})