From 927e091949baf4e9627f48444a90191780501cc4 Mon Sep 17 00:00:00 2001 From: Sam V Date: Tue, 21 Jun 2022 17:26:31 +0200 Subject: FindOpenAL: Add imported target Fixes: #20026 --- Help/release/dev/findopenal-add-import-library.rst | 4 ++++ Modules/FindOpenAL.cmake | 26 ++++++++++++++++++++++ Tests/CMakeLists.txt | 1 + Tests/FindOpenAL/CMakeLists.txt | 10 +++++++++ Tests/FindOpenAL/Test/CMakeLists.txt | 14 ++++++++++++ Tests/FindOpenAL/Test/main.cxx | 13 +++++++++++ 6 files changed, 68 insertions(+) create mode 100644 Help/release/dev/findopenal-add-import-library.rst create mode 100644 Tests/FindOpenAL/CMakeLists.txt create mode 100644 Tests/FindOpenAL/Test/CMakeLists.txt create mode 100644 Tests/FindOpenAL/Test/main.cxx diff --git a/Help/release/dev/findopenal-add-import-library.rst b/Help/release/dev/findopenal-add-import-library.rst new file mode 100644 index 0000000..6c9c93f --- /dev/null +++ b/Help/release/dev/findopenal-add-import-library.rst @@ -0,0 +1,4 @@ +findopenal-add-import-library +----------------------------- + +* The :module:`FindOpenAL` module now provides an imported target. diff --git a/Modules/FindOpenAL.cmake b/Modules/FindOpenAL.cmake index b5b92c5..53aafdc 100644 --- a/Modules/FindOpenAL.cmake +++ b/Modules/FindOpenAL.cmake @@ -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() diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 24e98f4..3e3447f 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1460,6 +1460,7 @@ if(BUILD_TESTING) LTTngUST ODBC OpenACC + OpenAL OpenCL OpenGL OpenMP diff --git a/Tests/FindOpenAL/CMakeLists.txt b/Tests/FindOpenAL/CMakeLists.txt new file mode 100644 index 0000000..fc4803e --- /dev/null +++ b/Tests/FindOpenAL/CMakeLists.txt @@ -0,0 +1,10 @@ +add_test(NAME FindOpenAL.Test COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --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 $ + ) diff --git a/Tests/FindOpenAL/Test/CMakeLists.txt b/Tests/FindOpenAL/Test/CMakeLists.txt new file mode 100644 index 0000000..fa3e263 --- /dev/null +++ b/Tests/FindOpenAL/Test/CMakeLists.txt @@ -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) diff --git a/Tests/FindOpenAL/Test/main.cxx b/Tests/FindOpenAL/Test/main.cxx new file mode 100644 index 0000000..bb45faf --- /dev/null +++ b/Tests/FindOpenAL/Test/main.cxx @@ -0,0 +1,13 @@ +#include +#include +#include + +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; +} -- cgit v0.12