Skip to content

Commit aa50858

Browse files
committed
Update demo's cmake to work with latest LabSound
1 parent 3f9da0f commit aa50858

File tree

3 files changed

+49
-19
lines changed

3 files changed

+49
-19
lines changed

CMakeLists.txt

+48-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11

2-
cmake_minimum_required (VERSION 3.4)
2+
cmake_minimum_required(VERSION 3.26)
33
project(LabSoundCDemo)
44

55
# Don't report that sample file installation up to date
66
set(CMAKE_INSTALL_MESSAGE LAZY)
77

88
set(LABSOUNDCDEMO_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
9-
configure_file("${LABSOUNDCDEMO_ROOT}/LabSoundDemo.config.h" "${LABSOUNDCDEMO_ROOT}/LabSoundDemo.h" @ONLY)
9+
configure_file("${LABSOUNDCDEMO_ROOT}/LabSoundDemo.config.h"
10+
"${LABSOUNDCDEMO_ROOT}/LabSoundDemo.h" @ONLY)
1011

11-
find_package(libnyquist REQUIRED)
12-
find_package(LabSound REQUIRED)
13-
find_package(LabSoundRtAudio REQUIRED)
12+
# Find LabSound and dependencies
13+
find_package(LabSound QUIET)
1414

15-
if (APPLE)
16-
set(PLATFORM_LIBS
15+
# if LabSound is not found, use FetchContent to download it
16+
if(NOT LabSound_FOUND)
17+
include(FetchContent)
18+
FetchContent_Declare(
19+
LabSound
20+
GIT_REPOSITORY "http://github.com/LabSound/LabSound.git"
21+
GIT_TAG "main"
22+
)
23+
message(STATUS "Fetching LabSound from source")
24+
FetchContent_MakeAvailable(LabSound)
25+
message(STATUS "LabSound found at: ${LabSound_SOURCE_DIR}")
26+
endif()
27+
28+
if(APPLE)
29+
set(PLATFORM_LIBS
1730
"-framework AudioToolbox"
1831
"-framework AudioUnit"
1932
"-framework Accelerate"
@@ -25,15 +38,38 @@ if (APPLE)
2538
)
2639
endif()
2740

28-
add_executable(LabSoundCDemo
29-
labsound-c.h labsound-c.cpp
30-
tinycthread.h tinycthread.c
41+
add_executable(LabSoundCDemo
42+
labsound-c.h labsound-c.cpp
43+
tinycthread.h tinycthread.c
3144
LabSoundCDemo.c flecs.h flecs.c)
45+
3246
set_property(TARGET LabSoundCDemo PROPERTY C_STANDARD 11)
3347
set_property(TARGET LabSoundCDemo PROPERTY CXX_STANDARD 17)
34-
target_link_libraries(LabSoundCDemo
35-
LabSound::LabSound
48+
target_link_libraries(LabSoundCDemo
49+
LabSound::LabSound
3650
LabSoundRtAudio::LabSoundRtAudio
3751
${PLATFORM_LIBS})
3852
target_include_directories(LabSoundCDemo PRIVATE "${LABSOUNDDEMO_ROOT}")
3953
install(TARGETS LabSoundCDemo RUNTIME DESTINATION bin)
54+
55+
# Copy the sample files from LabSound sources, src/assets/samples to
56+
# assets/samples in the run time bin directory
57+
message(STATUS "Copying sample files from ${LabSound_SOURCE_DIR}/assets/samples")
58+
file(GLOB SAMPLES "${LabSound_SOURCE_DIR}/assets/samples/*")
59+
foreach(SAMPLE ${SAMPLES})
60+
message(STATUS "Copying sample file: ${SAMPLE}")
61+
get_filename_component(SAMPLE_NAME ${SAMPLE} NAME)
62+
63+
# if the sample is a directory, copy the directory and its contents
64+
if(IS_DIRECTORY ${SAMPLE})
65+
# into the binary dir for easy debugging
66+
file(COPY ${SAMPLE} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/assets/samples)
67+
# if installing, copy the directory and its contents
68+
install(DIRECTORY ${SAMPLE} DESTINATION bin/assets/samples)
69+
else()
70+
# into the binary dir for easy debugging
71+
configure_file(${SAMPLE} ${CMAKE_CURRENT_BINARY_DIR}/assets/samples/${SAMPLE_NAME} COPYONLY)
72+
# if installing, copy the file
73+
install(FILES ${SAMPLE} DESTINATION bin/assets/samples)
74+
endif()
75+
endforeach()

LabSoundDemo.config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef LABSOUNDDEMOCONFIG_H
22
#define LABSOUNDDEMOCONFIG_H
33

4-
const char* asset_base = "@CMAKE_INSTALL_PREFIX@/share/LabSound/";
4+
const char* asset_base = "@CMAKE_INSTALL_PREFIX@/";
55

66
#endif

LabSoundDemo.h

-6
This file was deleted.

0 commit comments

Comments
 (0)