|
| 1 | +# require version 3.10 or higher |
| 2 | +cmake_minimum_required(VERSION 3.10) |
| 3 | + |
| 4 | +project(olcPGEX_MiniAudio) |
| 5 | + |
| 6 | +option(UPDATE_GIT_SUBMODULES "Update Git submodules" ON) |
| 7 | + |
| 8 | +if (UPDATE_GIT_SUBMODULES) |
| 9 | + message(STATUS "Updating Git submodules...") |
| 10 | + execute_process( |
| 11 | + COMMAND git submodule update --init --recursive |
| 12 | + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 13 | + RESULT_VARIABLE result |
| 14 | + ) |
| 15 | + |
| 16 | + if(NOT result EQUAL 0) |
| 17 | + message(FATAL_ERROR "Failed to update Git submodules") |
| 18 | + endif() |
| 19 | +endif() |
| 20 | + |
| 21 | +# Set C++ Standards |
| 22 | +set(CMAKE_CXX_STANDARD 20) |
| 23 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 24 | +set(CMAKE_CXX_EXTENSIONS OFF) |
| 25 | + |
| 26 | +function(add_common_settings target) |
| 27 | + |
| 28 | + ###################################################################### |
| 29 | + # MacOS |
| 30 | + ###################################################################### |
| 31 | + if(APPLE) |
| 32 | + |
| 33 | + # OpenGL |
| 34 | + set(OpenGL_GL_PREFERENCE LEGACY) |
| 35 | + find_package(OpenGL REQUIRED) |
| 36 | + include_directories(${OpenGL_INCLUDE_DIRS}) |
| 37 | + target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL) |
| 38 | + |
| 39 | + # Carbon |
| 40 | + FIND_LIBRARY(CARBON_LIBRARY Carbon) |
| 41 | + target_link_libraries(${target} ${CARBON_LIBRARY}) |
| 42 | + |
| 43 | + # GLUT |
| 44 | + find_package(GLUT REQUIRED) |
| 45 | + target_link_libraries(${target} ${GLUT_LIBRARIES}) |
| 46 | + |
| 47 | + # Threads |
| 48 | + find_package(Threads REQUIRED) |
| 49 | + target_link_libraries(${target} Threads::Threads) |
| 50 | + include_directories(${Threads_INCLUDE_DIRS}) |
| 51 | + |
| 52 | + find_package(PNG REQUIRED) |
| 53 | + target_link_libraries(${target} PNG::PNG) |
| 54 | + include_directories(${PNG_INCLUDE_DIRS}) |
| 55 | + |
| 56 | + # debug mode! |
| 57 | + target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DMA_DEBUG_OUTPUT>) |
| 58 | + target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DDEBUG=1>) |
| 59 | + |
| 60 | + endif() # APPLE |
| 61 | + |
| 62 | + |
| 63 | + ###################################################################### |
| 64 | + # Windows: MinGW |
| 65 | + ###################################################################### |
| 66 | + if(WIN32 AND MINGW) |
| 67 | + |
| 68 | + # OpenGL |
| 69 | + set(OpenGL_GL_PREFERENCE LEGACY) |
| 70 | + find_package(OpenGL REQUIRED) |
| 71 | + include_directories(${OpenGL_INCLUDE_DIRS}) |
| 72 | + target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL) |
| 73 | + |
| 74 | + if (NOT HAS_TERMINAL) |
| 75 | + target_link_libraries(${target} -mwindows -municode) |
| 76 | + endif (NOT HAS_TERMINAL) |
| 77 | + |
| 78 | + # GDI+ |
| 79 | + set(GDIPLUS_LIBRARY gdiplus) |
| 80 | + target_link_libraries(${target} ${GDIPLUS_LIBRARY}) |
| 81 | + |
| 82 | + # Shlwapi |
| 83 | + set(SHLWAPI_LIBRARY shlwapi) |
| 84 | + target_link_libraries(${target} ${SHLWAPI_LIBRARY}) |
| 85 | + |
| 86 | + # Dwmapi |
| 87 | + set(DWMAPI_LIBRARY dwmapi) |
| 88 | + target_link_libraries(${target} ${DWMAPI_LIBRARY}) |
| 89 | + |
| 90 | + # stdc++fs |
| 91 | + target_link_libraries(${target} stdc++fs) |
| 92 | + |
| 93 | + # debug mode! |
| 94 | + target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DMA_DEBUG_OUTPUT>) |
| 95 | + target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DDEBUG=1>) |
| 96 | + |
| 97 | + endif() |
| 98 | + |
| 99 | + ###################################################################### |
| 100 | + # Windows: Visual Studio / MSVC |
| 101 | + ###################################################################### |
| 102 | + if(WIN32 AND MSVC) |
| 103 | + |
| 104 | + # OpenGL |
| 105 | + set(OpenGL_GL_PREFERENCE LEGACY) |
| 106 | + find_package(OpenGL REQUIRED) |
| 107 | + include_directories(${OpenGL_INCLUDE_DIRS}) |
| 108 | + target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL) |
| 109 | + |
| 110 | + # set the startup project to the target executable instead of ALL_BUILD |
| 111 | + set_property( |
| 112 | + DIRECTORY |
| 113 | + ${CMAKE_CURRENT_SOURCE_DIR} |
| 114 | + PROPERTY |
| 115 | + VS_STARTUP_PROJECT |
| 116 | + ${target} |
| 117 | + ) |
| 118 | + |
| 119 | + # set working directory for Visual Studio Debugger |
| 120 | + set_target_properties( |
| 121 | + ${target} PROPERTIES |
| 122 | + VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin" |
| 123 | + ) |
| 124 | + |
| 125 | + # set subsytem, console if HAS_TERMINAL is true. windows if not |
| 126 | + if (HAS_TERMINAL) |
| 127 | + target_link_options(${target} PRIVATE "/SUBSYSTEM:CONSOLE") |
| 128 | + else () |
| 129 | + target_link_options(${target} PRIVATE "/SUBSYSTEM:WINDOWS") |
| 130 | + endif () |
| 131 | + |
| 132 | + # GDI+ |
| 133 | + set(GDIPLUS_LIBRARY gdiplus) |
| 134 | + target_link_libraries(${target} ${GDIPLUS_LIBRARY}) |
| 135 | + |
| 136 | + # Shlwapi |
| 137 | + set(SHLWAPI_LIBRARY shlwapi) |
| 138 | + target_link_libraries(${target} ${SHLWAPI_LIBRARY}) |
| 139 | + |
| 140 | + # Dwmapi |
| 141 | + set(DWMAPI_LIBRARY dwmapi) |
| 142 | + target_link_libraries(${target} ${DWMAPI_LIBRARY}) |
| 143 | + |
| 144 | + # debug mode! |
| 145 | + target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DMA_DEBUG_OUTPUT>) |
| 146 | + target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DDEBUG=1>) |
| 147 | + |
| 148 | + endif() # Visual Studio / MSVC |
| 149 | + |
| 150 | + ###################################################################### |
| 151 | + # Linux: using anything? |
| 152 | + ###################################################################### |
| 153 | + if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN) |
| 154 | + |
| 155 | + # OpenGL |
| 156 | + set(OpenGL_GL_PREFERENCE LEGACY) |
| 157 | + find_package(OpenGL REQUIRED) |
| 158 | + include_directories(${OpenGL_INCLUDE_DIRS}) |
| 159 | + target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL) |
| 160 | + |
| 161 | + # X11 |
| 162 | + find_package(X11 REQUIRED) |
| 163 | + target_link_libraries(${target} X11::X11) |
| 164 | + |
| 165 | + include_directories(${X11_INCLUDE_DIRS}) |
| 166 | + |
| 167 | + # Threads |
| 168 | + find_package(Threads REQUIRED) |
| 169 | + target_link_libraries(${target} Threads::Threads) |
| 170 | + include_directories(${Threads_INCLUDE_DIRS}) |
| 171 | + |
| 172 | + find_package(PNG REQUIRED) |
| 173 | + target_link_libraries(${target} PNG::PNG) |
| 174 | + include_directories(${PNG_INCLUDE_DIRS}) |
| 175 | + |
| 176 | + # stdc++fs |
| 177 | + target_link_libraries(${target} stdc++fs) |
| 178 | + |
| 179 | + # dl, for miniaudio |
| 180 | + target_link_libraries(${target} dl) |
| 181 | + |
| 182 | + # debug mode! |
| 183 | + target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DMA_DEBUG_OUTPUT>) |
| 184 | + target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DDEBUG=1>) |
| 185 | + |
| 186 | + endif() # Linux |
| 187 | + |
| 188 | + ###################################################################### |
| 189 | + # Emscripten |
| 190 | + ###################################################################### |
| 191 | + if (EMSCRIPTEN) |
| 192 | + |
| 193 | + # build Cache: libpng, zlib |
| 194 | + execute_process(COMMAND "${EMSCRIPTEN_ROOT_PATH}/embuilder${EMCC_SUFFIX}" build libpng zlib) |
| 195 | + |
| 196 | + # debug mode! |
| 197 | + target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DMA_DEBUG_OUTPUT>) |
| 198 | + target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DDEBUG=1>) |
| 199 | + |
| 200 | + target_link_options(${target} PRIVATE -sALLOW_MEMORY_GROWTH=1) |
| 201 | + target_link_options(${target} PRIVATE -sSTACK_SIZE=131072) |
| 202 | + target_link_options(${target} PRIVATE -sMAX_WEBGL_VERSION=2) |
| 203 | + target_link_options(${target} PRIVATE -sMIN_WEBGL_VERSION=2) |
| 204 | + target_link_options(${target} PRIVATE -sUSE_LIBPNG=1) |
| 205 | + target_link_options(${target} PRIVATE -sLLD_REPORT_UNDEFINED) |
| 206 | + target_link_options(${target} PRIVATE --shell-file "${CMAKE_CURRENT_SOURCE_DIR}/shell.html") |
| 207 | + target_link_options(${target} PRIVATE --preload-file ${CMAKE_SOURCE_DIR}/demo/assets@assets) |
| 208 | + |
| 209 | + endif() # Emscripten |
| 210 | + |
| 211 | + include_directories(${CMAKE_SOURCE_DIR}) |
| 212 | + include_directories(third_party/miniaudio) |
| 213 | + include_directories(third_party/olcPixelGameEngine) |
| 214 | + |
| 215 | + |
| 216 | + if (NOT EMSCRIPTEN) |
| 217 | + add_custom_command( |
| 218 | + TARGET ${target} |
| 219 | + POST_BUILD |
| 220 | + COMMAND ${CMAKE_COMMAND} |
| 221 | + ARGS -E copy_directory ${CMAKE_SOURCE_DIR}/demo/assets ${CMAKE_BINARY_DIR}/assets |
| 222 | + ) |
| 223 | + endif() |
| 224 | + |
| 225 | +endfunction() |
| 226 | + |
| 227 | +# Executable aka binary output |
| 228 | +add_executable( |
| 229 | + demo |
| 230 | + demo/demo.cpp |
| 231 | + demo/common.cpp |
| 232 | + olcPGEX_MiniAudio.h |
| 233 | + third_party/olcPixelGameEngine/olcPixelGameEngine.h |
| 234 | + third_party/miniaudio/miniaudio.h |
| 235 | +) |
| 236 | + |
| 237 | +add_executable( |
| 238 | + demo_synthesis |
| 239 | + demo/demo_synthesis.cpp |
| 240 | + demo/common.cpp |
| 241 | + olcPGEX_MiniAudio.h |
| 242 | + third_party/olcPixelGameEngine/olcPixelGameEngine.h |
| 243 | + third_party/miniaudio/miniaudio.h |
| 244 | +) |
| 245 | + |
| 246 | +add_executable( |
| 247 | + demo_waveform |
| 248 | + demo/demo_waveform.cpp |
| 249 | + demo/common.cpp |
| 250 | + olcPGEX_MiniAudio.h |
| 251 | + third_party/olcPixelGameEngine/olcPixelGameEngine.h |
| 252 | + third_party/miniaudio/miniaudio.h |
| 253 | +) |
| 254 | + |
| 255 | +if (EMSCRIPTEN) |
| 256 | + # generate an HTML file |
| 257 | + set(CMAKE_EXECUTABLE_SUFFIX .html) |
| 258 | +endif() |
| 259 | + |
| 260 | +add_common_settings(demo) |
| 261 | +add_common_settings(demo_synthesis) |
| 262 | +add_common_settings(demo_waveform) |
0 commit comments