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

Author Topic: All resources failing to load upon building project with CMake  (Read 3347 times)

0 Members and 1 Guest are viewing this topic.

TheSpaceEvader

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
This is my first time attempting to build my game with CMake, and i've followed the steps on this (https://github.com/SFML/SFML/wiki/Tutorial%3A-Build-your-SFML-project-with-CMake) tutorial up til now. However, once it came to the very final steps ("cmake CMakeLists.txt", "cmake --build .") my build appears to have failed loading any of my assets. This includes, pictures, sounds & fonts, while all SFML assets appear to be drawing as usual, I cant seem to figure it out. I've attempted to directly reference their file paths in the CMakeLists.txt file, in the hopes that even one variation of the different file paths would work, but no luck. It might go without saying, but run from within my IDE (CLion) the project runs perfectly. Just incase it's relevant (and as there's not really much code I can show here), I've included my CMakeLists.txt code, just incase that might help:

cmake_minimum_required(VERSION 3.8)

# Enable debug symbols by default
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
endif()

project(Sk_iver)

set(CMAKE_CXX_STANDARD 11)

# Set version information in a config.h file
set(myproject_VERSION_MAJOR 1)
set(myproject_VERSION_MINOR 0)
configure_file(
        "${PROJECT_SOURCE_DIR}/config.h.in"
        "${PROJECT_BINARY_DIR}/config.h"
)
include_directories("${PROJECT_BINARY_DIR}")

set(SOURCE_FILES
        Font
        Resources
        newDiver_spritesheet3.png
        Font/Arial_Unicode.ttf
        main.cpp
        Diver.cpp
        Diver.h
        README.md Ring.cpp Ring.h HandleEvents.cpp HandleEvents.h Background.cpp Background.h Particle.cpp Particle.h Particles.cpp Particles.h Game.cpp Game.h)

# Define sources and executable
set(EXECUTABLE_NAME "SK_IVER")
add_executable(${EXECUTABLE_NAME} ${SOURCE_FILES})

# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
find_package(SFML REQUIRED system window graphics network audio)
if (SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(SK_IVER ${SFML_LIBRARIES})
endif()

# Install target
install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin)

# CPack packagin
include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
set(CPACK_PACKAGE_VERSION_MAJOR "${myproject_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${myproject_VERSION_MINOR}")
include(CPack)
 
« Last Edit: July 05, 2018, 06:08:12 pm by TheSpaceEvader »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: All resources failing to load upon building project with CMake
« Reply #1 on: July 05, 2018, 08:51:30 am »
Your question seems a bit odd. Why are you adding resource files to the source file listing? Why do you need resource files when building your application?

SFML searches relative paths starting from the working directory. So if you're manually executing the application, you need to make sure the resources are next to the executable. If you run it through CLion, CLion may specify it's own working directory.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

TheSpaceEvader

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: All resources failing to load upon building project with CMake
« Reply #2 on: July 05, 2018, 12:57:54 pm »
I agree that this seems unnecessary, I did initially forgo mentioning any assets in the source files section, given that they were already directly mentioned in their respective files in the project:
// Title & Score Font assignment:
    if(!font.loadFromFile("Font/Arial_Unicode.ttf"))
        std::cout << "ERROR: Could not load font file." << std::endl;
but for whatever reason, when I attempt to run the build (whether it is mentioned or not in SOURCE_FILES section of CMakeLists.txt), all assets fail to load:
/Users/TheSpaceEvader/Documents/C++\ Projects/Sk-iver/SK_IVER ; exit;
Failed to open sound file "Resources/Sounds/nice_music.ogg" (couldn't open stream)
ERROR: could not load audio file from file path
Failed to load font "Font/Arial_Unicode.ttf" (failed to create the font face)
ERROR: Could not load font file.
Failed to load image "newDiver_spritesheet3.png". Reason: Unable to open file
ERROR: Could not load diver texture from file path.
Failed to load image "Resources/Images/skydiving_placeholder.jpg". Reason: Unable to open file
ERROR: Could not load diver texture from file path.
Window Active

[Process completed]

TheSpaceEvader

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: All resources failing to load upon building project with CMake
« Reply #3 on: July 05, 2018, 06:07:39 pm »
Why are you adding resource files to the source file listing? Why do you need resource files when building your application?
Just to be clear, my initial thinking was that I would not have to, as these resources are directly called to in my code. However, when the project is built by CMake, these resource files do not appear to have been packaged along with all the other project files. This results in a built program which, when run, show's a black screen with only any SFML objects being drawn, along with all the exceptions being raised in terminal, as can be seen here:


I am really unsure what the next step, and I apologise if this is not the place to ask questions like this, but I'm quite desperate to get this working and am now running out of ideas to potentially fix it. Thanks in advance if anyone can provide any suggestions or even just point me in the right direction!
« Last Edit: July 05, 2018, 06:10:29 pm by TheSpaceEvader »