PrimRock
PrimRock

Reputation: 1156

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

Say for example I have project hierarchy laid out like so...

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

How can I get my include files to show in my CodeLite project. It shows my src files perfectly fine, but the include folder is empty. Everything compiles and builds fine within the IDE, its just that the header includes are not visible in the project. What can I do to my CMakeLists to remedy this ?

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)

I searched the internet and came across this,

CMake: How to show headers in "Header files" in Visual Studio project?

and it works but GLOB_RECURSE is considered a bad practice. Is there an alternative ?

Upvotes: 0

Views: 550

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409432

The usual way to also include header files in a project is to also list them in the add_executable command.

Perhaps something like

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

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

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

Upvotes: 1

Related Questions