You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMakeLists.txt 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. # $Id: $
  2. #
  3. # For a "How-To" please refer to the Portaudio documentation at:
  4. # http://www.portaudio.com/trac/wiki/TutorialDir/Compile/CMake
  5. #
  6. CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
  7. # Check if the user is building PortAudio stand-alone or as part of a larger
  8. # project. If this is part of a larger project (i.e. the CMakeLists.txt has
  9. # been imported by some other CMakeLists.txt), we don't want to trump over
  10. # the top of that project's global settings.
  11. IF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_LIST_DIR})
  12. PROJECT(portaudio)
  13. # CMAKE_CONFIGURATION_TYPES only exists for multi-config generators (like
  14. # Visual Studio or Xcode). For these projects, we won't define
  15. # CMAKE_BUILD_TYPE as it does not make sense.
  16. IF(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  17. MESSAGE(STATUS "Setting CMAKE_BUILD_TYPE type to 'Debug' as none was specified.")
  18. SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
  19. SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
  20. ENDIF()
  21. SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
  22. IF(WIN32 AND MSVC)
  23. OPTION(PA_DLL_LINK_WITH_STATIC_RUNTIME "Link with static runtime libraries (minimizes runtime dependencies)" ON)
  24. IF(PA_DLL_LINK_WITH_STATIC_RUNTIME)
  25. FOREACH(flag_var
  26. CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  27. CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
  28. CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
  29. CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
  30. IF(${flag_var} MATCHES "/MD")
  31. STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
  32. ENDIF()
  33. ENDFOREACH()
  34. ENDIF()
  35. ENDIF()
  36. ENDIF()
  37. SET(PA_VERSION 19)
  38. SET(PA_PKGCONFIG_VERSION ${PA_VERSION})
  39. SET(PA_SOVERSION "${PA_VERSION}.0")
  40. # Most of the code from this point onwards is related to populating the
  41. # following variables:
  42. # PA_PUBLIC_INCLUDES - This contains the list of public PortAudio header
  43. # files. These files will be copied into /include paths on Unix'y
  44. # systems when "make install" is invoked.
  45. # PA_PRIVATE_INCLUDES - This contains the list of header files which
  46. # are not part of PortAudio, but are required by the various hostapis.
  47. # It is only used by CMake IDE generators (like Visual Studio) to
  48. # provide quick-links to useful headers. It has no impact on build
  49. # output.
  50. # PA_PRIVATE_INCLUDE_PATHS - This contains the list of include paths which
  51. # will be passed to the compiler while PortAudio is being built which
  52. # are not required by applications using the PortAudio API.
  53. # PA_PRIVATE_COMPILE_DEFINITIONS - This contains a list of preprocessor
  54. # macro definitions which will be set when compiling PortAudio source
  55. # files.
  56. # PA_SOURCES - This contains the list of source files which will be built
  57. # into the static and shared PortAudio libraries.
  58. # PA_NON_UNICODE_SOURCES - This also contains a list of source files which
  59. # will be build into the static and shared PortAudio libraries. However,
  60. # these sources will not have any unicode compiler definitions added
  61. # to them. This list should only contain external source dependencies.
  62. # PA_EXTRA_SHARED_SOURCES - Contains a list of extra files which will be
  63. # associated only with the shared PortAudio library. This only seems
  64. # relevant for Windows shared libraries which require a list of export
  65. # symbols.
  66. # Where other PA_* variables are set, these are almost always only used to
  67. # preserve the historic SOURCE_GROUP behavior (which again only has an impact
  68. # on IDE-style generators for visual appearance) or store the output of
  69. # find_library() calls.
  70. SET(PA_COMMON_INCLUDES
  71. src/common/pa_allocation.h
  72. src/common/pa_converters.h
  73. src/common/pa_cpuload.h
  74. src/common/pa_debugprint.h
  75. src/common/pa_dither.h
  76. src/common/pa_endianness.h
  77. src/common/pa_hostapi.h
  78. src/common/pa_memorybarrier.h
  79. src/common/pa_process.h
  80. src/common/pa_ringbuffer.h
  81. src/common/pa_stream.h
  82. src/common/pa_trace.h
  83. src/common/pa_types.h
  84. src/common/pa_util.h
  85. )
  86. SET(PA_COMMON_SOURCES
  87. src/common/pa_allocation.c
  88. src/common/pa_converters.c
  89. src/common/pa_cpuload.c
  90. src/common/pa_debugprint.c
  91. src/common/pa_dither.c
  92. src/common/pa_front.c
  93. src/common/pa_process.c
  94. src/common/pa_ringbuffer.c
  95. src/common/pa_stream.c
  96. src/common/pa_trace.c
  97. )
  98. SOURCE_GROUP("common" FILES ${PA_COMMON_INCLUDES} ${PA_COMMON_SOURCES})
  99. SET(PA_PUBLIC_INCLUDES include/portaudio.h)
  100. SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake_support)
  101. SET(PA_SKELETON_SOURCES src/hostapi/skeleton/pa_hostapi_skeleton.c)
  102. SOURCE_GROUP("hostapi\\skeleton" ${PA_SKELETON_SOURCES})
  103. SET(PA_SOURCES ${PA_COMMON_SOURCES} ${PA_SKELETON_SOURCES})
  104. SET(PA_PRIVATE_INCLUDE_PATHS src/common ${CMAKE_CURRENT_BINARY_DIR})
  105. IF(WIN32)
  106. SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS} _CRT_SECURE_NO_WARNINGS)
  107. SET(PA_PLATFORM_SOURCES
  108. src/os/win/pa_win_hostapis.c
  109. src/os/win/pa_win_util.c
  110. src/os/win/pa_win_waveformat.c
  111. src/os/win/pa_win_wdmks_utils.c
  112. src/os/win/pa_win_coinitialize.c)
  113. SET(PA_PLATFORM_INCLUDES
  114. src/os/win/pa_win_coinitialize.h
  115. src/os/win/pa_win_wdmks_utils.h)
  116. IF(MSVC)
  117. SET(PA_PLATFORM_SOURCES ${PA_PLATFORM_SOURCES} src/os/win/pa_x86_plain_converters.c)
  118. SET(PA_PLATFORM_INCLUDES ${PA_PLATFORM_INCLUDES} src/os/win/pa_x86_plain_converters.h)
  119. ELSE()
  120. SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS} _WIN32_WINNT=0x0501 WINVER=0x0501)
  121. SET(DEF_EXCLUDE_X86_PLAIN_CONVERTERS ";")
  122. ENDIF()
  123. SOURCE_GROUP("os\\win" FILES ${PA_PLATFORM_SOURCES} ${PA_PLATFORM_INCLUDES})
  124. SET(PA_SOURCES ${PA_SOURCES} ${PA_PLATFORM_SOURCES})
  125. SET(PA_PRIVATE_INCLUDES ${PA_PRIVATE_INCLUDES} ${PA_PLATFORM_INCLUDES})
  126. SET(PA_PRIVATE_INCLUDE_PATHS ${PA_PRIVATE_INCLUDE_PATHS} src/os/win)
  127. SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} winmm)
  128. # Try to find ASIO SDK (assumes that portaudio and asiosdk folders are side-by-side, see
  129. # http://www.portaudio.com/trac/wiki/TutorialDir/Compile/WindowsASIOMSVC)
  130. FIND_PACKAGE(ASIOSDK)
  131. IF(ASIOSDK_FOUND)
  132. OPTION(PA_USE_ASIO "Enable support for ASIO" ON)
  133. ELSE()
  134. OPTION(PA_USE_ASIO "Enable support for ASIO" OFF)
  135. ENDIF()
  136. IF(PA_USE_ASIO)
  137. SET(PA_PRIVATE_INCLUDE_PATHS ${PA_PRIVATE_INCLUDE_PATHS} ${ASIOSDK_ROOT_DIR}/common)
  138. SET(PA_PRIVATE_INCLUDE_PATHS ${PA_PRIVATE_INCLUDE_PATHS} ${ASIOSDK_ROOT_DIR}/host)
  139. SET(PA_PRIVATE_INCLUDE_PATHS ${PA_PRIVATE_INCLUDE_PATHS} ${ASIOSDK_ROOT_DIR}/host/pc)
  140. SET(PA_ASIO_SOURCES src/hostapi/asio/pa_asio.cpp src/hostapi/asio/iasiothiscallresolver.cpp)
  141. SET(PA_ASIOSDK_SOURCES ${ASIOSDK_ROOT_DIR}/common/asio.cpp ${ASIOSDK_ROOT_DIR}/host/pc/asiolist.cpp ${ASIOSDK_ROOT_DIR}/host/asiodrivers.cpp)
  142. SOURCE_GROUP("hostapi\\ASIO" FILES ${PA_ASIO_SOURCES})
  143. SOURCE_GROUP("hostapi\\ASIO\\ASIOSDK" FILES ${PA_ASIOSDK_SOURCES})
  144. SET(PA_PUBLIC_INCLUDES ${PA_PUBLIC_INCLUDES} include/pa_asio.h)
  145. SET(PA_SOURCES ${PA_SOURCES} ${PA_ASIO_SOURCES})
  146. SET(PA_NON_UNICODE_SOURCES ${PA_NON_UNICODE_SOURCES} ${PA_ASIOSDK_SOURCES})
  147. SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} ole32 uuid)
  148. ELSE()
  149. # Set variables for DEF file expansion
  150. SET(DEF_EXCLUDE_ASIO_SYMBOLS ";")
  151. ENDIF()
  152. OPTION(PA_USE_DS "Enable support for DirectSound" ON)
  153. IF(PA_USE_DS)
  154. IF(MINGW)
  155. MESSAGE(STATUS "DirectSound support will be built with DSound provided by MinGW.")
  156. OPTION(PA_USE_DIRECTSOUNDFULLDUPLEXCREATE "Use DirectSound full duplex create" OFF)
  157. ELSE(MINGW)
  158. OPTION(PA_USE_DIRECTSOUNDFULLDUPLEXCREATE "Use DirectSound full duplex create" ON)
  159. ENDIF(MINGW)
  160. MARK_AS_ADVANCED(PA_USE_DIRECTSOUNDFULLDUPLEXCREATE)
  161. IF(PA_USE_DIRECTSOUNDFULLDUPLEXCREATE)
  162. SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS} PAWIN_USE_DIRECTSOUNDFULLDUPLEXCREATE)
  163. ENDIF()
  164. SET(PA_DS_INCLUDES src/hostapi/dsound/pa_win_ds_dynlink.h)
  165. SET(PA_DS_SOURCES src/hostapi/dsound/pa_win_ds.c src/hostapi/dsound/pa_win_ds_dynlink.c)
  166. SOURCE_GROUP("hostapi\\dsound" FILES ${PA_DS_INCLUDES} ${PA_DS_SOURCES})
  167. SET(PA_PUBLIC_INCLUDES ${PA_PUBLIC_INCLUDES} include/pa_win_ds.h include/pa_win_waveformat.h)
  168. SET(PA_PRIVATE_INCLUDES ${PA_PRIVATE_INCLUDES} ${PA_DS_INCLUDES})
  169. SET(PA_SOURCES ${PA_SOURCES} ${PA_DS_SOURCES})
  170. SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} dsound)
  171. ENDIF(PA_USE_DS)
  172. OPTION(PA_USE_WMME "Enable support for MME" ON)
  173. IF(PA_USE_WMME)
  174. SET(PA_WMME_SOURCES src/hostapi/wmme/pa_win_wmme.c)
  175. SOURCE_GROUP("hostapi\\wmme" FILES ${PA_WMME_SOURCES})
  176. SET(PA_PUBLIC_INCLUDES ${PA_PUBLIC_INCLUDES} include/pa_win_wmme.h include/pa_win_waveformat.h)
  177. SET(PA_SOURCES ${PA_SOURCES} ${PA_WMME_SOURCES})
  178. SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} ole32 uuid)
  179. ENDIF()
  180. # MinGW versions below 4.93, especially non MinGW-w64 distributions may
  181. # break in the wasapi build. If an older MinGW version is required, WASAPI-
  182. # support needs to be disabled.
  183. OPTION(PA_USE_WASAPI "Enable support for WASAPI" ON)
  184. IF(PA_USE_WASAPI)
  185. SET(PA_WASAPI_SOURCES src/hostapi/wasapi/pa_win_wasapi.c)
  186. SOURCE_GROUP("hostapi\\wasapi" FILES ${PA_WASAPI_SOURCES})
  187. SET(PA_PUBLIC_INCLUDES ${PA_PUBLIC_INCLUDES} include/pa_win_wasapi.h include/pa_win_waveformat.h)
  188. SET(PA_SOURCES ${PA_SOURCES} ${PA_WASAPI_SOURCES})
  189. SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} ole32 uuid)
  190. ELSE()
  191. SET(DEF_EXCLUDE_WASAPI_SYMBOLS ";")
  192. ENDIF()
  193. OPTION(PA_USE_WDMKS "Enable support for WDMKS" ON)
  194. IF(PA_USE_WDMKS)
  195. SET(PA_WDMKS_SOURCES src/hostapi/wdmks/pa_win_wdmks.c)
  196. SOURCE_GROUP("hostapi\\wdmks" FILES ${PA_WDMKS_SOURCES})
  197. SET(PA_PUBLIC_INCLUDES ${PA_PUBLIC_INCLUDES} include/pa_win_wdmks.h)
  198. SET(PA_SOURCES ${PA_SOURCES} ${PA_WDMKS_SOURCES})
  199. SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} setupapi ole32 uuid)
  200. ENDIF()
  201. OPTION(PA_USE_WDMKS_DEVICE_INFO "Use WDM/KS API for device info" ON)
  202. MARK_AS_ADVANCED(PA_USE_WDMKS_DEVICE_INFO)
  203. IF(PA_USE_WDMKS_DEVICE_INFO)
  204. SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS} PAWIN_USE_WDMKS_DEVICE_INFO)
  205. ENDIF()
  206. SET(GENERATED_MESSAGE "CMake generated file, do NOT edit! Use CMake-GUI to change configuration instead.")
  207. CONFIGURE_FILE(cmake_support/template_portaudio.def ${CMAKE_CURRENT_BINARY_DIR}/portaudio_cmake.def @ONLY)
  208. CONFIGURE_FILE(cmake_support/options_cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/options_cmake.h @ONLY)
  209. SET(PA_PRIVATE_INCLUDES ${PA_PRIVATE_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR}/options_cmake.h)
  210. SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS} PORTAUDIO_CMAKE_GENERATED)
  211. SOURCE_GROUP("cmake_generated" FILES ${CMAKE_CURRENT_BINARY_DIR}/portaudio_cmake.def ${CMAKE_CURRENT_BINARY_DIR}/options_cmake.h)
  212. SET(PA_EXTRA_SHARED_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/portaudio_cmake.def)
  213. ELSE()
  214. SET(PA_PRIVATE_INCLUDE_PATHS ${PA_PRIVATE_INCLUDE_PATHS} src/os/unix)
  215. SET(PA_PLATFORM_SOURCES src/os/unix/pa_unix_hostapis.c src/os/unix/pa_unix_util.c)
  216. SOURCE_GROUP("os\\unix" FILES ${PA_PLATFORM_SOURCES})
  217. SET(PA_SOURCES ${PA_SOURCES} ${PA_PLATFORM_SOURCES})
  218. IF(APPLE)
  219. SET(CMAKE_MACOSX_RPATH 1)
  220. OPTION(PA_USE_COREAUDIO "Enable support for CoreAudio" ON)
  221. IF(PA_USE_COREAUDIO)
  222. SET(PA_COREAUDIO_SOURCES
  223. src/hostapi/coreaudio/pa_mac_core.c
  224. src/hostapi/coreaudio/pa_mac_core_blocking.c
  225. src/hostapi/coreaudio/pa_mac_core_utilities.c)
  226. SET(PA_COREAUDIO_INCLUDES
  227. src/hostapi/coreaudio/pa_mac_core_blocking.h
  228. src/hostapi/coreaudio/pa_mac_core_utilities.h)
  229. SOURCE_GROUP("hostapi\\coreaudio" FILES ${PA_COREAUDIO_SOURCES} ${PA_COREAUDIO_INCLUDES})
  230. SET(PA_PUBLIC_INCLUDES ${PA_PUBLIC_INCLUDES} include/pa_mac_core.h)
  231. SET(PA_PRIVATE_INCLUDES ${PA_PRIVATE_INCLUDES} ${PA_COREAUDIO_INCLUDES})
  232. SET(PA_SOURCES ${PA_SOURCES} ${PA_COREAUDIO_SOURCES})
  233. FIND_LIBRARY(COREAUDIO_LIBRARY CoreAudio REQUIRED)
  234. FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY AudioToolbox REQUIRED)
  235. FIND_LIBRARY(AUDIOUNIT_LIBRARY AudioUnit REQUIRED)
  236. FIND_LIBRARY(CARBON_LIBRARY Carbon REQUIRED)
  237. MARK_AS_ADVANCED(COREAUDIO_LIBRARY AUDIOTOOLBOX_LIBRARY AUDIOUNIT_LIBRARY CARBON_LIBRARY)
  238. SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} ${COREAUDIO_LIBRARY} ${AUDIOTOOLBOX_LIBRARY} ${AUDIOUNIT_LIBRARY} ${CARBON_LIBRARY})
  239. SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS} PA_USE_COREAUDIO)
  240. SET(PA_PKGCONFIG_LDFLAGS "${PA_PKGCONFIG_LDFLAGS} -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon")
  241. ENDIF()
  242. ELSEIF(UNIX)
  243. FIND_PACKAGE(Jack)
  244. IF(JACK_FOUND)
  245. OPTION(PA_USE_JACK "Enable support for Jack" ON)
  246. ELSE()
  247. OPTION(PA_USE_JACK "Enable support for Jack" OFF)
  248. ENDIF()
  249. IF(PA_USE_JACK)
  250. SET(PA_PRIVATE_INCLUDE_PATHS ${PA_PRIVATE_INCLUDE_PATHS} ${JACK_INCLUDE_DIRS})
  251. SET(PA_JACK_SOURCES src/hostapi/jack/pa_jack.c)
  252. SOURCE_GROUP("hostapi\\JACK" FILES ${PA_JACK_SOURCES})
  253. SET(PA_PUBLIC_INCLUDES ${PA_PUBLIC_INCLUDES} include/pa_jack.h)
  254. SET(PA_SOURCES ${PA_SOURCES} ${PA_JACK_SOURCES})
  255. SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS} PA_USE_JACK)
  256. SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} ${JACK_LIBRARIES})
  257. SET(PA_PKGCONFIG_LDFLAGS "${PA_PKGCONFIG_LDFLAGS} -ljack")
  258. ENDIF()
  259. FIND_PACKAGE(ALSA)
  260. IF(ALSA_FOUND)
  261. OPTION(PA_USE_ALSA "Enable support for ALSA" ON)
  262. ELSE()
  263. OPTION(PA_USE_ALSA "Enable support for ALSA" OFF)
  264. ENDIF()
  265. IF(PA_USE_ALSA)
  266. SET(PA_PRIVATE_INCLUDE_PATHS ${PA_PRIVATE_INCLUDE_PATHS} ${ALSA_INCLUDE_DIRS})
  267. SET(PA_ALSA_SOURCES src/hostapi/alsa/pa_linux_alsa.c)
  268. SOURCE_GROUP("hostapi\\ALSA" FILES ${PA_ALSA_SOURCES})
  269. SET(PA_PUBLIC_INCLUDES ${PA_PUBLIC_INCLUDES} include/pa_linux_alsa.h)
  270. SET(PA_SOURCES ${PA_SOURCES} ${PA_ALSA_SOURCES})
  271. SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS} PA_USE_ALSA)
  272. SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} ${ALSA_LIBRARIES})
  273. SET(PA_PKGCONFIG_LDFLAGS "${PA_PKGCONFIG_LDFLAGS} -lasound")
  274. ENDIF()
  275. ENDIF()
  276. SET(PA_PKGCONFIG_LDFLAGS "${PA_PKGCONFIG_LDFLAGS} -lm -lpthread")
  277. SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} m pthread)
  278. ENDIF()
  279. SOURCE_GROUP("include" FILES ${PA_PUBLIC_INCLUDES})
  280. SET(PA_INCLUDES ${PA_PRIVATE_INCLUDES} ${PA_PUBLIC_INCLUDES})
  281. IF(WIN32)
  282. OPTION(PA_UNICODE_BUILD "Enable Portaudio Unicode build" ON)
  283. IF(PA_UNICODE_BUILD)
  284. SET_SOURCE_FILES_PROPERTIES(${PA_SOURCES} PROPERTIES COMPILE_DEFINITIONS "UNICODE;_UNICODE")
  285. ENDIF()
  286. ENDIF()
  287. OPTION(PA_ENABLE_DEBUG_OUTPUT "Enable debug output for Portaudio" OFF)
  288. IF(PA_ENABLE_DEBUG_OUTPUT)
  289. SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS} PA_ENABLE_DEBUG_OUTPUT)
  290. ENDIF()
  291. INCLUDE(TestBigEndian)
  292. TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
  293. IF(IS_BIG_ENDIAN)
  294. SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS} PA_BIG_ENDIAN)
  295. ELSE()
  296. SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS} PA_LITTLE_ENDIAN)
  297. ENDIF()
  298. OPTION(PA_BUILD_STATIC "Build static library" ON)
  299. OPTION(PA_BUILD_SHARED "Build shared/dynamic library" ON)
  300. IF(MSVC)
  301. OPTION(PA_LIBNAME_ADD_SUFFIX "Add suffix _static to static library name" ON)
  302. ELSE()
  303. OPTION(PA_LIBNAME_ADD_SUFFIX "Add suffix _static to static library name" OFF)
  304. ENDIF()
  305. # MSVC: if PA_LIBNAME_ADD_SUFFIX is not used, and both static and shared libraries are
  306. # built, one, of import- and static libraries, will overwrite the other. In
  307. # embedded builds this is not an issue as they will only build the configuration
  308. # used in the host application.
  309. MARK_AS_ADVANCED(PA_LIBNAME_ADD_SUFFIX)
  310. IF(MSVC AND PA_BUILD_STATIC AND PA_BUILD_SHARED AND NOT PA_LIBNAME_ADD_SUFFIX)
  311. MESSAGE(WARNING "Building both shared and static libraries, and avoiding the suffix _static will lead to a name conflict")
  312. SET(PA_LIBNAME_ADD_SUFFIX ON CACHE BOOL "Forcing use of suffix _static to avoid name conflict between static and import library" FORCE)
  313. MESSAGE(WARNING "PA_LIBNAME_ADD_SUFFIX was set to ON")
  314. ENDIF()
  315. SET(PA_TARGETS "")
  316. IF(PA_BUILD_SHARED)
  317. LIST(APPEND PA_TARGETS portaudio)
  318. ADD_LIBRARY(portaudio SHARED ${PA_INCLUDES} ${PA_COMMON_INCLUDES} ${PA_SOURCES} ${PA_NON_UNICODE_SOURCES} ${PA_EXTRA_SHARED_SOURCES})
  319. SET_PROPERTY(TARGET portaudio APPEND_STRING PROPERTY COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS})
  320. TARGET_INCLUDE_DIRECTORIES(portaudio PRIVATE ${PA_PRIVATE_INCLUDE_PATHS})
  321. TARGET_INCLUDE_DIRECTORIES(portaudio PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
  322. TARGET_LINK_LIBRARIES(portaudio ${PA_LIBRARY_DEPENDENCIES})
  323. ENDIF()
  324. IF(PA_BUILD_STATIC)
  325. LIST(APPEND PA_TARGETS portaudio_static)
  326. ADD_LIBRARY(portaudio_static STATIC ${PA_INCLUDES} ${PA_COMMON_INCLUDES} ${PA_SOURCES} ${PA_NON_UNICODE_SOURCES})
  327. SET_PROPERTY(TARGET portaudio_static APPEND_STRING PROPERTY COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS})
  328. TARGET_INCLUDE_DIRECTORIES(portaudio_static PRIVATE ${PA_PRIVATE_INCLUDE_PATHS})
  329. TARGET_INCLUDE_DIRECTORIES(portaudio_static PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
  330. TARGET_LINK_LIBRARIES(portaudio_static ${PA_LIBRARY_DEPENDENCIES})
  331. IF(NOT PA_LIBNAME_ADD_SUFFIX)
  332. SET_PROPERTY(TARGET portaudio_static PROPERTY OUTPUT_NAME portaudio)
  333. ENDIF()
  334. ENDIF()
  335. IF(WIN32 AND MSVC)
  336. OPTION(PA_CONFIG_LIB_OUTPUT_PATH "Make sure that output paths are kept neat" OFF)
  337. IF(CMAKE_CL_64)
  338. SET(TARGET_POSTFIX x64)
  339. IF(PA_CONFIG_LIB_OUTPUT_PATH)
  340. SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin/x64)
  341. ENDIF()
  342. ELSE()
  343. SET(TARGET_POSTFIX x86)
  344. IF(PA_CONFIG_LIB_OUTPUT_PATH)
  345. SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin/Win32)
  346. ENDIF()
  347. ENDIF()
  348. IF(PA_BUILD_SHARED)
  349. IF(PA_LIBNAME_ADD_SUFFIX)
  350. SET_TARGET_PROPERTIES(portaudio PROPERTIES OUTPUT_NAME portaudio_${TARGET_POSTFIX})
  351. ELSE()
  352. SET_TARGET_PROPERTIES(portaudio PROPERTIES OUTPUT_NAME portaudio)
  353. ENDIF()
  354. ENDIF()
  355. IF(PA_BUILD_STATIC)
  356. IF(PA_LIBNAME_ADD_SUFFIX)
  357. SET_TARGET_PROPERTIES(portaudio_static PROPERTIES OUTPUT_NAME portaudio_static_${TARGET_POSTFIX})
  358. ELSE()
  359. SET_TARGET_PROPERTIES(portaudio_static PROPERTIES OUTPUT_NAME portaudio)
  360. ENDIF()
  361. ENDIF()
  362. ELSE()
  363. IF(APPLE AND CMAKE_VERSION VERSION_GREATER 3.4.2)
  364. OPTION(PA_OUTPUT_OSX_FRAMEWORK "Generate an OS X framework instead of the simple library" OFF)
  365. IF(PA_OUTPUT_OSX_FRAMEWORK)
  366. SET_TARGET_PROPERTIES(portaudio PROPERTIES
  367. FRAMEWORK TRUE
  368. MACOSX_FRAMEWORK_IDENTIFIER com.portaudio
  369. FRAMEWORK_VERSION A
  370. PUBLIC_HEADER "${PA_PUBLIC_INCLUDES}"
  371. VERSION ${PA_SOVERSION}
  372. SOVERSION ${PA_SOVERSION})
  373. ENDIF()
  374. ENDIF()
  375. ENDIF()
  376. # At least on Windows in embedded builds, portaudio's install target should likely
  377. # not be executed, as the library would usually already be installed as part of, and
  378. # by means of the host application.
  379. # The option below offers the option to avoid executing the portaudio install target
  380. # for cases in which the host-application executes install, but no independent install
  381. # of portaudio is wished.
  382. OPTION(PA_DISABLE_INSTALL "Disable targets install and uninstall (for embedded builds)" OFF)
  383. IF(NOT PA_OUTPUT_OSX_FRAMEWORK AND NOT PA_DISABLE_INSTALL)
  384. INCLUDE(CMakePackageConfigHelpers)
  385. CONFIGURE_PACKAGE_CONFIG_FILE(cmake_support/portaudioConfig.cmake.in ${CMAKE_BINARY_DIR}/cmake/portaudio/portaudioConfig.cmake
  386. INSTALL_DESTINATION "lib/cmake/portaudio"
  387. NO_CHECK_REQUIRED_COMPONENTS_MACRO)
  388. WRITE_BASIC_PACKAGE_VERSION_FILE(${CMAKE_BINARY_DIR}/cmake/portaudio/portaudioConfigVersion.cmake
  389. VERSION ${PA_VERSION}
  390. COMPATIBILITY SameMajorVersion)
  391. CONFIGURE_FILE(cmake_support/portaudio-2.0.pc.in ${CMAKE_CURRENT_BINARY_DIR}/portaudio-2.0.pc @ONLY)
  392. INSTALL(FILES README.txt DESTINATION share/doc/portaudio)
  393. INSTALL(FILES LICENSE.txt DESTINATION share/doc/portaudio)
  394. INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/portaudio-2.0.pc DESTINATION lib/pkgconfig)
  395. INSTALL(FILES ${PA_PUBLIC_INCLUDES} DESTINATION include)
  396. INSTALL(TARGETS ${PA_TARGETS}
  397. EXPORT portaudio-targets
  398. RUNTIME DESTINATION bin
  399. LIBRARY DESTINATION lib
  400. ARCHIVE DESTINATION lib)
  401. INSTALL(EXPORT portaudio-targets FILE "portaudioTargets.cmake" DESTINATION "lib/cmake/portaudio")
  402. EXPORT(TARGETS ${PA_TARGETS} FILE "${PROJECT_BINARY_DIR}/cmake/portaudio/portaudioTargets.cmake")
  403. INSTALL(FILES "${CMAKE_BINARY_DIR}/cmake/portaudio/portaudioConfig.cmake"
  404. "${CMAKE_BINARY_DIR}/cmake/portaudio/portaudioConfigVersion.cmake"
  405. DESTINATION "lib/cmake/portaudio")
  406. IF (NOT TARGET uninstall)
  407. CONFIGURE_FILE(
  408. "${CMAKE_CURRENT_SOURCE_DIR}/cmake_support/cmake_uninstall.cmake.in"
  409. "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  410. IMMEDIATE @ONLY)
  411. ADD_CUSTOM_TARGET(uninstall
  412. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
  413. ENDIF()
  414. ENDIF()
  415. # Prepared for inclusion of test files
  416. OPTION(PA_BUILD_TESTS "Include test projects" OFF)
  417. IF(PA_BUILD_TESTS)
  418. SUBDIRS(test)
  419. ENDIF()
  420. # Prepared for inclusion of test files
  421. OPTION(PA_BUILD_EXAMPLES "Include example projects" OFF)
  422. IF(PA_BUILD_EXAMPLES)
  423. SUBDIRS(examples)
  424. ENDIF()