0

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 ?

PrimRock
  • 1,076
  • 2
  • 15
  • 27
  • 1
    You could list the header files together with the source files for the [`add_executable`](https://cmake.org/cmake/help/latest/command/add_executable.html) command? Or possibly use the [`source_group`](https://cmake.org/cmake/help/latest/command/source_group.html) command? – Some programmer dude Mar 26 '20 at 04:32
  • @Someprogrammerdude It worked!......Though I could have sworn I tried adding the headers to``add_executable`` before... Not quite sure why it worked now... This maybe out the scope of this question, but do you by any chance have any idea of why I have a ``src`` folder within my ``src`` folder. Same thing with my include folder. For example, ``src/src/``. Its definitely not like that in my project hierarchy. Is it something CMake is causing ? – PrimRock Mar 26 '20 at 05:02
  • It might have to do with the Codelite IDE setup? I don't know, as I don't really use it myself. – Some programmer dude Mar 26 '20 at 05:07
  • @Someprogrammerdude It appears to be IDE related, because when I built the source for another IDE the file structure is totally different. You can post your first comment as the answer and I'll gladly accept it – PrimRock Mar 26 '20 at 05:21
  • There is a very similar question with several answers [here](https://stackoverflow.com/q/13703647/3987854). – Kevin Mar 26 '20 at 12:20

1 Answers1

1

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})
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621