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

Author Topic: SFML with CMake help!  (Read 3270 times)

0 Members and 1 Guest are viewing this topic.

Aganthor

  • Newbie
  • *
  • Posts: 2
    • View Profile
SFML with CMake help!
« on: September 08, 2018, 03:57:42 am »
Hello everyone!
My first time posting :)
Here is my problem: CMake is finding the new SFML 2.5 Cmake config file. But it doesn't let the compiler find the SFML header file.

Here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.11)

project(AgEngine VERSION 0.1 LANGUAGES CXX)

add_executable(AgEngine main.cpp Game.cpp)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

target_compile_options(AgEngine PRIVATE -Werror)

target_compile_features(AgEngine PRIVATE cxx_std_17)

# Find SFML
find_package(SFML 2.5 COMPONENTS audio graphics window system REQUIRED)

#Include SOL2 header files
include_directories(${CMAKE_SOURCE_DIR}/sol2/include)

#add_subdirectory(ECS)

target_link_libraries(AgEngine
        PUBLIC
        sfml-graphics sfml-audio sfml-window sfml-system )

And here is the ouput of my make command :
build make
-- Found SFML 2.5.0 in /usr/lib64/cmake/SFML
-- Configuring done
-- Generating done
-- Build files have been written to: /home/lucb/Programming/cpp/AgEngine/build
Scanning dependencies of target AgEngine
[ 33%] Building CXX object CMakeFiles/AgEngine.dir/main.cpp.o
In file included from /home/lucb/Programming/cpp/AgEngine/main.cpp:3:
/home/lucb/Programming/cpp/AgEngine/Game.h:3:10: fatal error: SFML\Window.hpp: No such file or directory
 #include <SFML\Window.hpp>
          ^~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/AgEngine.dir/build.make:63: CMakeFiles/AgEngine.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/AgEngine.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Here is my compile_commands.json file:
[
{
  "directory": "/home/lucb/Programming/cpp/AgEngine/build",
  "command": "/usr/bin/c++   -I/home/lucb/Programming/cpp/AgEngine/sol2/include    -Werror -std=gnu++17 -o CMakeFiles/AgEngine.dir/main.cpp.o -c /home/lucb/Programming/cpp/AgEngine/main.cpp",
  "file": "/home/lucb/Programming/cpp/AgEngine/main.cpp"
},
{
  "directory": "/home/lucb/Programming/cpp/AgEngine/build",
  "command": "/usr/bin/c++   -I/home/lucb/Programming/cpp/AgEngine/sol2/include    -Werror -std=gnu++17 -o CMakeFiles/AgEngine.dir/Game.cpp.o -c /home/lucb/Programming/cpp/AgEngine/Game.cpp",
  "file": "/home/lucb/Programming/cpp/AgEngine/Game.cpp"
}
]%

I'm on Manjaro and have SFML installed with the package manager, so no fancy directories.

It looks like CMake isn't able to tell my compiler where the SFML include files are even though it did find the SFMLConfig.cmake..

Can anybody help me?

Thanks in advance.
Aganthor!


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: SFML with CMake help!
« Reply #1 on: September 08, 2018, 08:10:54 am »
Use forward slashes in your code, i.e. <SFML/Window.hpp>. While Windows may be able to deal with backslashes, Linux like environments don't. Since Windows can also deal with forward slashes, there's essentially no point in ever using backslashes. ;)
« Last Edit: September 08, 2018, 12:54:29 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Aganthor

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: SFML with CMake help!
« Reply #2 on: September 08, 2018, 12:40:57 pm »
Oh my god!

The problem was so obvious that it evaded me. Thank you so much  8)

Aganthor!

Use forward slashes in your code, i.e. <SFML/Window.hpp>. While Windows may be able to deal with backslashes, Linux like environments don't. Since Windows can also deal with forward slashes, there's essentially no point in every using backslashes. ;)