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

Author Topic: Issues migrating an SFML project from Visual Studio to CMake  (Read 1210 times)

0 Members and 1 Guest are viewing this topic.

InterdimensionalCat

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Issues migrating an SFML project from Visual Studio to CMake
« on: October 24, 2020, 05:35:49 am »
I have been working on a relatively large project using SFML in Windows (Visual Studio) for a couple years, and I now potential developers who are using linux machines, and I want to make my project cross platform. I am using very few or no windows dependencies, but it seems like migrating the project over to Cmake is the best/only way to make the project cross platform.

I have been working on migrating the project and everything seems set up correctly, but I am getting an error saying "Cannot open include file: 'SFML\Graphics.hpp': No such file or directory", I assume this is an issue with linking the library through CMake, but I cannot figure out what I am doing wrong.

Here is my CMakeLists.txt:
# CMakeList.txt : CMake project for GameEngine2020, include source and define
# project specific logic here.
#
# set minimum version required for CMake
cmake_minimum_required (VERSION 3.8)

set(PROJECT_NAME "GameEngine2020")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

project(${PROJECT_NAME})

## If you want to link SFML statically
#set(SFML_STATIC_LIBRARIES TRUE)

## In most cases better set in the CMake cache
set(SFML_DIR "${CMAKE_CURRENT_LIST_DIR}/SFML/lib/cmake/SFML")

#file(GLOB ALL_REQUIRED_DLL "${CMAKE_CURRENT_LIST_DR}/SFML/bin/*.dll")
#file(COPY ${ALL_REQUIRED_DLL} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

set(SOURCE_FILES
ActionState.h
...
...(all the program files)...
...
TileSet.h
)

find_package(SFML 2.5 COMPONENTS graphics audio main network system window REQUIRED)
add_executable(${PROJECT_NAME} GameEngine2020.cpp GameEngine2020.h)
target_link_libraries(${PROJECT_NAME} sfml-graphics-d sfml-audio-d sfml-system-d sfml-window-d)

The rest of the code is on github here, but I think the issue is something within the CMakeLists.txt: https://github.com/InterdimensionalCat/2020GameEngine.git

EDIT: Solved, I was using ${CMAKE_CURRENT_LIST_DIR} when I should have been using ${PROJECT_SOURCE_DIR} not sure how I made that mistake


« Last Edit: October 24, 2020, 10:25:35 pm by InterdimensionalCat »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Issues migrating an SFML project from Visual Studio to CMake
« Reply #1 on: October 27, 2020, 11:13:21 am »
If you're working on cross-platform support, you should also change all your header includes to use forward-slashes (/) instead of backward-slashes (\). :)

I also recommend to set the SFML_DIR in your CMake cache instead of the CMake file itself, as on other systems, the location might be slightly different.

You don't need to have system and window in the find_package, as they're dependencies of graphics (and audio).
And finally, the linking should not have names with -d, those targets don't exist and CMake will decide whether it uses the release or debug library.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

InterdimensionalCat

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Issues migrating an SFML project from Visual Studio to CMake
« Reply #2 on: November 01, 2020, 04:33:08 am »
Thanks for the info. I figured out all of this when testing the program on linux over the past two days except the part about setting the SFML_DIR in the CMake cache. I am pretty new to cmake and I am not sure exactly how to do that. Is there any documentation explaining it?