CMake Lists
CMake Lists
#
# For a "How-To" please refer to the Portaudio documentation at:
# http://www.portaudio.com/trac/wiki/TutorialDir/Compile/CMake
#
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(PA_VERSION 19)
SET(PA_PKGCONFIG_VERSION ${PA_VERSION})
SET(PA_SOVERSION "${PA_VERSION}.0")
# Most of the code from this point onwards is related to populating the
# following variables:
# PA_PUBLIC_INCLUDES - This contains the list of public PortAudio header
# files. These files will be copied into /include paths on Unix'y
# systems when "make install" is invoked.
# PA_PRIVATE_INCLUDES - This contains the list of header files which
# are not part of PortAudio, but are required by the various hostapis.
# It is only used by CMake IDE generators (like Visual Studio) to
# provide quick-links to useful headers. It has no impact on build
# output.
# PA_PRIVATE_INCLUDE_PATHS - This contains the list of include paths which
# will be passed to the compiler while PortAudio is being built which
# are not required by applications using the PortAudio API.
# PA_PRIVATE_COMPILE_DEFINITIONS - This contains a list of preprocessor
# macro definitions which will be set when compiling PortAudio source
# files.
# PA_SOURCES - This contains the list of source files which will be built
# into the static and shared PortAudio libraries.
# PA_NON_UNICODE_SOURCES - This also contains a list of source files which
# will be build into the static and shared PortAudio libraries. However,
# these sources will not have any unicode compiler definitions added
# to them. This list should only contain external source dependencies.
# PA_EXTRA_SHARED_SOURCES - Contains a list of extra files which will be
# associated only with the shared PortAudio library. This only seems
# relevant for Windows shared libraries which require a list of export
# symbols.
# Where other PA_* variables are set, these are almost always only used to
# preserve the historic SOURCE_GROUP behavior (which again only has an impact
# on IDE-style generators for visual appearance) or store the output of
# find_library() calls.
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
)
SET(PA_PUBLIC_INCLUDES include/portaudio.h)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} $
{CMAKE_CURRENT_SOURCE_DIR}/cmake_support)
SET(PA_SKELETON_SOURCES src/hostapi/skeleton/pa_hostapi_skeleton.c)
SOURCE_GROUP("hostapi\\skeleton" ${PA_SKELETON_SOURCES})
SET(PA_SOURCES ${PA_COMMON_SOURCES} ${PA_SKELETON_SOURCES})
SET(PA_PRIVATE_INCLUDE_PATHS src/common ${CMAKE_CURRENT_BINARY_DIR})
IF(WIN32)
SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS}
_CRT_SECURE_NO_WARNINGS)
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)
SET(PA_PLATFORM_INCLUDES
src/os/win/pa_win_coinitialize.h
src/os/win/pa_win_wdmks_utils.h)
IF(MSVC)
SET(PA_PLATFORM_SOURCES ${PA_PLATFORM_SOURCES}
src/os/win/pa_x86_plain_converters.c)
SET(PA_PLATFORM_INCLUDES ${PA_PLATFORM_INCLUDES}
src/os/win/pa_x86_plain_converters.h)
ELSE()
SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS}
_WIN32_WINNT=0x0501 WINVER=0x0501)
SET(DEF_EXCLUDE_X86_PLAIN_CONVERTERS ";")
ENDIF()
# 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)
OPTION(PA_USE_ASIO "Enable support for ASIO" ON)
ELSE()
OPTION(PA_USE_ASIO "Enable support for ASIO" OFF)
ENDIF()
IF(PA_USE_ASIO)
SET(PA_PRIVATE_INCLUDE_PATHS ${PA_PRIVATE_INCLUDE_PATHS} $
{ASIOSDK_ROOT_DIR}/common)
SET(PA_PRIVATE_INCLUDE_PATHS ${PA_PRIVATE_INCLUDE_PATHS} $
{ASIOSDK_ROOT_DIR}/host)
SET(PA_PRIVATE_INCLUDE_PATHS ${PA_PRIVATE_INCLUDE_PATHS} $
{ASIOSDK_ROOT_DIR}/host/pc)
SET(PA_ASIO_SOURCES src/hostapi/asio/pa_asio.cpp
src/hostapi/asio/iasiothiscallresolver.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})
SET(PA_PUBLIC_INCLUDES ${PA_PUBLIC_INCLUDES} include/pa_asio.h)
SET(PA_SOURCES ${PA_SOURCES} ${PA_ASIO_SOURCES})
SET(PA_NON_UNICODE_SOURCES ${PA_NON_UNICODE_SOURCES} ${PA_ASIOSDK_SOURCES})
SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} ole32 uuid)
ELSE()
# Set variables for DEF file expansion
SET(DEF_EXCLUDE_ASIO_SYMBOLS ";")
ENDIF()
SET(PA_EXTRA_SHARED_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/portaudio_cmake.def)
ELSE()
IF(APPLE)
SET(CMAKE_MACOSX_RPATH 1)
OPTION(PA_USE_COREAUDIO "Enable support for CoreAudio" ON)
IF(PA_USE_COREAUDIO)
SET(PA_COREAUDIO_SOURCES
src/hostapi/coreaudio/pa_mac_core.c
src/hostapi/coreaudio/pa_mac_core_blocking.c
src/hostapi/coreaudio/pa_mac_core_utilities.c)
SET(PA_COREAUDIO_INCLUDES
src/hostapi/coreaudio/pa_mac_core_blocking.h
src/hostapi/coreaudio/pa_mac_core_utilities.h)
SOURCE_GROUP("hostapi\\coreaudio" FILES ${PA_COREAUDIO_SOURCES} $
{PA_COREAUDIO_INCLUDES})
SET(PA_PUBLIC_INCLUDES ${PA_PUBLIC_INCLUDES} include/pa_mac_core.h)
SET(PA_PRIVATE_INCLUDES ${PA_PRIVATE_INCLUDES} ${PA_COREAUDIO_INCLUDES})
SET(PA_SOURCES ${PA_SOURCES} ${PA_COREAUDIO_SOURCES})
ELSEIF(UNIX)
FIND_PACKAGE(Jack)
IF(JACK_FOUND)
OPTION(PA_USE_JACK "Enable support for Jack" ON)
ELSE()
OPTION(PA_USE_JACK "Enable support for Jack" OFF)
ENDIF()
IF(PA_USE_JACK)
SET(PA_PRIVATE_INCLUDE_PATHS ${PA_PRIVATE_INCLUDE_PATHS} $
{JACK_INCLUDE_DIRS})
SET(PA_JACK_SOURCES src/hostapi/jack/pa_jack.c)
SOURCE_GROUP("hostapi\\JACK" FILES ${PA_JACK_SOURCES})
SET(PA_PUBLIC_INCLUDES ${PA_PUBLIC_INCLUDES} include/pa_jack.h)
SET(PA_SOURCES ${PA_SOURCES} ${PA_JACK_SOURCES})
SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS}
PA_USE_JACK)
SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} ${JACK_LIBRARIES})
SET(PA_PKGCONFIG_LDFLAGS "${PA_PKGCONFIG_LDFLAGS} -ljack")
ENDIF()
FIND_PACKAGE(ALSA)
IF(ALSA_FOUND)
OPTION(PA_USE_ALSA "Enable support for ALSA" ON)
OPTION(PA_ALSA_DYNAMIC "Enable loading ALSA through dlopen" OFF)
ELSE()
OPTION(PA_USE_ALSA "Enable support for ALSA" OFF)
ENDIF()
IF(PA_USE_ALSA)
SET(PA_PRIVATE_INCLUDE_PATHS ${PA_PRIVATE_INCLUDE_PATHS} $
{ALSA_INCLUDE_DIRS})
SET(PA_ALSA_SOURCES src/hostapi/alsa/pa_linux_alsa.c)
SOURCE_GROUP("hostapi\\ALSA" FILES ${PA_ALSA_SOURCES})
SET(PA_PUBLIC_INCLUDES ${PA_PUBLIC_INCLUDES} include/pa_linux_alsa.h)
SET(PA_SOURCES ${PA_SOURCES} ${PA_ALSA_SOURCES})
SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS}
PA_USE_ALSA)
IF(PA_ALSA_DYNAMIC)
SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS}
PA_ALSA_DYNAMIC)
SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} ${CMAKE_DL_LIBS})
SET(PA_PKGCONFIG_LDFLAGS "${PA_PKGCONFIG_LDFLAGS} -l${CMAKE_DL_LIBS}")
ELSE()
SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} ${ALSA_LIBRARIES})
SET(PA_PKGCONFIG_LDFLAGS "${PA_PKGCONFIG_LDFLAGS} -lasound")
ENDIF()
ENDIF()
ENDIF()
ENDIF()
IF(WIN32)
OPTION(PA_UNICODE_BUILD "Enable Portaudio Unicode build" ON)
IF(PA_UNICODE_BUILD)
SET_SOURCE_FILES_PROPERTIES(${PA_SOURCES} PROPERTIES COMPILE_DEFINITIONS
"UNICODE;_UNICODE")
ENDIF()
ENDIF()
INCLUDE(TestBigEndian)
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
IF(IS_BIG_ENDIAN)
SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS}
PA_BIG_ENDIAN)
ELSE()
SET(PA_PRIVATE_COMPILE_DEFINITIONS ${PA_PRIVATE_COMPILE_DEFINITIONS}
PA_LITTLE_ENDIAN)
ENDIF()
IF(MSVC)
OPTION(PA_LIBNAME_ADD_SUFFIX "Add suffix _static to static library name" ON)
ELSE()
OPTION(PA_LIBNAME_ADD_SUFFIX "Add suffix _static to static library name" OFF)
ENDIF()
# MSVC: if PA_LIBNAME_ADD_SUFFIX is not used, and both static and shared libraries
are
# built, one, of import- and static libraries, will overwrite the other. In
# embedded builds this is not an issue as they will only build the configuration
# used in the host application.
MARK_AS_ADVANCED(PA_LIBNAME_ADD_SUFFIX)
IF(MSVC AND PA_BUILD_STATIC AND PA_BUILD_SHARED AND NOT PA_LIBNAME_ADD_SUFFIX)
MESSAGE(WARNING "Building both shared and static libraries, and avoiding the
suffix _static will lead to a name conflict")
SET(PA_LIBNAME_ADD_SUFFIX ON CACHE BOOL "Forcing use of suffix _static to avoid
name conflict between static and import library" FORCE)
MESSAGE(WARNING "PA_LIBNAME_ADD_SUFFIX was set to ON")
ENDIF()
SET(PA_TARGETS "")
IF(PA_BUILD_SHARED)
LIST(APPEND PA_TARGETS portaudio)
ADD_LIBRARY(portaudio SHARED ${PA_INCLUDES} ${PA_COMMON_INCLUDES} ${PA_SOURCES} $
{PA_NON_UNICODE_SOURCES} ${PA_EXTRA_SHARED_SOURCES})
SET_PROPERTY(TARGET portaudio APPEND_STRING PROPERTY COMPILE_DEFINITIONS $
{PA_PRIVATE_COMPILE_DEFINITIONS})
TARGET_INCLUDE_DIRECTORIES(portaudio PRIVATE ${PA_PRIVATE_INCLUDE_PATHS})
TARGET_INCLUDE_DIRECTORIES(portaudio PUBLIC "$<BUILD_INTERFACE:$
{CMAKE_CURRENT_SOURCE_DIR}/include>" "$<INSTALL_INTERFACE:include>")
TARGET_LINK_LIBRARIES(portaudio ${PA_LIBRARY_DEPENDENCIES})
ENDIF()
IF(PA_BUILD_STATIC)
LIST(APPEND PA_TARGETS portaudio_static)
ADD_LIBRARY(portaudio_static STATIC ${PA_INCLUDES} ${PA_COMMON_INCLUDES} $
{PA_SOURCES} ${PA_NON_UNICODE_SOURCES})
SET_PROPERTY(TARGET portaudio_static APPEND_STRING PROPERTY COMPILE_DEFINITIONS $
{PA_PRIVATE_COMPILE_DEFINITIONS})
TARGET_INCLUDE_DIRECTORIES(portaudio_static PRIVATE ${PA_PRIVATE_INCLUDE_PATHS})
TARGET_INCLUDE_DIRECTORIES(portaudio_static PUBLIC "$<BUILD_INTERFACE:$
{CMAKE_CURRENT_SOURCE_DIR}/include>" "$<INSTALL_INTERFACE:include>")
TARGET_LINK_LIBRARIES(portaudio_static ${PA_LIBRARY_DEPENDENCIES})
IF(NOT PA_LIBNAME_ADD_SUFFIX)
SET_PROPERTY(TARGET portaudio_static PROPERTY OUTPUT_NAME portaudio)
ENDIF()
ENDIF()
CONFIGURE_PACKAGE_CONFIG_FILE(cmake_support/portaudioConfig.cmake.in $
{CMAKE_BINARY_DIR}/cmake/portaudio/portaudioConfig.cmake
INSTALL_DESTINATION "lib/cmake/portaudio"
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
WRITE_BASIC_PACKAGE_VERSION_FILE($
{CMAKE_BINARY_DIR}/cmake/portaudio/portaudioConfigVersion.cmake
VERSION ${PA_VERSION}
COMPATIBILITY SameMajorVersion)
CONFIGURE_FILE(cmake_support/portaudio-2.0.pc.in $
{CMAKE_CURRENT_BINARY_DIR}/portaudio-2.0.pc @ONLY)
INSTALL(FILES README.md DESTINATION share/doc/portaudio)
INSTALL(FILES LICENSE.txt DESTINATION share/doc/portaudio)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/portaudio-2.0.pc DESTINATION
lib/pkgconfig)
INSTALL(FILES ${PA_PUBLIC_INCLUDES} DESTINATION include)
INSTALL(TARGETS ${PA_TARGETS}
EXPORT portaudio-targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
INSTALL(EXPORT portaudio-targets FILE "portaudioTargets.cmake" DESTINATION
"lib/cmake/portaudio")
EXPORT(TARGETS ${PA_TARGETS} FILE "$
{PROJECT_BINARY_DIR}/cmake/portaudio/portaudioTargets.cmake")
INSTALL(FILES "${CMAKE_BINARY_DIR}/cmake/portaudio/portaudioConfig.cmake"
"${CMAKE_BINARY_DIR}/cmake/portaudio/portaudioConfigVersion.cmake"
DESTINATION "lib/cmake/portaudio")