CMakeLists.txt 8.6 KB
Newer Older
1 2 3 4 5 6 7 8 9
# $Id: $
#
# For a "How-To" please refer to the Portaudio documentation at:
# http://www.portaudio.com/trac/wiki/TutorialDir/Compile/CMake
#
PROJECT( portaudio )

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

10 11
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)

robiwan's avatar
robiwan committed
12
OPTION(PA_CONFIG_LIB_OUTPUT_PATH "Make sure that output paths are kept neat" OFF)
13 14
IF(CMAKE_CL_64)
SET(TARGET_POSTFIX x64)
robiwan's avatar
robiwan committed
15
IF(PA_CONFIG_LIB_OUTPUT_PATH)
16
SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin/x64)
robiwan's avatar
robiwan committed
17
ENDIF(PA_CONFIG_LIB_OUTPUT_PATH)
18 19
ELSE(CMAKE_CL_64)
SET(TARGET_POSTFIX x86)
robiwan's avatar
robiwan committed
20
IF(PA_CONFIG_LIB_OUTPUT_PATH)
21
SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin/Win32)
robiwan's avatar
robiwan committed
22
ENDIF(PA_CONFIG_LIB_OUTPUT_PATH)
23 24
ENDIF(CMAKE_CL_64)

25 26 27 28 29
OPTION(PA_ENABLE_DEBUG_OUTPUT "Enable debug output for Portaudio" OFF)
IF(PA_ENABLE_DEBUG_OUTPUT)
ADD_DEFINITIONS(-DPA_ENABLE_DEBUG_OUTPUT)
ENDIF(PA_ENABLE_DEBUG_OUTPUT)

30
IF(WIN32 AND MSVC)
robiwan's avatar
robiwan committed
31 32
OPTION(PA_DLL_LINK_WITH_STATIC_RUNTIME "Link with static runtime libraries (minimizes runtime dependencies)" ON)
IF(PA_DLL_LINK_WITH_STATIC_RUNTIME)
33 34 35 36 37 38 39 40 41
  FOREACH(flag_var
		CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
		CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
		CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
		CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
    IF(${flag_var} MATCHES "/MD")
      STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
    ENDIF(${flag_var} MATCHES "/MD")
  ENDFOREACH(flag_var)
robiwan's avatar
robiwan committed
42
ENDIF(PA_DLL_LINK_WITH_STATIC_RUNTIME)
43 44 45 46

ENDIF(WIN32 AND MSVC)

IF(WIN32)
robiwan's avatar
robiwan committed
47
OPTION(PA_UNICODE_BUILD "Enable Portaudio Unicode build" ON)
48 49 50 51 52 53 54 55 56

SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_support)
# Try to find DirectX SDK
FIND_PACKAGE(DXSDK)
# Try to find ASIO SDK (assumes that portaudio and asiosdk folders are side-by-side, see
# http://www.portaudio.com/trac/wiki/TutorialDir/Compile/WindowsASIOMSVC)
FIND_PACKAGE(ASIOSDK)

IF(ASIOSDK_FOUND)
robiwan's avatar
robiwan committed
57
OPTION(PA_USE_ASIO "Enable support for ASIO" ON)
58
ELSE(ASIOSDK_FOUND)
robiwan's avatar
robiwan committed
59
OPTION(PA_USE_ASIO "Enable support for ASIO" OFF)
60 61
ENDIF(ASIOSDK_FOUND)
IF(DXSDK_FOUND)
robiwan's avatar
robiwan committed
62
OPTION(PA_USE_DS "Enable support for DirectSound" ON)
63
ELSE(DXSDK_FOUND)
robiwan's avatar
robiwan committed
64
OPTION(PA_USE_DS "Enable support for DirectSound" OFF)
65
ENDIF(DXSDK_FOUND)
robiwan's avatar
robiwan committed
66 67 68 69 70 71 72 73 74
OPTION(PA_USE_WMME "Enable support for MME" ON)
OPTION(PA_USE_WASAPI "Enable support for WASAPI" ON)
OPTION(PA_USE_WDMKS "Enable support for WDMKS" ON)
OPTION(PA_USE_WDMKS_DEVICE_INFO "Use WDM/KS API for device info" ON)
MARK_AS_ADVANCED(PA_USE_WDMKS_DEVICE_INFO)
IF(PA_USE_DS)
OPTION(PA_USE_DIRECTSOUNDFULLDUPLEXCREATE "Use DirectSound full duplex create" ON)
MARK_AS_ADVANCED(PA_USE_DIRECTSOUNDFULLDUPLEXCREATE)
ENDIF(PA_USE_DS)
75 76 77
ENDIF(WIN32)

# Set variables for DEF file expansion
robiwan's avatar
robiwan committed
78
IF(NOT PA_USE_ASIO)
79
SET(DEF_EXCLUDE_ASIO_SYMBOLS ";")
robiwan's avatar
robiwan committed
80
ENDIF(NOT PA_USE_ASIO)
81

robiwan's avatar
robiwan committed
82
IF(NOT PA_USE_WASAPI)
83
SET(DEF_EXCLUDE_WASAPI_SYMBOLS ";")
robiwan's avatar
robiwan committed
84
ENDIF(NOT PA_USE_WASAPI)
85

robiwan's avatar
robiwan committed
86
IF(PA_USE_WDMKS_DEVICE_INFO)
87
ADD_DEFINITIONS(-DPAWIN_USE_WDMKS_DEVICE_INFO)
robiwan's avatar
robiwan committed
88
ENDIF(PA_USE_WDMKS_DEVICE_INFO)
89

robiwan's avatar
robiwan committed
90
IF(PA_USE_DIRECTSOUNDFULLDUPLEXCREATE)
91
ADD_DEFINITIONS(-DPAWIN_USE_DIRECTSOUNDFULLDUPLEXCREATE)
robiwan's avatar
robiwan committed
92
ENDIF(PA_USE_DIRECTSOUNDFULLDUPLEXCREATE)
93 94 95 96 97 98

#######################################
IF(WIN32)
INCLUDE_DIRECTORIES(src/os/win)
ENDIF(WIN32)

robiwan's avatar
robiwan committed
99
IF(PA_USE_ASIO)
100 101 102 103
INCLUDE_DIRECTORIES(${ASIOSDK_ROOT_DIR}/common)
INCLUDE_DIRECTORIES(${ASIOSDK_ROOT_DIR}/host)
INCLUDE_DIRECTORIES(${ASIOSDK_ROOT_DIR}/host/pc)

robiwan's avatar
robiwan committed
104 105 106 107
SET(PA_ASIO_INCLUDES
  include/pa_asio.h
)  

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
SET(PA_ASIO_SOURCES 
  src/hostapi/asio/pa_asio.cpp
)  

SET(PA_ASIOSDK_SOURCES
  ${ASIOSDK_ROOT_DIR}/common/asio.cpp
  ${ASIOSDK_ROOT_DIR}/host/pc/asiolist.cpp
  ${ASIOSDK_ROOT_DIR}/host/asiodrivers.cpp
)

SOURCE_GROUP("hostapi\\ASIO" FILES
  ${PA_ASIO_SOURCES}
)

SOURCE_GROUP("hostapi\\ASIO\\ASIOSDK" FILES
  ${PA_ASIOSDK_SOURCES}
)
robiwan's avatar
robiwan committed
125
ENDIF(PA_USE_ASIO)
126

robiwan's avatar
robiwan committed
127
IF(PA_USE_DS)
128 129 130 131
INCLUDE_DIRECTORIES(${DXSDK_INCLUDE_DIR})
INCLUDE_DIRECTORIES(src/os/win)

SET(PA_DS_INCLUDES
robiwan's avatar
robiwan committed
132
  include/pa_win_ds.h
133 134 135 136 137 138 139 140 141 142 143 144
  src/hostapi/dsound/pa_win_ds_dynlink.h
)

SET(PA_DS_SOURCES
  src/hostapi/dsound/pa_win_ds.c
  src/hostapi/dsound/pa_win_ds_dynlink.c
)

SOURCE_GROUP("hostapi\\dsound" FILES
  ${PA_DS_INCLUDES}
  ${PA_DS_SOURCES}
)
robiwan's avatar
robiwan committed
145 146 147 148 149 150 151
ENDIF(PA_USE_DS)

IF(PA_USE_WMME)

SET(PA_WMME_INCLUDES
  include/pa_win_wmme.h
)
152 153 154 155 156 157 158 159

SET(PA_WMME_SOURCES
  src/hostapi/wmme/pa_win_wmme.c
)

SOURCE_GROUP("hostapi\\wmme" FILES
  ${PA_WMME_SOURCES}
)
robiwan's avatar
robiwan committed
160 161 162 163 164 165 166
ENDIF(PA_USE_WMME)

IF(PA_USE_WASAPI)

SET(PA_WASAPI_INCLUDES
  include/pa_win_wasapi.h
)
167 168 169 170 171 172 173 174

SET(PA_WASAPI_SOURCES
  src/hostapi/wasapi/pa_win_wasapi.c
)

SOURCE_GROUP("hostapi\\wasapi" FILES
  ${PA_WASAPI_SOURCES}
)
robiwan's avatar
robiwan committed
175 176 177
ENDIF(PA_USE_WASAPI)

IF(PA_USE_WDMKS)
178
ADD_DEFINITIONS(-DPA_WDMKS_NO_KSGUID_LIB)
robiwan's avatar
robiwan committed
179 180 181 182

SET(PA_WDMKS_INCLUDES
  include/pa_win_wdmks.h
)
183 184 185 186 187 188 189 190

SET(PA_WDMKS_SOURCES
  src/hostapi/wdmks/pa_win_wdmks.c
)

SOURCE_GROUP("hostapi\\wdmks" FILES
  ${PA_WDMKS_SOURCES}
)
robiwan's avatar
robiwan committed
191
ENDIF(PA_USE_WDMKS)
192 193 194 195 196 197 198 199 200 201 202 203

SET(PA_SKELETON_SOURCES
  src/hostapi/skeleton/pa_hostapi_skeleton.c
)

SOURCE_GROUP("hostapi\\skeleton" 
  ${PA_SKELETON_SOURCES})

#######################################
IF(WIN32)
SET(PA_INCLUDES 
  include/portaudio.h
robiwan's avatar
robiwan committed
204 205 206 207 208
  ${PA_ASIO_INCLUDES}
  ${PA_DS_INCLUDES}
  ${PA_WMME_INCLUDES}
  ${PA_WASAPI_INCLUDES}
  ${PA_WDMKS_INCLUDES}
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 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
)
ENDIF(WIN32)

SOURCE_GROUP("include" FILES
  ${PA_INCLUDES}
)

SET(PA_COMMON_INCLUDES
  src/common/pa_allocation.h
  src/common/pa_converters.h
  src/common/pa_cpuload.h
  src/common/pa_debugprint.h
  src/common/pa_dither.h
  src/common/pa_endianness.h
  src/common/pa_hostapi.h
  src/common/pa_memorybarrier.h
  src/common/pa_process.h
  src/common/pa_ringbuffer.h
  src/common/pa_stream.h
  src/common/pa_trace.h
  src/common/pa_types.h
  src/common/pa_util.h
)

SET(PA_COMMON_SOURCES
  src/common/pa_allocation.c
  src/common/pa_converters.c
  src/common/pa_cpuload.c
  src/common/pa_debugprint.c
  src/common/pa_dither.c
  src/common/pa_front.c
  src/common/pa_process.c
  src/common/pa_ringbuffer.c
  src/common/pa_stream.c
  src/common/pa_trace.c
)

SOURCE_GROUP("common" FILES
  ${PA_COMMON_INCLUDES}
  ${PA_COMMON_SOURCES}
)

SOURCE_GROUP("cmake_generated" FILES
  ${CMAKE_CURRENT_BINARY_DIR}/portaudio_cmake.def
  ${CMAKE_CURRENT_BINARY_DIR}/options_cmake.h
)

IF(WIN32)
SET(PA_PLATFORM_SOURCES 
  src/os/win/pa_win_hostapis.c
  src/os/win/pa_win_util.c
  src/os/win/pa_win_waveformat.c
  src/os/win/pa_win_wdmks_utils.c
  src/os/win/pa_win_coinitialize.c
  src/os/win/pa_x86_plain_converters.c
)

SOURCE_GROUP("os\\win" FILES
  ${PA_PLATFORM_SOURCES}
)
ENDIF(WIN32)

INCLUDE_DIRECTORIES( include )
INCLUDE_DIRECTORIES( src/common )

IF(WIN32 AND MSVC)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ENDIF(WIN32 AND MSVC)

ADD_DEFINITIONS(-DPORTAUDIO_CMAKE_GENERATED)
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} )

SET(SOURCES_LESS_ASIO_SDK
  ${PA_COMMON_SOURCES}
  ${PA_ASIO_SOURCES}
  ${PA_DS_SOURCES}
  ${PA_WMME_SOURCES}
  ${PA_WASAPI_SOURCES}
  ${PA_WDMKS_SOURCES}
  ${PA_SKELETON_SOURCES}
  ${PA_PLATFORM_SOURCES}
)

robiwan's avatar
robiwan committed
292
IF(PA_UNICODE_BUILD)
293 294 295 296 297
SET_SOURCE_FILES_PROPERTIES(
  ${SOURCES_LESS_ASIO_SDK}
  PROPERTIES
  COMPILE_DEFINITIONS "UNICODE;_UNICODE"
)
robiwan's avatar
robiwan committed
298
ENDIF(PA_UNICODE_BUILD)
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324

ADD_LIBRARY(portaudio SHARED
  ${PA_INCLUDES}
  ${PA_COMMON_INCLUDES}
  ${SOURCES_LESS_ASIO_SDK}
  ${PA_ASIOSDK_SOURCES}
  ${CMAKE_CURRENT_BINARY_DIR}/portaudio_cmake.def
  ${CMAKE_CURRENT_BINARY_DIR}/options_cmake.h
)

ADD_LIBRARY(portaudio_static STATIC
  ${PA_INCLUDES}
  ${PA_COMMON_INCLUDES}
  ${SOURCES_LESS_ASIO_SDK}
  ${PA_ASIOSDK_SOURCES}
  ${CMAKE_CURRENT_BINARY_DIR}/options_cmake.h
)

# Configure the exports file according to settings
SET(GENERATED_MESSAGE "CMake generated file, do NOT edit! Use CMake-GUI to change configuration instead.")
CONFIGURE_FILE( cmake_support/template_portaudio.def ${CMAKE_CURRENT_BINARY_DIR}/portaudio_cmake.def @ONLY )
# Configure header for options (PA_USE_xxx)
CONFIGURE_FILE( cmake_support/options_cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/options_cmake.h @ONLY )

IF(WIN32)
# If we use DirectSound, we need this for the library to be found (if not in VS project settings)
robiwan's avatar
robiwan committed
325
IF(PA_USE_DS AND DXSDK_FOUND)
326
TARGET_LINK_LIBRARIES(portaudio ${DXSDK_DSOUND_LIBRARY})
robiwan's avatar
robiwan committed
327
ENDIF(PA_USE_DS AND DXSDK_FOUND)
328 329

# If we use WDM/KS we need setupapi.lib
robiwan's avatar
robiwan committed
330
IF(PA_USE_WDMKS)
331
TARGET_LINK_LIBRARIES(portaudio setupapi)
robiwan's avatar
robiwan committed
332
ENDIF(PA_USE_WDMKS)
333

334 335 336 337
SET_TARGET_PROPERTIES(portaudio PROPERTIES OUTPUT_NAME portaudio_${TARGET_POSTFIX}
                                FOLDER "Portaudio")
SET_TARGET_PROPERTIES(portaudio_static PROPERTIES OUTPUT_NAME portaudio_static_${TARGET_POSTFIX}
                                FOLDER "Portaudio")
338 339
ENDIF(WIN32)

robiwan's avatar
robiwan committed
340 341
OPTION(PA_BUILD_TESTS "Include test projects" OFF)
OPTION(PA_BUILD_EXAMPLES "Include example projects" OFF)
342 343

# Prepared for inclusion of test files
robiwan's avatar
robiwan committed
344
IF(PA_BUILD_TESTS)
345
SUBDIRS(test)
robiwan's avatar
robiwan committed
346 347 348 349 350 351
ENDIF(PA_BUILD_TESTS)

# Prepared for inclusion of test files
IF(PA_BUILD_EXAMPLES)
SUBDIRS(examples)
ENDIF(PA_BUILD_EXAMPLES)
352 353 354

#################################