blob: 84de10b88d06706cd96d0ce3ac370b0268f521fc [file] [log] [blame]
Ethan Sommerac41ba52020-05-22 20:31:20 -04001cmake_minimum_required(VERSION 3.1)
Taylor Holberton18939502017-10-12 20:09:05 -04002
Ethan Sommerac41ba52020-05-22 20:31:20 -04003execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/version.sh -s print
4 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
5 OUTPUT_VARIABLE TINYALSA_VERSION)
Taylor Holberton18939502017-10-12 20:09:05 -04006
Ethan Sommerac41ba52020-05-22 20:31:20 -04007project("TinyALSA" VERSION ${TINYALSA_VERSION} LANGUAGES C)
8
Ethan Sommer0c279d82020-06-05 16:44:53 -04009set(CMAKE_C_STANDARD 99)
10set(CMAKE_C_STANDARD_REQUIRED ON)
11set(CMAKE_C_EXTENSIONS OFF)
12
Ethan Sommerac41ba52020-05-22 20:31:20 -040013# Options
14option(BUILD_SHARED_LIBS "Build shared libraries" ON)
Bhalchandra Gajare986b8e32019-09-04 15:32:35 -070015option(TINYALSA_USES_PLUGINS "Whether or not to build with plugin support" OFF)
Ethan Sommerac41ba52020-05-22 20:31:20 -040016option(TINYALSA_BUILD_EXAMPLES "Build examples" ON)
17option(TINYALSA_BUILD_UTILS "Build utility tools" ON)
Bhalchandra Gajare986b8e32019-09-04 15:32:35 -070018
Ethan Sommerac41ba52020-05-22 20:31:20 -040019# Library
20add_library("tinyalsa"
Taylor Holberton18939502017-10-12 20:09:05 -040021 "src/pcm.c"
Bhalchandra Gajare986b8e32019-09-04 15:32:35 -070022 "src/pcm_hw.c"
23 "src/pcm_plugin.c"
24 "src/snd_card_plugin.c"
Bhalchandra Gajaree7c627d2019-06-19 15:30:42 -070025 "src/mixer.c"
26 "src/mixer_hw.c"
27 "src/mixer_plugin.c")
Taylor Holberton18939502017-10-12 20:09:05 -040028
Ethan Sommerac41ba52020-05-22 20:31:20 -040029set_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")
Taylor Holberton18939502017-10-12 20:09:05 -040036
Ethan Sommerac41ba52020-05-22 20:31:20 -040037set_target_properties("tinyalsa" PROPERTIES
38 VERSION ${TinyALSA_VERSION}
39 SOVERSION ${TinyALSA_VERSION_MAJOR})
Taylor Holberton18939502017-10-12 20:09:05 -040040
Ethan Sommerac41ba52020-05-22 20:31:20 -040041target_include_directories("tinyalsa" PUBLIC
42 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
43 $<INSTALL_INTERFACE:include>)
44target_compile_definitions("tinyalsa" PRIVATE
Ethan Sommer0c279d82020-06-05 16:44:53 -040045 $<$<BOOL:${TINYALSA_USES_PLUGINS}>:TINYALSA_USES_PLUGINS>
46 PUBLIC _POSIX_C_SOURCE=200809L)
Ethan Sommerac41ba52020-05-22 20:31:20 -040047target_link_libraries("tinyalsa" PUBLIC ${CMAKE_DL_LIBS})
Taylor Holberton18939502017-10-12 20:09:05 -040048
Ethan Sommerac41ba52020-05-22 20:31:20 -040049# Examples
50if(TINYALSA_BUILD_EXAMPLES)
51 set(TINYALSA_EXAMPLES pcm-readi pcm-writei)
52else()
53 set(TINYALSA_EXAMPLES)
54endif()
Taylor Holberton18939502017-10-12 20:09:05 -040055
Ethan Sommerac41ba52020-05-22 20:31:20 -040056foreach(EXAMPLE IN LISTS TINYALSA_EXAMPLES)
57 add_executable("${EXAMPLE}" "examples/${EXAMPLE}.c")
58 target_link_libraries("${EXAMPLE}" PRIVATE "tinyalsa")
59endforeach()
Taylor Holberton0c601a32020-06-03 21:27:20 -040060
Ethan Sommerac41ba52020-05-22 20:31:20 -040061# 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()
Riff, Eric73100732020-09-16 21:38:54 -030072
73if(TINYALSA_BUILD_UTILS)
74 target_link_libraries("tinywavinfo" PRIVATE m)
75endif()
Taylor Holberton18939502017-10-12 20:09:05 -040076
Ethan Sommerac41ba52020-05-22 20:31:20 -040077# Add C warning flags
78include(CheckCCompilerFlag)
Ethan Sommer0c279d82020-06-05 16:44:53 -040079foreach(FLAG IN ITEMS -Wall -Wextra -Wpedantic -Werror -Wfatal-errors)
Ethan Sommerac41ba52020-05-22 20:31:20 -040080 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()
Taylor Holberton18939502017-10-12 20:09:05 -040090
Ethan Sommerac41ba52020-05-22 20:31:20 -040091# Install
92include(GNUInstallDirs)
93install(TARGETS "tinyalsa" ${TINYALSA_UTILS}
Khem Rajfe4f3c22019-12-16 22:58:41 -080094 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
95 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Ethan Sommerac41ba52020-05-22 20:31:20 -040096 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Ethan Sommer77eb4e32020-06-06 17:53:52 -040097 PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tinyalsa)