FindOpenAL: Add imported target

Fixes: #20026
This commit is contained in:
Sam V
2022-06-21 17:26:31 +02:00
committed by Brad King
parent 2f3ea66a76
commit 927e091949
6 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
findopenal-add-import-library
-----------------------------
* The :module:`FindOpenAL` module now provides an imported target.

View File

@@ -29,6 +29,16 @@ OpenAL is searched in the following order:
5. Manually compiled framework: ``/Library/Frameworks``.
6. Add-on package: ``/opt``.
IMPORTED Targets
^^^^^^^^^^^^^^^^
.. versionadded:: 3.25
This module defines the :prop_tgt:`IMPORTED` target:
``OpenAL::OpenAL``
The OpenAL library, if found.
Result Variables
^^^^^^^^^^^^^^^^
@@ -94,3 +104,19 @@ find_package_handle_standard_args(
)
mark_as_advanced(OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
if(OPENAL_INCLUDE_DIR AND OPENAL_LIBRARY)
if(NOT TARGET OpenAL::OpenAL)
if(EXISTS "${OPENAL_LIBRARY}")
add_library(OpenAL::OpenAL UNKNOWN IMPORTED)
set_target_properties(OpenAL::OpenAL PROPERTIES
IMPORTED_LOCATION "${OPENAL_LIBRARY}")
else()
add_library(OpenAL::OpenAL INTERFACE IMPORTED)
set_target_properties(OpenAL::OpenAL PROPERTIES
IMPORTED_LIBNAME "${OPENAL_LIBRARY}")
endif()
set_target_properties(OpenAL::OpenAL PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OPENAL_INCLUDE_DIR}")
endif()
endif()

View File

@@ -1460,6 +1460,7 @@ if(BUILD_TESTING)
LTTngUST
ODBC
OpenACC
OpenAL
OpenCL
OpenGL
OpenMP

View File

@@ -0,0 +1,10 @@
add_test(NAME FindOpenAL.Test COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindOpenAL/Test"
"${CMake_BINARY_DIR}/Tests/FindOpenAL/Test"
${build_generator_args}
--build-project TestFindOpenAL
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)

View File

@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.21)
project(TestFindOpenAL CXX)
include(CTest)
find_package(OpenAL REQUIRED)
add_executable(test_tgt main.cxx)
target_link_libraries(test_tgt OpenAL::OpenAL)
add_test(NAME test_tgt COMMAND test_tgt)
add_executable(test_var main.cxx)
target_include_directories(test_var PRIVATE ${OPENAL_INCLUDE_DIR})
target_link_libraries(test_var PRIVATE ${OPENAL_LIBRARY})
add_test(NAME test_var COMMAND test_var)

View File

@@ -0,0 +1,13 @@
#include <AL/al.h>
#include <AL/alc.h>
#include <stdio.h>
int main()
{
/* Reference an AL symbol without requiring a context at runtime. */
printf("&alGetString = %p\n", &alGetString);
/* Reference an ALC symbol without requiring a context at runtime. */
printf("&alcGetString = %p\n", &alcGetString);
return 0;
}