Code Monkey home page Code Monkey logo

cmake-sfml-project's Introduction

SFML logo

SFML — Simple and Fast Multimedia Library

SFML is a simple, fast, cross-platform and object-oriented multimedia API. It provides access to windowing, graphics, audio and network. It is written in C++, and has bindings for various languages such as C, .Net, Ruby, Python.

State of Development

Development is focused on the next major version in the master branch. No more features are planned for the 2.x release series.

  • The master branch contains work in progress for the next major version SFML 3. As such it's considered unstable, but any testing and feedback is highly appreciated.
  • The 2.6.1 tag is the latest official SFML release and will be the last minor release in the 2.x series.

CMake Template

The easiest way to get started with SFML is our CMake-based project template. This template will automatically download and build SFML alongside your own application. Read the README for full instructions on how to use it.

Download

  • You can get the latest official release on SFML's website.
  • You can also get the source code of the current development version from the Git repository.
  • Alternatively, you can get the latest snapshot / artifact builds from the artifacts storage.

Install

Follow the instructions of the tutorials, there is one for each platform/compiler that SFML supports.

Learn

There are several places to learn SFML:

Community

Here are some useful community links:

Contribute

SFML is an open-source project, and it needs your help to go on growing and improving. If you want to get involved and suggest some additional features, file a bug report or submit a patch, please have a look at the contribution guidelines.

Authors

License

The SFML libraries and source code are distributed under the zlib/libpng license. See license.md. External libraries used by SFML are distributed under their own licenses.

In short, SFML is free for any use (commercial or personal, proprietary or open-source). You can use SFML in your project without any restriction. You can even omit to mention that you use SFML -- although it would be appreciated.

External libraries used by SFML

cmake-sfml-project's People

Contributors

christhrasher avatar expl0it3r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cmake-sfml-project's Issues

Add helper script for installing Ubuntu deps

It's common that Ubuntu users are missing some packages they need to install. Let's put that all in a simple shell script so they don't have to dig into the CI script or ask on Discord about it. The CI pipeline can use this script too to ensure it's continuously up to date.

In the future we could extend this to work on Fedora or other Linux distros as well.

Installing the target also installs SFML files

It's kind of a common problem with FetchContent that it also pulls in all the install instructions from the fetched content.
There some workarounds with manual add_subdirectory and EXCLUDE_FROM_ALL, not sure what's the best solution.

fatal error: 'freetype/config/ftheader.h' file not found #include <freetype/config/ftheader.h>

I am new to SFML and have started with following instruction on this page https://www.sfml-dev.org/tutorials/2.6/start-cmake.php. I was able to get all the setup done except running the last build command fails.

When I run the build command I get this error

cmake --build build

[ 14%] Built target sfml-system
[ 48%] Built target sfml-window
[ 49%] Building CXX object _deps/sfml-build/src/SFML/Graphics/CMakeFiles/sfml-graphics.dir/Font.cpp.o
In file included from /Users/subham/Desktop/code/SFML/cmake-sfml-project/build/_deps/sfml-src/src/SFML/Graphics/Font.cpp:35:
/Library/Frameworks/Mono.framework/Headers/ft2build.h:56:10: fatal error: 'freetype/config/ftheader.h' file not found
#include <freetype/config/ftheader.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Frameworks/Mono.framework/Headers/ft2build.h:56:10: note: did not find header 'config/ftheader.h' in framework 'freetype' (loaded from '/Users/subham/Desktop/code/SFML/cmake-sfml-project/build/_deps/sfml-src/extlibs/libs-osx/Frameworks')
1 error generated.
make[2]: *** [_deps/sfml-build/src/SFML/Graphics/CMakeFiles/sfml-graphics.dir/Font.cpp.o] Error 1
make[1]: *** [_deps/sfml-build/src/SFML/Graphics/CMakeFiles/sfml-graphics.dir/all] Error 2
make: *** [all] Error 2

Copy openal32.dll alongside the executable

Anyone using the Audio module on Windows is going to run into this problem. Because there is no corresponding CMake target for that DLL, CMake can't know to automatically copy it like it does all other DLLs. An upstream fix to SFML/SFML would be preferred but maybe for now we automatically copy that DLL whenever someone is using Windows.

sfml-graphics-2.dll could not be found

I tried using this template for building my school assignment using CMake, which works great on either MacOS or Linux.
However, when using it on Windows, I just keep getting this error. I've tried it with several devices. Everything builds correctly, and I can find the .dll in the _deps folder. Am I missing something?

The install target includes all SFML options, including pkg-config and cmake configuration

The default installation includes all of the SFML development information. I'm

git clone https://github.com/SFML/cmake-sfml-project.git
cd cmake-sfml-project/
mkdir build && cd build
cmake ..
make -j
make install

On ubuntu this gives me

[100%] Built target sfml-audio
Install the project...
-- Install configuration: ""
CMake Error at _deps/sfml-build/cmake_install.cmake:54 (file):
  file cannot create directory: /usr/local/lib/pkgconfig.  Maybe need
  administrative privileges.
Call Stack (most recent call first):
  cmake_install.cmake:47 (include)


make: *** [Makefile:120: install] Error 1

Which, yes, with admin privileges would work. But also that would be installing SFML and not the binary. You can make this go away by specifying an install prefix cmake -DCMAKE_INSTALL_PREFIX=install .. but then you're still installing the SFML stuff.

Is that expected? If not, how can I prevent that from happening?

Clarify usage instructions

Specify what directory to run CMake commands from

I never mentioned that you have to run those CMake commands from the same directory as the repo. It's fair to assume someone may assume you can run those from anywhere.


Explicitly mention that users must clone the repo they made

This is never explicitly mentioned and I can understand why someone new to GitHub may think they just need to copy a few files to their computer.

Add branch that includes ImGui and SFML-ImGui

It takes another ~10 lines of CMake to incorporate those two projects plus some tweaks to main.cpp to demonstrate basic usage. It may be worth adding a branch that demonstrates that so those who want to use ImGui have something to reference. The build instructions would be the same.

Clarify that non sfml-graphics libraries need to be added to CMakeList

The CMakeList includes the sfml-graphics library, but not the others, such as sfml-audio. A new user would not understand that these are different libraries that need to be specified independently.

Suggestion 1: Add the rest of the libraries to the CMakeList.txt
Suggestion 2: Add instructions to the README.md for how to change CMakeList.txt to link to these libraries

OpenAL32 module created without symbols

I'm using the CMakeLists.txt template from the master branch with this only relevant modification:

target_link_libraries(CMakeSFMLProject PRIVATE sfml-graphics sfml-audio)
file(GLOB DATA
  "${PROJECT_SOURCE_DIR}/data/*"
)
file(COPY ${DATA} DESTINATION "${PROJECT_BINARY_DIR}")

In main.cpp I have this relevant code:

sf::SoundBuffer buf;
if (!buf.loadFromFile("sound.wav"))
  return -1;
sf::Sound sound;
sound.setBuffer(buf);
sound.play();

Compiling it on WIndows 10 with MSVC on x64 Native Tools Command Prompt for VS 2022:

cmake -S . -B build
cmake --build build --config Release
.\build\bin\Release\CMakeSFMLProject.exe

The exe is built, but when I try to run it, Windows gives me the helpful error message: "The app could not be initialized correctly (0xc000007b)".
Running it in Visual Studio, the debug output yields (in portuguese):

"CMakeSFMLProject.exe" (Win32): Carregado "C:\Users\<long_path>\SFML\out\build\x64-release-windows\bin\openal32.dll". O módulo foi criado sem símbolos.
"CMakeSFMLProject.exe" (Win32): Não carregado "C:\Users\<long_path>\SFML\out\build\x64-release-windows\bin\openal32.dll"

Which translates to something like:

"CMakeSFMLProject.exe" (Win32): Loaded "C:\Users\<long_path>\SFML\out\build\x64-release-windows\bin\openal32.dll". The module was created without symbols.
"CMakeSFMLProject.exe" (Win32): Not loaded "C:\Users\<long_path>\SFML\out\build\x64-release-windows\bin\openal32.dll"

The error does not occur if I don't use/link sfml-audio.

I was able to make OpenAL32 work with the following script:

# Add OpenAL32 (required by sfml-audio on Windows)
if(WIN32)
    set(OPENAL32_URL "https://openal-soft.org/openal-binaries/openal-soft-1.23.1-bin.zip")
    set(OPENAL32_ZIP_PATH "${CMAKE_BINARY_DIR}/openal-soft.zip")
    set(OPENAL32_DIR "${CMAKE_BINARY_DIR}/OpenAL32")
    set(OPENAL32_PATH "${OPENAL32_DIR}/openal-soft-1.23.1-bin")
    if(NOT EXISTS ${OPENAL32_DIR})
        file(DOWNLOAD ${OPENAL32_URL} ${OPENAL32_ZIP_PATH})
        execute_process(COMMAND powershell -Command "Expand-Archive \"${OPENAL32_ZIP_PATH}\" -DestinationPath \"${OPENAL32_DIR}\"")
        file(RENAME "${OPENAL32_PATH}/bin/Win64/soft_oal.dll" "${OPENAL32_PATH}/bin/Win64/OpenAL32.dll")
        file(REMOVE ${OPENAL32_ZIP_PATH})
    endif()
    add_library(OpenAL32 SHARED IMPORTED)
    set_target_properties(OpenAL32 PROPERTIES
        IMPORTED_LOCATION "${OPENAL32_PATH}/bin/Win64/OpenAL32.dll"
        IMPORTED_IMPLIB "${OPENAL32_PATH}/libs/Win64/OpenAL32.lib"
    )
    target_link_libraries(CMakeSFMLProject PRIVATE OpenAL32)
endif()
if (WIN32 AND BUILD_SHARED_LIBS)
    add_custom_command(TARGET CMakeSFMLProject POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:CMakeSFMLProject> $<TARGET_FILE_DIR:CMakeSFMLProject> COMMAND_EXPAND_LISTS)
endif()

But it requires fetching from openal-soft.org, which is slow and I don't know if it would violate any licenses.
Since the dll from openal-soft works, I think the openal binary in ${SFML_SOURCE_DIR}/extlibs/bin/$<IF:$<BOOL:${ARCH_64BITS}>,x64,x86>/openal32.dll might be the problem.

Consider disabling warnings as errors within SFML

SFML/SFML#2464

STB Image 2.28 included some new code that triggers an MSVC warning related to lossy conversions. When using CMake 3.24 or newer, CMake has the ability to tell MSVC to ignore warnings in 3rd party code. However anyone using an older version does not get that fix and thus MSVC emits a warning about this 3rd party code which due to the default of WARNINGS_AS_ERRORS get promoted to a error that breaks the build.

This was never caught in SFML's CI pipeline because GitHub Actions CI runners always use the latest CMake release which means they've been using CMake 3.24 or newer for many months now. Users on VS 2019 have an older release of CMake and thus are prone to encounter this problem.

All we need is set(WARNINGS_AS_ERRORS OFF) before the FetchContent call unless we're willing to fix this upstream in SFML itself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.