Skip to content

Commit

Permalink
[CMake] Reenabled OpenAL when using Emscripten
Browse files Browse the repository at this point in the history
- This broke when making OpenAL non-mandatory
  - Emscripten having its own script producing different variable names, it was not properly used anymore

- Renamed (un-pluralized) OpenAL's & FBX's lib & include variables to be more standard
  - CMake's standard FindOpenAL.cmake script gives singular variables, and parts of the documentation also mentions singular forms

- Updated the license year
  • Loading branch information
Razakhel committed Jan 3, 2023
1 parent effab1d commit 81e743e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
17 changes: 13 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,24 @@ endif ()
################

find_package(OpenAL)

if (RAZ_USE_EMSCRIPTEN)
# Emscripten's FindOpenAL.cmake script historically sets the capitalized found variable, but always finds it anyway
set(OpenAL_FOUND ON)
endif ()

option(RAZ_USE_AUDIO "Enable audio capabilities (requires OpenAL to be installed)" ${OpenAL_FOUND})

if (RAZ_USE_AUDIO)
if (NOT OpenAL_FOUND)
message(SEND_ERROR "Audio required but OpenAL not found; please review its location")
endif ()

target_include_directories(RaZ SYSTEM PRIVATE ${OPENAL_INCLUDE_DIRS})
target_link_libraries(RaZ PRIVATE ${OPENAL_LIBS})
if (NOT RAZ_USE_EMSCRIPTEN)
# Emscripten manages the includes & library on its own; adding the include directory messes up predefined types
target_include_directories(RaZ SYSTEM PRIVATE ${OPENAL_INCLUDE_DIR})
target_link_libraries(RaZ PRIVATE ${OPENAL_LIBRARY})
endif ()
target_compile_definitions(RaZ PUBLIC RAZ_USE_AUDIO)
else ()
file(
Expand Down Expand Up @@ -312,8 +321,8 @@ if (RAZ_COMPILER_MSVC OR (RAZ_COMPILER_GCC AND NOT MINGW)) # FBX SDK unavailable
message(SEND_ERROR "FBX required but SDK not found; please review its location")
endif ()

target_include_directories(RaZ SYSTEM PRIVATE ${FBX_INCLUDE_DIRS})
target_link_libraries(RaZ PRIVATE ${FBX_LIBS})
target_include_directories(RaZ SYSTEM PRIVATE ${FBX_INCLUDE_DIR})
target_link_libraries(RaZ PRIVATE ${FBX_LIBRARY})
target_compile_definitions(RaZ PUBLIC RAZ_USE_FBX ${FBX_DEFINITIONS})
endif ()
endif ()
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2017-2020 Romain Milbert
Copyright (c) 2023 Romain Milbert

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 6 additions & 6 deletions cmake/FindFBX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ else ()
endif ()

find_path(
FBX_INCLUDE_DIRS
FBX_INCLUDE_DIR

NAMES
fbxsdk.h
Expand All @@ -54,7 +54,7 @@ else ()
endif ()

find_library(
FBX_LIBS
FBX_LIBRARY

NAMES
libfbxsdk
Expand Down Expand Up @@ -92,18 +92,18 @@ if (WIN32)
)
endif ()

if (FBX_LIBS AND FBX_INCLUDE_DIRS)
if (FBX_LIBRARY AND FBX_INCLUDE_DIR)
set(FBX_FOUND ON)
set(FBX_DEFINITIONS -DFBXSDK_SHARED)

message("[FBX] Found:")
message(" - Include directory: ${FBX_INCLUDE_DIRS}")
message(" - Library: ${FBX_LIBS}")
message(" - Include directory: ${FBX_INCLUDE_DIR}")
message(" - Library: ${FBX_LIBRARY}")
if (WIN32)
message(" - DLL: ${FBX_DLL}")
endif ()

if (UNIX)
list(APPEND FBX_LIBS xml2) # The SDK requires libxml2
list(APPEND FBX_LIBRARY xml2) # The SDK requires libxml2
endif ()
endif ()
14 changes: 7 additions & 7 deletions cmake/FindOpenAL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (WIN32 OR CYGWIN)
endif ()

find_library(
OPENAL_LIBS
OPENAL_LIBRARY

NAMES
OpenAL al openal OpenAL32
Expand Down Expand Up @@ -67,7 +67,7 @@ if (WIN32 OR CYGWIN)
)
endif ()
elseif (APPLE)
set(OPENAL_LIBS "-framework OpenAL")
set(OPENAL_LIBRARY "-framework OpenAL")

file(
GLOB
Expand All @@ -80,7 +80,7 @@ elseif (APPLE)
"/usr/local/opt/openal*"
)
else () # Linux
set(OPENAL_LIBS openal)
set(OPENAL_LIBRARY openal)

file(
GLOB
Expand All @@ -94,7 +94,7 @@ else () # Linux
endif ()

find_path(
OPENAL_INCLUDE_DIRS
OPENAL_INCLUDE_DIR

NAMES
AL/al.h
Expand All @@ -108,12 +108,12 @@ find_path(
include/AL include/OpenAL include AL OpenAL
)

if (OPENAL_LIBS AND OPENAL_INCLUDE_DIRS)
if (OPENAL_LIBRARY AND OPENAL_INCLUDE_DIR)
set(OpenAL_FOUND ON)

message("[OpenAL] Found:")
message(" - Include directory: ${OPENAL_INCLUDE_DIRS}")
message(" - Library: ${OPENAL_LIBS}")
message(" - Include directory: ${OPENAL_INCLUDE_DIR}")
message(" - Library: ${OPENAL_LIBRARY}")
if (WIN32)
message(" - DLL: ${OPENAL_DLL}")
endif ()
Expand Down

0 comments on commit 81e743e

Please sign in to comment.