0

I'm new to C++ and CMake and started a big project. Im using VScode as my text editor and CMake as my build tool.

The problem is that i can include "SFML/Graphics.hpp in all my header files that has a source file with the same name, but in header-only files if i include "SFML/Graphics.hpp" or any other file that include "SFML/Graphics" cmake won't build and returns an error.

Here's is my code

Project Directory Tree

Game|> (root)
  |- CMakeLists.txt
  |> include
  |    |- BaseComponent.hpp (Header-only)
  |    |- TransformComponent.hpp (Header-only)
  |    |- CombatComponent.hpp (Header-only)
  |    |- MovementComponent.hpp (Header-only)
  |    |- Constants.hpp (Header-only)
  |    |- TimeUtils.hpp (Header-only)
  |    |- EcsManager.hpp
  |    |- EntityManager.hpp
  |    |- Game.hpp
  |    |- GameContext.hpp (Header-only)
  |    |- Scene.hpp (Header-only)
  |    |- GameScene.hpp
  |    |- System.hpp
  |    |- Input.hpp
  |    |- MovementSystem.hpp
  |    |- RenderableSystem.hpp
  |> src
  |    |- CMakeLists.txt
  |    |- main.cpp
  |    |- Game.cpp
  |    |- EntityManager.cpp
  |    |- SceneManager.cpp
  |    |- Input.cpp
  |    |- GameScene.cpp
  |    |> Ecs
       |    |- CMakeLists.txt
       |    |- EcsManager.cpp
       |    |- System.cpp
       |    |> Systems
            |    |- CMakeLists.txt
            |    |- MovementSystem.cpp
            |    |- RenderableSystem.cpp
  |    
  |> bin
  |> build

CMakeLists.txt - Root

project(RPG)
set(CMAKE_TOOLCHAIN_FILE         
"C:/Users/dante/vcpkg/scripts/buildsystems/vcpkg.cmake")

set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/bin")
set(SOURCES src/EntityManager.cpp src/Game.cpp src/GameScene.cpp 
src/main.cpp src/SceneManager.cpp src/Input.cpp)
include_directories("${PROJECT_SOURCE_DIR}/include")

add_subdirectory(src)

find_package(SFML 2.5.1 COMPONENTS REQUIRED graphics window system network 
audio)
find_package(nlohmann_json 3.2.0 REQUIRED)

add_executable(RPG ${SOURCES}) 
target_link_libraries(RPG sfml-graphics sfml-window sfml-system sfml- 
network sfml-audio)
target_link_libraries(RPG nlohmann_json::nlohmann_json)
target_link_libraries(RPG ECS)

CMakeLists.txt - src

add_subdirectory(Ecs)

CMakeLists.txt - Ecs

add_subdirectory(Systems)

add_library(ECS EcsManager.cpp System.cpp )

target_link_libraries(ECS ECS_SYSTEMS)

CMakeLists.txt - Systems

add_library(ECS_SYSTEMS MovementSystem.cpp RenderableSystem.cpp)

The erro that Cmake outputs is : 'SFML/Graphics.hpp': No such file or directory MSVC(C1083)

If i include "SFML/Graphics.hpp" in any "Any"Component Class it gives error If i include "SFML/Graphics.hpp" in a .hpp file that have a .cpp file associated with it and include that class in "Any"Component Class (or any other header-only) it gives error.

I can't find any solution to that in stackoverflow.

Don't judge my folder structure it was different when the error first came up... than i changed to that to see if the CMake would build.

1
  • I forgot to say that i USE VCPKG to manage my packages Commented Nov 12, 2019 at 2:47

1 Answer 1

0

You need to add the SFML include directory to the list of include directories.

After

find_package(SFML 2.5.1 COMPONENTS REQUIRED graphics window system network audio)

add the line

include_directories(${SFML_INCLUDE_DIR})
Sign up to request clarification or add additional context in comments.

8 Comments

Thta didn't solve the problem... still the same error. Im using vcpkg to manage packages @Jason
@DanteAraújo What happens if you add the line message(${INCLUDE_DIRECTORIES})?
it doesn't show anything. Any other message it shows normally but if i message the include_directories variable doesn't show anything.
if i added get_directory_property(prop INCLUDE_DIRECTORIES) message(${prop}) than it shows my project_source_dir/include
@DanteAraújo What happens if you add message(${SFML_INCLUDE_DIR})?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.