cmake_minimum_required(VERSION 3.16) project(demo64k LANGUAGES C CXX) option(DEMO_SIZE_OPT "Enable size optimization flags" OFF) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Search in both debug and release set(WGPU_SEARCH_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/wgpu-native/target/debug ${CMAKE_CURRENT_SOURCE_DIR}/third_party/wgpu-native/target/release ) find_library( WGPU_LIBRARY NAMES libwgpu_native.a wgpu_native.lib wgpu_native HINTS ${WGPU_SEARCH_PATHS} REQUIRED ) include_directories( src third_party third_party/wgpu-native/ffi third_party/wgpu-native/ffi/webgpu-headers ) find_package(glfw3 REQUIRED) set(DEMO_LIBS glfw ${WGPU_LIBRARY}) # Platform-specific dependencies for wgpu-native if (APPLE) set_source_files_properties(src/platform.cc PROPERTIES COMPILE_FLAGS "-x objective-c++") list(APPEND DEMO_LIBS "-framework Metal" "-framework Foundation" "-framework Cocoa" "-framework QuartzCore" ) else() # Assume Linux/other POSIX-like systems might need these list(APPEND DEMO_LIBS pthread m dl) endif() add_executable(demo64k src/main.cc src/platform.cc src/gpu/gpu.cc src/audio/audio.cc src/audio/fdct.cc src/audio/idct.cc src/audio/window.cc src/audio/synth.cc ) target_link_libraries(demo64k PRIVATE ${DEMO_LIBS}) if (DEMO_SIZE_OPT) if (MSVC) target_compile_options(demo64k PRIVATE /Os /GS-) target_link_options(demo64k PRIVATE /OPT:REF /OPT:ICF /INCREMENTAL:NO) else() target_compile_options(demo64k PRIVATE -Os -ffunction-sections -fdata-sections) target_link_options(demo64k PRIVATE -Wl,--gc-sections -s) endif() endif() option(DEMO_BUILD_TESTS "Build tests" OFF) enable_testing() if(DEMO_BUILD_TESTS) add_executable(test_window src/tests/test_window.cc src/audio/window.cc ) target_include_directories(test_window PRIVATE src) add_test(NAME HammingWindowTest COMMAND test_window) add_executable(test_synth src/tests/test_synth.cc src/audio/synth.cc src/audio/idct.cc src/audio/window.cc ) target_include_directories(test_synth PRIVATE src) add_test(NAME SynthEngineTest COMMAND test_synth) add_executable(test_spectool src/tests/test_spectool.cc src/audio/audio.cc src/audio/window.cc src/audio/fdct.cc src/audio/synth.cc src/audio/idct.cc ) target_include_directories(test_spectool PRIVATE src third_party) target_link_libraries(test_spectool PRIVATE ${DEMO_LIBS}) add_test(NAME SpectoolEndToEndTest COMMAND test_spectool) endif() option(DEMO_BUILD_TOOLS "Build tools" OFF) if(DEMO_BUILD_TOOLS) add_executable(spectool tools/spectool.cc src/platform.cc src/audio/audio.cc src/audio/fdct.cc src/audio/idct.cc src/audio/window.cc src/audio/synth.cc ) target_include_directories(spectool PRIVATE src third_party) target_link_libraries(spectool PRIVATE ${DEMO_LIBS}) add_executable(specview tools/specview.cc ) target_include_directories(specview PRIVATE src) endif()