Setting up SFML with cmake.

Setting up sfml with cmake.

Audio Library Requirement :

sudo apt-get install libopenal-dev libsndfile1-dev libflac-dev libvorbis-dev

Root CMakeLists.txt file.

cmake_minimum_required(VERSION 3.15)

project(myapp)

add_subdirectory(vendors)
add_subdirectory(src)

src dir CMakeLists.txt

add_executable(app main.cpp)

target_link_libraries(
    app 
    PRIVATE
    SFML::Graphics

    )

vendors directory CMakeLists.txt

add_subdirectory(sfml)

vendors sfml directory CMakeLists.txt

include(FetchContent)

FetchContent_Declare(
    sfml
    GIT_REPOSITORY https://github.com/SFML/SFML.git
    GIT_TAG master
    )


FetchContent_MakeAvailable(sfml)

main.cpp code

#include <SFML/Window.hpp>

int main()
{
    sf::Window window(sf::VideoMode({800, 600}), "My window");

    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        while (const std::optional event = window.pollEvent())
        {
            // "close requested" event: we close the window
            if (event->is<sf::Event::Closed>())
                window.close();
        }
    }
}