aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 84de10b88d06706cd96d0ce3ac370b0268f521fc (plain)
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
cmake_minimum_required(VERSION 3.1)

execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/version.sh -s print
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    OUTPUT_VARIABLE TINYALSA_VERSION)

project("TinyALSA" VERSION ${TINYALSA_VERSION} LANGUAGES C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)

# Options
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(TINYALSA_USES_PLUGINS "Whether or not to build with plugin support" OFF)
option(TINYALSA_BUILD_EXAMPLES "Build examples" ON)
option(TINYALSA_BUILD_UTILS "Build utility tools" ON)

# Library
add_library("tinyalsa"
    "src/pcm.c"
    "src/pcm_hw.c"
    "src/pcm_plugin.c"
    "src/snd_card_plugin.c"
    "src/mixer.c"
    "src/mixer_hw.c"
    "src/mixer_plugin.c")

set_property(TARGET "tinyalsa" PROPERTY PUBLIC_HEADER
    "include/tinyalsa/attributes.h"
    "include/tinyalsa/version.h"
    "include/tinyalsa/asoundlib.h"
    "include/tinyalsa/pcm.h"
    "include/tinyalsa/plugin.h"
    "include/tinyalsa/mixer.h")

set_target_properties("tinyalsa" PROPERTIES
    VERSION ${TinyALSA_VERSION}
    SOVERSION ${TinyALSA_VERSION_MAJOR})

target_include_directories("tinyalsa" PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include>)
target_compile_definitions("tinyalsa" PRIVATE
    $<$<BOOL:${TINYALSA_USES_PLUGINS}>:TINYALSA_USES_PLUGINS>
    PUBLIC _POSIX_C_SOURCE=200809L)
target_link_libraries("tinyalsa" PUBLIC ${CMAKE_DL_LIBS})

# Examples
if(TINYALSA_BUILD_EXAMPLES)
    set(TINYALSA_EXAMPLES pcm-readi pcm-writei)
else()
    set(TINYALSA_EXAMPLES)
endif()

foreach(EXAMPLE IN LISTS TINYALSA_EXAMPLES)
    add_executable("${EXAMPLE}" "examples/${EXAMPLE}.c")
    target_link_libraries("${EXAMPLE}" PRIVATE "tinyalsa")
endforeach()

# Utilities
if(TINYALSA_BUILD_UTILS)
    set(TINYALSA_UTILS tinyplay tinycap tinypcminfo tinymix tinywavinfo)
else()
    set(TINYALSA_UTILS)
endif()

foreach(UTIL IN LISTS TINYALSA_UTILS)
    add_executable("${UTIL}" "utils/${UTIL}.c")
    target_link_libraries("${UTIL}" PRIVATE "tinyalsa")
endforeach()

if(TINYALSA_BUILD_UTILS)
    target_link_libraries("tinywavinfo" PRIVATE m)
endif()

# Add C warning flags
include(CheckCCompilerFlag)
foreach(FLAG IN ITEMS -Wall -Wextra -Wpedantic -Werror -Wfatal-errors)
    string(TOUPPER "HAVE${FLAG}" HAVE_VAR)
    string(REPLACE "-" "_" HAVE_VAR "${HAVE_VAR}")
    check_c_compiler_flag("${FLAG}" "${HAVE_VAR}")
    if("${${HAVE_VAR}}")
        target_compile_options("tinyalsa" PRIVATE "${FLAG}")
        foreach(UTIL IN LISTS TINYALSA_UTILS)
            target_compile_options("${UTIL}" PRIVATE "${FLAG}")
        endforeach()
    endif()
endforeach()

# Install
include(GNUInstallDirs)
install(TARGETS "tinyalsa" ${TINYALSA_UTILS}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tinyalsa)