Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Masalan

Pages: [1]
1
General / Re: CMake include problem
« on: June 15, 2021, 08:30:13 pm »
Thank you, I'll definetely try it. Thanks a lot for help.

2
General / Re: CMake include problem
« on: June 13, 2021, 06:50:00 am »
You would need to add this to your CMake script.

target_link_libraries("window" PUBLIC
    "sfml-graphics"
    "sfml-audio"
)
 

Thanks for the reply.

I have solved it by adding add_compile_options(-I c:/SFML/include/) before add_subdirectory(src)

Your solution is good, but what if I have much more libs? Is there any flexible solution than adding sfml libs to every lib I wrote on my own?

3
General / CMake include problem
« on: June 10, 2021, 09:06:35 pm »
Hello. Working on Windows. Im trying to dive in gamedev, but this thing is blocking me.
Im trying to include "SFML/Graphics.hpp" in one of my header files, located in src folder. Main.cpp is located in the same directory.
#pragma once

#include <SFML/Graphics.hpp>

class Window
{
public:
    Window(const std::string& window_name);

    void update();

    void beginDraw();
    void Draw(const sf::Drawable& drawable);
    void endDraw();

    bool isOpen() const;

private:
    sf::RenderWindow window;
}
 
This is the trouble header. When compiling it says that it cant find SFML/Graphics.

CMakeLists.txt, located out of src folder.
cmake_minimum_required(VERSION 3.20.3)

project(SNAKE)

add_subdirectory(src)


set(SFML_DIR "c:\\SFML\\lib\\cmake\\SFML\\")
find_package(SFML 2.5 COMPONENTS graphics audio REQUIRED)
target_link_libraries(${PROJECT_NAME} sfml-graphics sfml-audio)
 

window.hpp is located in src folder. CMakeLists.txt in src folder:
add_executable(${PROJECT_NAME} main.cpp)


add_library(window window.cpp window.hpp)


set(LIBRARIES window)
target_link_libraries(${PROJECT_NAME} ${LIBRARIES})
 

Error log:
In file included from E:\GameDev\SFML\Snake\src\window.cpp:1:
E:\GameDev\SFML\Snake\src\window.hpp:3:10: fatal error: SFML/Graphics.hpp: No such file or directory
 #include <SFML/Graphics.hpp>
 

Whats interesting, main.cpp located in the same directory has no trouble including "SFML/Graphics".
Im new to cmake and dont know how things work. Can someone help me to make "window.hpp" include "SFML/Graphics.hpp" correctly?

Pages: [1]