Skip to content

Commit

Permalink
Add SFML-Audio to the project
Browse files Browse the repository at this point in the history
I want to add sounds to the game, so it needs an audio module.
Unfortunately, sfml-audio is written in C++98 so the corresponding
settings in CMAKE had to be set.
  • Loading branch information
Notiooo committed Dec 1, 2023
1 parent b6e7aec commit ff216a9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions AimGL/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ target_include_directories(AimGLSrc PUBLIC
${CUSTOM_INCLUDES_DIR}
)


set_target_properties(sfml-audio PROPERTIES CXX_STANDARD 98 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO)

target_link_libraries(AimGLSrc
PUBLIC
sfml-graphics
sfml-audio
ImGui-SFML::ImGui-SFML
glew_s
glm
Expand All @@ -53,11 +57,21 @@ add_custom_command(TARGET AimGLSrc POST_BUILD
$<TARGET_FILE:sfml-graphics>
$<TARGET_FILE:sfml-window>
$<TARGET_FILE:sfml-system>
$<TARGET_FILE:sfml-audio>
$<TARGET_FILE:spdlog>
$<TARGET_FILE:minitrace>
$<TARGET_FILE_DIR:AimGLSrc>
)

# Copy OpenAL32.dll for SFML AUDIO
if (WIN32 AND SFML_BUILD_AUDIO)
add_custom_command(TARGET AimGLSrc POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${FETCHCONTENT_BASE_DIR}/sfml-src/extlibs/bin/x64/openal32.dll
$<TARGET_FILE_DIR:AimGLSrc>
)
endif()

# Remove previous game resources

add_custom_command(TARGET AimGLSrc PRE_BUILD
Expand Down
2 changes: 2 additions & 0 deletions AimGL/src/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <imgui.h>

// SFML
#include <SFML/Audio/Sound.hpp>
#include <SFML/Audio/SoundBuffer.hpp>
#include <SFML/OpenGL.hpp>
#include <SFML/System/Time.hpp>
#include <SFML/Window.hpp>
Expand Down
1 change: 1 addition & 0 deletions AimGL/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ add_custom_command(TARGET AimGLTests POST_BUILD
$<TARGET_FILE:sfml-graphics>
$<TARGET_FILE:sfml-window>
$<TARGET_FILE:sfml-system>
$<TARGET_FILE:sfml-audio>
$<TARGET_FILE:spdlog>
$<TARGET_FILE_DIR:AimGLTests>
)
Expand Down
3 changes: 1 addition & 2 deletions AimGL/vendor/sfml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ FetchContent_Declare(
GIT_TAG 2f11710abc5aa478503a7ff3f9e654bd2078ebab # 2.5.1
)

# No need to build audio and network modules
set(SFML_BUILD_AUDIO FALSE)
# No need to build network modules
set(SFML_BUILD_NETWORK FALSE)

FetchContent_MakeAvailable(sfml)
Expand Down

0 comments on commit ff216a9

Please sign in to comment.