Skip to content

Commit

Permalink
Fix include paths in FindOpenAL.cmake/FindOpenGL.cmake (#16840)
Browse files Browse the repository at this point in the history
Also add a test that uses both of these modules.

Fixes: #16833
  • Loading branch information
sbc100 committed Apr 29, 2022
1 parent 7c2752f commit 485a7b4
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 40 deletions.
4 changes: 2 additions & 2 deletions cmake/Modules/FindOpenAL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ if (NOT OPENAL_FOUND)
SET(OPENAL_FOUND TRUE)

# For Emscripten-compiled apps in the test suite (test_alut), this is expected...
SET(OPENAL_INCLUDE_DIR "${EMSCRIPTEN_ROOT_PATH}/system/include")
SET(OPENAL_INCLUDE_DIR "${EMSCRIPTEN_SYSROOT}/include")
# ... but the stock FindOpenAL.cmake would have returned this.
#SET(OPENAL_INCLUDE_DIR "${EMSCRIPTEN_ROOT_PATH}/system/include/AL")

# Returning "-lopenal" is now considered mandatory
SET(OPENAL_LIBRARY "-lopenal")
SET(OPENAL_LIB "-lopenal")

set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${EMSCRIPTEN_ROOT_PATH}/system/include" "${EMSCRIPTEN_ROOT_PATH}/system/include/AL")
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${OPENAL_INCLUDE_DIR}" "${OPENAL_INCLUDE_DIR}/AL")

MARK_AS_ADVANCED(OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
endif()
10 changes: 4 additions & 6 deletions cmake/Modules/FindOpenGL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ SET(OPENGL_GLU_FOUND TRUE)
SET(OPENGL_XMESA_FOUND FALSE)

# This is the path where <GL/gl.h> is found
SET(OPENGL_INCLUDE_DIR "${EMSCRIPTEN_ROOT_PATH}/system/include")
SET(OPENGL_INCLUDE_DIR "${EMSCRIPTEN_SYSROOT}/include")

# No library to link against for OpenGL, since Emscripten picks it up automatically from library_webgl.js,
# but need to report something, or CMake thinks we failed in the search.
SET(OPENGL_LIBRARIES "nul")
SET(OPENGL_gl_LIBRARY "nul")
SET(OPENGL_glu_LIBRARY "nul")
SET(OPENGL_gl_LIBRARY "GL")
SET(OPENGL_glu_LIBRARY "GLU")
SET(OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY})

mark_as_advanced(
OPENGL_INCLUDE_DIR
Expand Down
15 changes: 7 additions & 8 deletions src/library_openal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3055,13 +3055,6 @@ var LibraryOpenAL = {
alGetString__proxy: 'sync',
alGetString__sig: 'ii',
alGetString: function(param) {
if (!AL.currentCtx) {
#if OPENAL_DEBUG
err('alGetString() called without a valid context');
#endif
return 0;
}

if (AL.stringCache[param]) {
return AL.stringCache[param];
}
Expand Down Expand Up @@ -3104,7 +3097,13 @@ var LibraryOpenAL = {
ret = ret.trim();
break;
default:
AL.currentCtx.err = 0xA002 /* AL_INVALID_ENUM */;
if (AL.currentCtx) {
AL.currentCtx.err = 0xA002 /* AL_INVALID_ENUM */;
} else {
#if OPENAL_DEBUG
err('alGetString() called without a valid context');
#endif
}
return 0;
}

Expand Down
20 changes: 20 additions & 0 deletions tests/cmake/find_modules/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.0)
project(find_modules)

add_executable(test_prog test.c)

find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
target_link_libraries(test_prog ${OPENGL_LIBRARIES})
message(" test: OPENGL_LIBRARIES: ${OPENGL_LIBRARIES}")

find_package(OpenAL REQUIRED)
include_directories(${OPENAL_INCLUDE_DIR})
target_link_libraries(test_prog ${OPENAL_LIBRARY})
message(" test: OPENGL_LIBRARIES: ${OPENAL_LIBRARIES}")

find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
target_link_libraries(test_prog SDL2::SDL2)
message(" test: SDL2_LIBRARIES: ${SDL2_LIBRARIES}")
message(" test: SDL2_INCLUDE_DIRS: ${SDL2_INCLUDE_DIRS}")
16 changes: 16 additions & 0 deletions tests/cmake/find_modules/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Invlude emscripten/version.h to ensure that the in-tree
// include directory has not been added to the include path.
#include <emscripten/version.h>
#include <stdio.h>
#include <AL/al.h>
#include <GL/gl.h>
#include <SDL.h>

int main() {
SDL_version compiled;
SDL_VERSION(&compiled);
SDL_Log("SDL version: %d.%d.%d\n", compiled.major, compiled.minor, compiled.patch);

printf("AL_VERSION: %s\n", alGetString(AL_VERSION));
return 0;
}
9 changes: 0 additions & 9 deletions tests/cmake/find_sdl2/CMakeLists.txt

This file was deleted.

10 changes: 0 additions & 10 deletions tests/cmake/find_sdl2/sdl2.c

This file was deleted.

11 changes: 6 additions & 5 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,11 +789,12 @@ def test_cmake_install(self):
self.assertContained('foo: 42\n', self.run_js('build2/Bar.js'))
self.run_process(['cmake', '--build', 'build2', '--target', 'install'])

def test_cmake_find_sdl2(self):
os.mkdir('build')
self.run_process([EMCMAKE, 'cmake', test_file('cmake/find_sdl2')], cwd='build')
self.run_process(['cmake', '--build', 'build'])
self.assertContained('SDL version: 2.0.', self.run_js('build/sdl2.js'))
def test_cmake_find_modules(self):
self.run_process([EMCMAKE, 'cmake', test_file('cmake/find_modules')])
self.run_process(['cmake', '--build', '.'])
output = self.run_js('test_prog.js')
self.assertContained('AL_VERSION: 1.1', output)
self.assertContained('SDL version: 2.0.', output)

def test_system_include_paths(self):
# Verify that all default include paths are within `emscripten/system`
Expand Down

0 comments on commit 485a7b4

Please sign in to comment.