0

I've got 2 CMakeLists.txt files in my project.

CMakeLists.txt

cmake_minimum_required(VERSION 3.2)
project(Game)

set(CMAKE_CXX_STANDARD 14)

include_directories(core)
add_subdirectory(core)

add_executable(${PROJECT_NAME} game/main.cpp)
target_link_libraries(${PROJECT_NAME} Core)

core/CMakeLists.txt

project(Core)    
set(SOURCE_FILES ecs/Component.hpp ecs/Destroyable.hpp ecs/Destroyable.cpp ecs/Entity.hpp ecs/Entity.cpp Game.cpp Game.hpp components/Sprite.hpp components/Sprite.cpp components/Transform.hpp components/Transform.cpp ecs/Serializable.hpp ecs/ComponentsCreator.cpp ecs/ComponentsCreator.hpp common/Utility.cpp common/Utility.hpp common/Logger.hpp common/Logger.cpp common/Vector2.hpp common/Vector2.cpp components/Camera.cpp components/Camera.hpp ecs/Component.cpp components/AnimationPlayer.cpp components/AnimationPlayer.hpp Animation.cpp Animation.hpp Frame.cpp Frame.hpp lib/termcolor.hpp lib/json.hpp)

add_library(${PROJECT_NAME} ${SOURCE_FILES})

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/")
find_package(SFML REQUIRED system window graphics network audio)
if (SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES})
endif()

And I'm getting this error while compiling "core/ecs/Entity.hpp:3:29: fatal error: SFML/Graphics.hpp: No such file or directory". Could someone take a look and tell me what's wrong with this?

2
  • Possible duplicate of cmake link glew header file Commented Jan 7, 2018 at 21:05
  • BTW, instead of link_libraries it should be target_link_libraries: you need to link target, marked with first argument, with libraries in other arguments. But the command you currently use links all futher targets (created after the command) with libraries-arguments. Commented Jan 7, 2018 at 21:09

1 Answer 1

0

Your script won't work this way, it's most likely broken due to you calling project() more than once.

The stuff inside core is handled as a standalone project, so the include directories etc. inside are never applied to your root.

Remove the first line project(Core) from the second file and define the target directly as Core. After that it should work, unless I've missed something else.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for answer, but how do I "define the target directly as Core"?

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.