Skip to content

Commit ca3ba8c

Browse files
committed
Update CMake script to relax build options for examples.
This makes it so examples don't throw annoying warnings, that in order to fix, would require making the example code unnecessarily untidy.
1 parent cb95cd6 commit ca3ba8c

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

CMakeLists.txt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ if(NOT MINIAUDIO_NO_EXTRA_NODES)
588588

589589
if(MINIAUDIO_BUILD_EXAMPLES)
590590
add_executable(miniaudio_${name}_node_example extras/nodes/ma_${name}_node/ma_${name}_node_example.c)
591-
target_link_libraries(miniaudio_${name}_node_example PRIVATE miniaudio_common_options)
591+
target_link_libraries(miniaudio_${name}_node_example PRIVATE miniaudio_example)
592592
endif()
593593
endfunction()
594594

@@ -600,12 +600,18 @@ if(NOT MINIAUDIO_NO_EXTRA_NODES)
600600
endif()
601601

602602

603-
# Interface with common options to simplify the setup of tests and examples. Note that we don't pass
604-
# in COMPILE_DEFINES here because want to allow the tests and examples to define their own defines. If
605-
# we were to use COMPILE_DEFINES here many of the tests and examples would not compile.
606-
add_library(miniaudio_common_options INTERFACE)
607-
target_compile_options(miniaudio_common_options INTERFACE ${COMPILE_OPTIONS})
608-
target_link_libraries (miniaudio_common_options INTERFACE ${COMMON_LINK_LIBRARIES})
603+
# Interface for examples. Examples do not include COMPILE_OPTIONS because when compiling with things
604+
# like MINIAUDIO_FORCE_C89, etc. it could sometimes result in warnings which would make automated
605+
# build tools have unnecessarily messy output. Working around these errors would require us modifying
606+
# the examples in ways where it would negatively affect its readablity.
607+
add_library(miniaudio_example INTERFACE)
608+
target_link_libraries (miniaudio_example INTERFACE ${COMMON_LINK_LIBRARIES})
609+
610+
# Interface for tests. This includes our COMPILE_OPTIONS settings because we want tests to check for
611+
# build errors with MINIAUDIO_FORCE_C89, etc.
612+
add_library(miniaudio_test INTERFACE)
613+
target_compile_options(miniaudio_test INTERFACE ${COMPILE_OPTIONS})
614+
target_link_libraries (miniaudio_test INTERFACE ${COMMON_LINK_LIBRARIES})
609615

610616
# Tests
611617
#
@@ -617,7 +623,7 @@ if(MINIAUDIO_BUILD_TESTS)
617623

618624
function(add_miniaudio_test name source)
619625
add_executable(${name} ${TESTS_DIR}/${source})
620-
target_link_libraries(${name} PRIVATE miniaudio_common_options)
626+
target_link_libraries(${name} PRIVATE miniaudio_test)
621627
if(TARGET miniaudio_pipewire)
622628
target_link_libraries(${name} PRIVATE miniaudio_pipewire)
623629
target_compile_definitions(${name} PRIVATE MA_TESTS_INCLUDE_PIPEWIRE)
@@ -654,11 +660,10 @@ if (MINIAUDIO_BUILD_EXAMPLES)
654660

655661
function(add_miniaudio_example name source)
656662
add_executable(${name} ${EXAMPLES_DIR}/${source})
657-
target_link_libraries(${name} PRIVATE miniaudio_common_options)
663+
target_link_libraries(${name} PRIVATE miniaudio_example)
658664
endfunction()
659665

660666
add_miniaudio_example(miniaudio_custom_backend custom_backend.c)
661-
target_compile_options(miniaudio_custom_backend PRIVATE -Wno-declaration-after-statement)
662667

663668
add_miniaudio_example(miniaudio_custom_decoder_engine custom_decoder_engine.c)
664669
if(HAS_LIBVORBIS)

0 commit comments

Comments
 (0)