I was trying to configure CMake to link the SFML libraries on my Windows computer, and am failing miserably.
My directory looks as follows
|-build
|__//Build stuff
|-cmake_modules
|__FindSFML.cmake
|-main.cpp
|-CmakeLists.txt
For some reason, while CMake is able to find SFML, it is unable to find the include directory of it. I run CMake as follows:
cmake .. -DCMAKE_PREFIX_PATH=C:/SFML-2.4.2
and my CMakeLists.txt looks as follows:
cmake_minimum_required(VERSION 3.9)
project(SFML-CmakeTest)
set(CMAKE_BUILD_TYPE Release)
set(EXECUTABLE_NAME "sfml_test_cmake")
add_executable(${EXECUTABLE_NAME} main.cpp)
set(SFML_FIND_PATH ${CMAKE_PREFIX_PATH})
set(SFML_INCLUDE_PATH "${SFML_FIND_PATH}/include")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
find_package(SFML 2.4 REQUIRED system window graphics network audio)
include_directories(${SFML_INCUDE_PATH})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
my main.cpp is as simple as it gets:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow testWindow{ sf::VideoMode{ 640, 480 }, "Test Window", sf::Style::Default };
while (testWindow.isOpen())
{
sf::Event winEvent;
while (testWindow.pollEvent(winEvent))
{
if (winEvent.type == sf::Event::Closed)
{
testWindow.close();
}
}
testWindow.clear();
testWindow.display();
}
}
Unfortunately, I get the VS error, unable to find SFML/Graphics.hpp. What am I doing wrong? My SFML is located in C:\SFML-2.4.2