summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 69e51c6ce030ee3fecf9d2f7e50dce61732a8c70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
cmake_minimum_required(VERSION 3.16)
project(demo64k LANGUAGES C CXX)

if(APPLE)
    add_definitions(-DGLFW_EXPOSE_NATIVE_COCOA)
elseif(WIN32)
    add_definitions(-DGLFW_EXPOSE_NATIVE_WIN32)
elseif(UNIX)
    if(DEFINED CMAKE_USE_WAYLAND)
        add_definitions(-DGLFW_EXPOSE_NATIVE_WAYLAND)
    else()
        add_definitions(-DGLFW_EXPOSE_NATIVE_X11)
    endif()
endif()

option(DEMO_SIZE_OPT "Enable size optimization flags" OFF)
option(DEMO_STRIP_ALL "Strip all unnecessary code for final build" OFF)

if (DEMO_STRIP_ALL)
    add_definitions(-DSTRIP_ALL)
    set(DEMO_SIZE_OPT ON)
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find wgpu-native (system install)
find_library(WGPU_LIBRARY NAMES wgpu_native libwgpu_native REQUIRED)
find_path(WGPU_INCLUDE_DIR NAMES webgpu.h PATH_SUFFIXES webgpu-headers REQUIRED)

include_directories(
    src
    third_party
    ${WGPU_INCLUDE_DIR}
    third_party/glfw3webgpu
)

find_package(glfw3 REQUIRED)

set(DEMO_LIBS glfw ${WGPU_LIBRARY})

# Platform-specific dependencies
if (APPLE)
    set_source_files_properties(
        src/platform.cc 
        third_party/glfw3webgpu/glfw3webgpu.c
        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
    third_party/glfw3webgpu/glfw3webgpu.c
)

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)
    elseif (APPLE)
        target_compile_options(demo64k PRIVATE -Os)
        target_link_options(demo64k PRIVATE -Wl,-dead_strip)
    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

            third_party/glfw3webgpu/glfw3webgpu.c

        )

        target_include_directories(test_spectool PRIVATE

            src

            third_party

            ${WGPU_INCLUDE_DIR}

            third_party/glfw3webgpu

        )
    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
            third_party/glfw3webgpu/glfw3webgpu.c
        )
        target_include_directories(spectool PRIVATE
            src
            third_party
            ${WGPU_INCLUDE_DIR}
            third_party/glfw3webgpu
        )
    target_link_libraries(spectool PRIVATE ${DEMO_LIBS})

    add_executable(specview
        tools/specview.cc
    )
    target_include_directories(specview PRIVATE src)
endif()