File: CMakeLists.txt

package info (click to toggle)
ableton-link 1.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 960 kB
  • sloc: cpp: 9,080; python: 243; sh: 28; makefile: 16
file content (251 lines) | stat: -rw-r--r-- 7,120 bytes parent folder | download
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
cmake_minimum_required(VERSION 3.0)
project(LinkExamples)

#     _    ____ ___ ___
#    / \  / ___|_ _/ _ \
#   / _ \ \___ \| | | | |
#  / ___ \ ___) | | |_| |
# /_/   \_\____/___\___/
#

if(WIN32)
  function(configure_asio asio_sdk_path_OUT)
    # ASIO-related path/file variables
    set(asio_download_root "https://www.steinberg.net/sdk_downloads")
    set(asio_file_name "asiosdk2.3.zip")
    set(asio_dir_name "ASIOSDK2.3")
    set(asio_working_dir "${CMAKE_BINARY_DIR}/modules")
    set(asio_output_path "${asio_working_dir}/${asio_file_name}")

    message(STATUS "Downloading ASIO SDK")
    file(DOWNLOAD "${asio_download_root}/${asio_file_name}" ${asio_output_path})
    file(SHA1 ${asio_output_path} asio_zip_hash)
    message("   ASIO SDK SHA1: ${asio_zip_hash}")

    message("   Extracting ASIO SDK")
    execute_process(COMMAND ${CMAKE_COMMAND} -E tar "xf" ${asio_output_path} --format=zip
      WORKING_DIRECTORY ${asio_working_dir}
      INPUT_FILE ${asio_output_path}
    )

    # Set the ASIO SDK path for the caller
    set(${asio_sdk_path_OUT} "${asio_working_dir}/${asio_dir_name}" PARENT_SCOPE)
  endfunction()
endif()

#     _             _ _
#    / \  _   _  __| (_) ___
#   / _ \| | | |/ _` | |/ _ \
#  / ___ \ |_| | (_| | | (_) |
# /_/   \_\__,_|\__,_|_|\___/
#

set(linkhut_audio_SOURCES)

if(APPLE)
  set(linkhut_audio_SOURCES
    linkaudio/AudioPlatform_CoreAudio.hpp
    linkaudio/AudioPlatform_CoreAudio.cpp
  )
elseif(WIN32)
  if(LINK_BUILD_ASIO)
    configure_asio(asio_sdk_path)

    include_directories(${asio_sdk_path}/common)
    include_directories(${asio_sdk_path}/host)
    include_directories(${asio_sdk_path}/host/pc)

    set(linkhut_audio_SOURCES
      ${asio_sdk_path}/common/asio.cpp
      ${asio_sdk_path}/host/asiodrivers.cpp
      ${asio_sdk_path}/host/pc/asiolist.cpp
      linkaudio/AudioPlatform_Asio.hpp
      linkaudio/AudioPlatform_Asio.cpp
    )
  else()
    message(WARNING "LinkHut has been configured to be built with the WASAPI audio "
      "driver. This driver is considered experimental and has problems with low-latency "
      "playback. Please consider using the ASIO driver instead.")
    set(linkhut_audio_SOURCES
      linkaudio/AudioPlatform_Wasapi.hpp
      linkaudio/AudioPlatform_Wasapi.cpp
    )
  endif()
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  if(LINK_BUILD_JACK)
    set(linkhut_audio_SOURCES
      linkaudio/AudioPlatform_Jack.hpp
      linkaudio/AudioPlatform_Jack.cpp
    )
  else()
    set(linkhut_audio_SOURCES
      linkaudio/AudioPlatform_Portaudio.hpp
      linkaudio/AudioPlatform_Portaudio.cpp
    )
  endif()
endif()

include_directories(linkaudio)
source_group("Audio Sources" FILES ${linkhut_audio_SOURCES})

#   ____
#  / ___|___  _ __ ___  _ __ ___   ___  _ __
# | |   / _ \| '_ ` _ \| '_ ` _ \ / _ \| '_ \
# | |__| (_) | | | | | | | | | | | (_) | | | |
#  \____\___/|_| |_| |_|_| |_| |_|\___/|_| |_|
#

function(configure_linkhut_executable target)
  if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    target_link_libraries(${target} pthread)
  endif()

  target_link_libraries(${target} Ableton::Link)

  target_set_word_size(${target})
endfunction()

function(configure_linkhut_audio_sources target)
  if(APPLE)
    target_link_libraries(${target} "-framework AudioUnit")
    target_compile_definitions(${target} PRIVATE
      -DLINKHUT_AUDIO_PLATFORM_COREAUDIO=1
    )
  elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    if(LINK_BUILD_JACK)
      target_link_libraries(${target} jack)
      target_compile_definitions(${target} PRIVATE
        -DLINKHUT_AUDIO_PLATFORM_JACK=1
      )
    else()
      target_link_libraries(${target} asound portaudio)
      target_compile_definitions(${target} PRIVATE
        -DLINKHUT_AUDIO_PLATFORM_PORTAUDIO=1
      )
    endif()
  elseif(WIN32)
    if(LINK_BUILD_ASIO)
      # ASIO uses lots of old-school string APIs from the C stdlib
      add_definitions("/D_CRT_SECURE_NO_WARNINGS")
      target_compile_definitions(${target} PRIVATE
        -DLINKHUT_AUDIO_PLATFORM_ASIO=1
      )
    else()
      target_compile_definitions(${target} PRIVATE
        -DLINKHUT_AUDIO_PLATFORM_WASAPI=1
      )
      endif()

    target_link_libraries(${target} winmm)
  endif()

endfunction()

if(WIN32)
  # When building LinkHut, additional warnings are generated from third-party frameworks
  set(extra_ignored_warnings_LIST
    "/wd4127" # conditional expression is constant
    "/wd4702" # unreachable code
  )
  if(LINK_BUILD_ASIO)
    set(extra_ignored_warnings_LIST
      ${extra_ignored_warnings_LIST}
      "/wd4267" # 'argument': conversion from '?' to '?', possible loss of data
      "/wd4477" # 'printf': format string '%?' requires an argument of type '?'
    )
  endif()
  string(REPLACE ";" " " extra_ignored_warnings "${extra_ignored_warnings_LIST}")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${extra_ignored_warnings}")
endif()

#  _     _       _    _   _       _
# | |   (_)_ __ | | _| | | |_   _| |_
# | |   | | '_ \| |/ / |_| | | | | __|
# | |___| | | | |   <|  _  | |_| | |_
# |_____|_|_| |_|_|\_\_| |_|\__,_|\__|
#

set(linkhut_HEADERS
  linkaudio/AudioEngine.hpp
  linkaudio/AudioPlatform.hpp
  ${link_HEADERS}
)

set(linkhut_SOURCES
  linkaudio/AudioEngine.cpp
  linkhut/main.cpp
)

add_executable(LinkHut
  ${linkhut_HEADERS}
  ${linkhut_SOURCES}
  ${linkhut_audio_SOURCES}
)
configure_linkhut_audio_sources(LinkHut)
configure_linkhut_executable(LinkHut)
source_group("LinkHut" FILES ${linkhut_HEADERS} ${linkhut_SOURCES})

#   ___  _     _       _    _   _       _
#  / _ \| |   (_)_ __ | | _| | | |_   _| |_
# | | | | |   | | '_ \| |/ / |_| | | | | __|
# | |_| | |___| | | | |   <|  _  | |_| | |_
#  \__\_\_____|_|_| |_|_|\_\_| |_|\__,_|\__|
#

if(LINK_BUILD_QT_EXAMPLES)

  set(CMAKE_AUTOMOC ON)
  set(CMAKE_INCLUDE_CURRENT_DIR ON)

  find_package(Qt5Quick REQUIRED)

  set(qlinkhut_HEADERS
    linkaudio/AudioEngine.hpp
    linkaudio/AudioPlatform.hpp
    qlinkhut/Controller.hpp
    ${link_HEADERS}
  )

  set(qlinkhut_SOURCES
    linkaudio/AudioEngine.cpp
    qlinkhut/Controller.cpp
    qlinkhut/main.cpp
    ${link_SOURCES}
  )
  source_group("QLinkHut" FILES ${qlinkhut_HEADERS} ${qlinkhut_SOURCES})
  qt5_add_resources(UI_RESOURCES qlinkhut/resources.qrc)

  add_executable(QLinkHut
    ${qlinkhut_HEADERS}
    ${qlinkhut_SOURCES}
    ${linkhut_audio_SOURCES}
    ${UI_RESOURCES}
  )
  target_link_libraries(QLinkHut Qt5::Quick)
  configure_linkhut_audio_sources(QLinkHut)
  configure_linkhut_executable(QLinkHut)

  # A silent version of QLinkHut that uses the Link application context instead of
  # the audio buffer context. It is the same as QLinkHut except that it doesn't
  # generate sound.

  add_executable(QLinkHutSilent
    ${qlinkhut_HEADERS}
    ${qlinkhut_SOURCES}
    linkaudio/AudioPlatform_Dummy.hpp
    ${UI_RESOURCES}
  )
  target_link_libraries(QLinkHutSilent Qt5::Quick)

  target_compile_definitions(QLinkHutSilent PRIVATE
    -DLINKHUT_AUDIO_PLATFORM_DUMMY=1
  )
  if(UNIX)
    set_target_properties(QLinkHutSilent
      PROPERTIES
      COMPILE_FLAGS "-Wno-unused"
    )
  endif()

  configure_linkhut_executable(QLinkHutSilent)
endif()