• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1cmake_minimum_required(VERSION 3.1)
2
3execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/version.sh -s print
4    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
5    OUTPUT_VARIABLE TINYALSA_VERSION)
6
7project("TinyALSA" VERSION ${TINYALSA_VERSION} LANGUAGES C)
8
9set(CMAKE_C_STANDARD 99)
10set(CMAKE_C_STANDARD_REQUIRED ON)
11set(CMAKE_C_EXTENSIONS OFF)
12
13# Options
14option(BUILD_SHARED_LIBS "Build shared libraries" ON)
15option(TINYALSA_USES_PLUGINS "Whether or not to build with plugin support" OFF)
16option(TINYALSA_BUILD_EXAMPLES "Build examples" ON)
17option(TINYALSA_BUILD_UTILS "Build utility tools" ON)
18
19# Library
20add_library("tinyalsa"
21    "src/pcm.c"
22    "src/pcm_hw.c"
23    "src/pcm_plugin.c"
24    "src/snd_card_plugin.c"
25    "src/mixer.c"
26    "src/mixer_hw.c"
27    "src/mixer_plugin.c")
28
29set_property(TARGET "tinyalsa" PROPERTY PUBLIC_HEADER
30    "include/tinyalsa/attributes.h"
31    "include/tinyalsa/version.h"
32    "include/tinyalsa/asoundlib.h"
33    "include/tinyalsa/pcm.h"
34    "include/tinyalsa/plugin.h"
35    "include/tinyalsa/mixer.h")
36
37set_target_properties("tinyalsa" PROPERTIES
38    VERSION ${TinyALSA_VERSION}
39    SOVERSION ${TinyALSA_VERSION_MAJOR})
40
41target_include_directories("tinyalsa" PUBLIC
42    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
43    $<INSTALL_INTERFACE:include>)
44target_compile_definitions("tinyalsa" PRIVATE
45    $<$<BOOL:${TINYALSA_USES_PLUGINS}>:TINYALSA_USES_PLUGINS>
46    PUBLIC _POSIX_C_SOURCE=200809L)
47target_link_libraries("tinyalsa" PUBLIC ${CMAKE_DL_LIBS})
48
49# Examples
50if(TINYALSA_BUILD_EXAMPLES)
51    set(TINYALSA_EXAMPLES pcm-readi pcm-writei)
52else()
53    set(TINYALSA_EXAMPLES)
54endif()
55
56foreach(EXAMPLE IN LISTS TINYALSA_EXAMPLES)
57    add_executable("${EXAMPLE}" "examples/${EXAMPLE}.c")
58    target_link_libraries("${EXAMPLE}" PRIVATE "tinyalsa")
59endforeach()
60
61# Utilities
62if(TINYALSA_BUILD_UTILS)
63    set(TINYALSA_UTILS tinyplay tinycap tinypcminfo tinymix tinywavinfo)
64else()
65    set(TINYALSA_UTILS)
66endif()
67
68foreach(UTIL IN LISTS TINYALSA_UTILS)
69    add_executable("${UTIL}" "utils/${UTIL}.c")
70    target_link_libraries("${UTIL}" PRIVATE "tinyalsa")
71endforeach()
72
73if(TINYALSA_BUILD_UTILS)
74    target_link_libraries("tinywavinfo" PRIVATE m)
75endif()
76
77# Add C warning flags
78include(CheckCCompilerFlag)
79foreach(FLAG IN ITEMS -Wall -Wextra -Wpedantic -Werror -Wfatal-errors)
80    string(TOUPPER "HAVE${FLAG}" HAVE_VAR)
81    string(REPLACE "-" "_" HAVE_VAR "${HAVE_VAR}")
82    check_c_compiler_flag("${FLAG}" "${HAVE_VAR}")
83    if("${${HAVE_VAR}}")
84        target_compile_options("tinyalsa" PRIVATE "${FLAG}")
85        foreach(UTIL IN LISTS TINYALSA_UTILS)
86            target_compile_options("${UTIL}" PRIVATE "${FLAG}")
87        endforeach()
88    endif()
89endforeach()
90
91# Install
92include(GNUInstallDirs)
93install(TARGETS "tinyalsa" ${TINYALSA_UTILS}
94    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
95    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
96    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
97    PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tinyalsa)
98