blob: 1388a8db4997ae1a384ef26aff6dcbbfc750a1ec [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
9# Options
10option(BUILD_SHARED_LIBS "Build shared libraries" ON)
Bhalchandra Gajare986b8e32019-09-04 15:32:35 -070011option(TINYALSA_USES_PLUGINS "Whether or not to build with plugin support" OFF)
Ethan Sommerac41ba52020-05-22 20:31:20 -040012option(TINYALSA_BUILD_EXAMPLES "Build examples" ON)
13option(TINYALSA_BUILD_UTILS "Build utility tools" ON)
Bhalchandra Gajare986b8e32019-09-04 15:32:35 -070014
Ethan Sommerac41ba52020-05-22 20:31:20 -040015# Library
16add_library("tinyalsa"
Taylor Holberton18939502017-10-12 20:09:05 -040017 "src/pcm.c"
Bhalchandra Gajare986b8e32019-09-04 15:32:35 -070018 "src/pcm_hw.c"
19 "src/pcm_plugin.c"
20 "src/snd_card_plugin.c"
Bhalchandra Gajaree7c627d2019-06-19 15:30:42 -070021 "src/mixer.c"
22 "src/mixer_hw.c"
23 "src/mixer_plugin.c")
Taylor Holberton18939502017-10-12 20:09:05 -040024
Ethan Sommerac41ba52020-05-22 20:31:20 -040025set_property(TARGET "tinyalsa" PROPERTY PUBLIC_HEADER
26 "include/tinyalsa/attributes.h"
27 "include/tinyalsa/version.h"
28 "include/tinyalsa/asoundlib.h"
29 "include/tinyalsa/pcm.h"
30 "include/tinyalsa/plugin.h"
31 "include/tinyalsa/mixer.h")
Taylor Holberton18939502017-10-12 20:09:05 -040032
Ethan Sommerac41ba52020-05-22 20:31:20 -040033set_target_properties("tinyalsa" PROPERTIES
34 VERSION ${TinyALSA_VERSION}
35 SOVERSION ${TinyALSA_VERSION_MAJOR})
Taylor Holberton18939502017-10-12 20:09:05 -040036
Ethan Sommerac41ba52020-05-22 20:31:20 -040037target_include_directories("tinyalsa" PUBLIC
38 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
39 $<INSTALL_INTERFACE:include>)
40target_compile_definitions("tinyalsa" PRIVATE
41 $<$<BOOL:${TINYALSA_USES_PLUGINS}>:TINYALSA_USES_PLUGINS>)
42target_link_libraries("tinyalsa" PUBLIC ${CMAKE_DL_LIBS})
Taylor Holberton18939502017-10-12 20:09:05 -040043
Ethan Sommerac41ba52020-05-22 20:31:20 -040044# Examples
45if(TINYALSA_BUILD_EXAMPLES)
46 set(TINYALSA_EXAMPLES pcm-readi pcm-writei)
47else()
48 set(TINYALSA_EXAMPLES)
49endif()
Taylor Holberton18939502017-10-12 20:09:05 -040050
Ethan Sommerac41ba52020-05-22 20:31:20 -040051foreach(EXAMPLE IN LISTS TINYALSA_EXAMPLES)
52 add_executable("${EXAMPLE}" "examples/${EXAMPLE}.c")
53 target_link_libraries("${EXAMPLE}" PRIVATE "tinyalsa")
54endforeach()
Taylor Holberton0c601a32020-06-03 21:27:20 -040055
Ethan Sommerac41ba52020-05-22 20:31:20 -040056# Utilities
57if(TINYALSA_BUILD_UTILS)
58 set(TINYALSA_UTILS tinyplay tinycap tinypcminfo tinymix tinywavinfo)
59else()
60 set(TINYALSA_UTILS)
61endif()
62
63foreach(UTIL IN LISTS TINYALSA_UTILS)
64 add_executable("${UTIL}" "utils/${UTIL}.c")
65 target_link_libraries("${UTIL}" PRIVATE "tinyalsa")
66endforeach()
Taylor Holberton0c601a32020-06-03 21:27:20 -040067target_link_libraries("tinywavinfo" PRIVATE m)
Taylor Holberton18939502017-10-12 20:09:05 -040068
Ethan Sommerac41ba52020-05-22 20:31:20 -040069# Add C warning flags
70include(CheckCCompilerFlag)
71foreach(FLAG IN ITEMS -Wall -Wextra -Werror -Wfatal-errors)
72 string(TOUPPER "HAVE${FLAG}" HAVE_VAR)
73 string(REPLACE "-" "_" HAVE_VAR "${HAVE_VAR}")
74 check_c_compiler_flag("${FLAG}" "${HAVE_VAR}")
75 if("${${HAVE_VAR}}")
76 target_compile_options("tinyalsa" PRIVATE "${FLAG}")
77 foreach(UTIL IN LISTS TINYALSA_UTILS)
78 target_compile_options("${UTIL}" PRIVATE "${FLAG}")
79 endforeach()
80 endif()
81endforeach()
Taylor Holberton18939502017-10-12 20:09:05 -040082
Ethan Sommerac41ba52020-05-22 20:31:20 -040083# Install
84include(GNUInstallDirs)
85install(TARGETS "tinyalsa" ${TINYALSA_UTILS}
Khem Rajfe4f3c22019-12-16 22:58:41 -080086 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
87 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Ethan Sommerac41ba52020-05-22 20:31:20 -040088 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Ethan Sommer77eb4e32020-06-06 17:53:52 -040089 PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tinyalsa)