Reformat CMake files

This commit is contained in:
badaix 2022-07-01 11:02:44 +02:00
parent fddcf46984
commit 4ced199c9e
5 changed files with 478 additions and 435 deletions

View file

@ -1,6 +1,10 @@
cmake_minimum_required(VERSION 3.2)
project(snapcast LANGUAGES CXX VERSION 0.26.0)
project(
snapcast
LANGUAGES CXX
VERSION 0.26.0)
set(PROJECT_DESCRIPTION "Multiroom client-server audio player")
set(PROJECT_URL "https://github.com/badaix/snapcast")
@ -15,69 +19,70 @@ option(UBSAN "Enable UndefinedBehaviorSanitizer" OFF)
option(TIDY "Enable clang tidy" OFF)
IF (REVISION)
add_compile_definitions(REVISION=\"${REVISION}\")
ENDIF()
IF (TIDY)
FIND_PROGRAM(CLANG_TIDY "clang-tidy")
IF(CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
ENDIF()
ENDIF()
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set (FREEBSD TRUE)
if (BUILD_CLIENT)
message(FATAL_ERROR "Snapclient not yet supported for FreeBSD, use \"-DBUILD_CLIENT=OFF\"")
endif()
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Android")
set (ANDROID TRUE)
if(REVISION)
add_compile_definitions(REVISION=\"${REVISION}\")
endif()
if(TIDY)
find_program(CLANG_TIDY "clang-tidy")
if(CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
endif()
endif()
if (MSVC)
# warning level 4 and all warnings as errors
# warning C4505: 'getArch': unreferenced local function has been removed
# warning C4458: declaration of 'size' hides class member
# warning C4459: declaration of 'query' hides global declaration
add_compile_options(/W4 /wd4458 /wd4459 /wd4505)
if (WERROR)
add_compile_options(/WX)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(FREEBSD TRUE)
if(BUILD_CLIENT)
message(
FATAL_ERROR
"Snapclient not yet supported for FreeBSD, use \"-DBUILD_CLIENT=OFF\"")
endif()
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
set(ANDROID TRUE)
endif()
if(MSVC)
# warning level 4 and all warnings as errors warning C4505: 'getArch':
# unreferenced local function has been removed warning C4458: declaration of
# 'size' hides class member warning C4459: declaration of 'query' hides global
# declaration
add_compile_options(/W4 /wd4458 /wd4459 /wd4505)
if(WERROR)
add_compile_options(/WX)
endif()
else()
# lots of warnings and all warnings as errors
add_compile_options(-Wall -Wextra -pedantic -Wno-unused-function)
if (MACOSX)
add_compile_options(-Wno-deprecated-declarations)
endif()
# lots of warnings and all warnings as errors
add_compile_options(-Wall -Wextra -pedantic -Wno-unused-function)
if(MACOSX)
add_compile_options(-Wno-deprecated-declarations)
endif()
if (WERROR)
add_compile_options(-Werror)
endif()
if(WERROR)
add_compile_options(-Werror)
endif()
if (ASAN)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()
if(ASAN)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()
if (TSAN)
add_compile_options(-fsanitize=thread)
add_link_options(-fsanitize=thread)
endif()
if(TSAN)
add_compile_options(-fsanitize=thread)
add_link_options(-fsanitize=thread)
endif()
if (UBSAN)
add_compile_options(-fsanitize=undefined)
add_link_options(-fsanitize=undefined)
endif()
if(UBSAN)
add_compile_options(-fsanitize=undefined)
add_link_options(-fsanitize=undefined)
endif()
endif()
include(GNUInstallDirs)
if(NOT WIN32)
option(BUILD_SERVER "Build Snapserver" ON) # no Windows server for now
option(BUILD_SERVER "Build Snapserver" ON) # no Windows server for now
endif()
option(BUILD_CLIENT "Build Snapclient" ON)
@ -90,41 +95,47 @@ option(BUILD_WITH_AVAHI "Build with AVAHI support" ON)
option(BUILD_WITH_EXPAT "Build with EXPAT support" ON)
option(BUILD_WITH_PULSE "Build with PulseAudio support" ON)
if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
message(FATAL_ERROR "One or both of BUILD_SHARED_LIBS or BUILD_STATIC_LIBS must be set to ON to build")
if(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
message(
FATAL_ERROR
"One or both of BUILD_SHARED_LIBS or BUILD_STATIC_LIBS must be set to ON to build"
)
endif()
if (NOT BUILD_CLIENT AND NOT BUILD_SERVER)
message(FATAL_ERROR "One or both of BUILD_CLIENT or BUILD_SERVER must be set to ON to build")
if(NOT BUILD_CLIENT AND NOT BUILD_SERVER)
message(
FATAL_ERROR
"One or both of BUILD_CLIENT or BUILD_SERVER must be set to ON to build")
endif()
# Configure paths
if(NOT DEFINED CMAKE_INSTALL_BINDIR)
SET(CMAKE_INSTALL_BINDIR bin CACHE
PATH "Output directory for binary files")
set(CMAKE_INSTALL_BINDIR
bin
CACHE PATH "Output directory for binary files")
endif()
if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
SET(CMAKE_INSTALL_LIBDIR lib CACHE PATH "Output directory for libraries")
set(CMAKE_INSTALL_LIBDIR
lib
CACHE PATH "Output directory for libraries")
endif()
if(NOT DEFINED CMAKE_INSTALL_INCLUDEDIR)
SET(CMAKE_INSTALL_INCLUDEDIR include CACHE
PATH "Output directory for header files")
set(CMAKE_INSTALL_INCLUDEDIR
include
CACHE PATH "Output directory for header files")
endif()
set(INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}"
"${CMAKE_INSTALL_INCLUDEDIR}")
set(INCLUDE_DIRS "${CMAKE_SOURCE_DIR}" "${CMAKE_INSTALL_INCLUDEDIR}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
add_compile_definitions(VERSION="${PROJECT_VERSION}")
if(NOT ANDROID)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
endif()
# Configure compiler options
@ -133,27 +144,27 @@ set(CMAKE_CXX_STANDARD 17)
include(${CMAKE_SOURCE_DIR}/cmake/TargetArch.cmake)
target_architecture(HOST_ARCH)
#message(STATUS "System name: ${CMAKE_SYSTEM_NAME}")
# message(STATUS "System name: ${CMAKE_SYSTEM_NAME}")
message(STATUS "Architecture: ${HOST_ARCH}")
#message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}")
# message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}")
if (ARCH)
message(STATUS "Using arch: ${ARCH}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${ARCH}")
if(ARCH)
message(STATUS "Using arch: ${ARCH}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${ARCH}")
endif()
include(CheckAtomic)
INCLUDE(TestBigEndian)
TEST_BIG_ENDIAN(BIGENDIAN)
IF(${BIGENDIAN})
add_compile_definitions(IS_BIG_ENDIAN)
ENDIF(${BIGENDIAN})
include(TestBigEndian)
test_big_endian(BIGENDIAN)
if(${BIGENDIAN})
add_compile_definitions(IS_BIG_ENDIAN)
endif(${BIGENDIAN})
# Check dependencies
if(NOT WIN32) # no PkgConfig on Windows...
find_package(PkgConfig REQUIRED)
find_package(PkgConfig REQUIRED)
endif()
find_package(Threads REQUIRED)
@ -164,234 +175,235 @@ include_directories(${INCLUDE_DIRS})
include(${CMAKE_SOURCE_DIR}/cmake/CheckCXX11StringSupport.cmake)
CHECK_CXX11_STRING_SUPPORT(HAS_CXX11_STRING_SUPPORT)
check_cxx11_string_support(HAS_CXX11_STRING_SUPPORT)
if(NOT HAS_CXX11_STRING_SUPPORT)
add_compile_definitions(NO_CPP11_STRING)
add_compile_definitions(NO_CPP11_STRING)
endif()
if(NOT WIN32 AND NOT ANDROID)
if(MACOSX)
set(BONJOUR_FOUND true)
if (BONJOUR_FOUND)
add_compile_definitions(HAS_BONJOUR)
endif (BONJOUR_FOUND)
if(MACOSX)
set(BONJOUR_FOUND true)
if(BONJOUR_FOUND)
add_compile_definitions(HAS_BONJOUR)
endif(BONJOUR_FOUND)
add_compile_definitions(FREEBSD MACOS HAS_DAEMON)
link_directories("/usr/local/lib")
list(APPEND INCLUDE_DIRS "/usr/local/include")
add_compile_definitions(FREEBSD MACOS HAS_DAEMON)
link_directories("/usr/local/lib")
list(APPEND INCLUDE_DIRS "/usr/local/include")
else()
pkg_search_module(ALSA REQUIRED alsa)
if(ALSA_FOUND)
add_compile_definitions(HAS_ALSA)
endif(ALSA_FOUND)
if(BUILD_WITH_PULSE)
pkg_search_module(PULSE libpulse)
if(PULSE_FOUND)
add_compile_definitions(HAS_PULSE)
endif(PULSE_FOUND)
endif(BUILD_WITH_PULSE)
if(BUILD_WITH_AVAHI)
pkg_search_module(AVAHI avahi-client)
if(AVAHI_FOUND)
add_compile_definitions(HAS_AVAHI)
else()
message(STATUS "avahi-client not found")
endif(AVAHI_FOUND)
endif(BUILD_WITH_AVAHI)
add_compile_definitions(HAS_DAEMON)
if(FREEBSD)
add_compile_definitions(FREEBSD)
link_directories("/usr/local/lib")
list(APPEND INCLUDE_DIRS "/usr/local/include")
endif()
endif()
pkg_search_module(SOXR soxr)
if(SOXR_FOUND)
add_compile_definitions(HAS_SOXR)
else()
message(STATUS "soxr not found")
endif(SOXR_FOUND)
if(BUILD_WITH_FLAC)
pkg_search_module(FLAC flac)
if(FLAC_FOUND)
add_compile_definitions(HAS_FLAC)
else()
message(STATUS "flac not found")
endif(FLAC_FOUND)
endif()
pkg_search_module(ALSA REQUIRED alsa)
if (ALSA_FOUND)
add_compile_definitions(HAS_ALSA)
endif (ALSA_FOUND)
if(BUILD_WITH_PULSE)
pkg_search_module(PULSE libpulse)
if (PULSE_FOUND)
add_compile_definitions(HAS_PULSE)
endif (PULSE_FOUND)
endif(BUILD_WITH_PULSE)
if(BUILD_WITH_AVAHI)
pkg_search_module(AVAHI avahi-client)
if (AVAHI_FOUND)
add_compile_definitions(HAS_AVAHI)
else()
message(STATUS "avahi-client not found")
endif (AVAHI_FOUND)
endif(BUILD_WITH_AVAHI)
add_compile_definitions(HAS_DAEMON)
if(FREEBSD)
add_compile_definitions(FREEBSD)
link_directories("/usr/local/lib")
list(APPEND INCLUDE_DIRS "/usr/local/include")
endif()
endif()
pkg_search_module(SOXR soxr)
if (SOXR_FOUND)
add_compile_definitions(HAS_SOXR)
if(BUILD_WITH_VORBIS OR BUILD_WITH_TREMOR)
pkg_search_module(OGG ogg)
if(OGG_FOUND)
add_compile_definitions(HAS_OGG)
else()
message(STATUS "soxr not found")
endif (SOXR_FOUND)
message(STATUS "ogg not found")
endif(OGG_FOUND)
endif()
if(BUILD_WITH_FLAC)
pkg_search_module(FLAC flac)
if (FLAC_FOUND)
add_compile_definitions(HAS_FLAC)
else()
message(STATUS "flac not found")
endif (FLAC_FOUND)
endif()
if(BUILD_WITH_VORBIS)
pkg_search_module(VORBIS vorbis)
if(VORBIS_FOUND)
add_compile_definitions(HAS_VORBIS)
endif(VORBIS_FOUND)
endif()
if(BUILD_WITH_VORBIS OR BUILD_WITH_TREMOR)
pkg_search_module(OGG ogg)
if (OGG_FOUND)
add_compile_definitions(HAS_OGG)
else()
message(STATUS "ogg not found")
endif (OGG_FOUND)
endif()
if(BUILD_WITH_TREMOR)
pkg_search_module(TREMOR vorbisidec)
if(TREMOR_FOUND)
add_compile_definitions(HAS_TREMOR)
endif(TREMOR_FOUND)
endif()
if(BUILD_WITH_VORBIS)
pkg_search_module(VORBIS vorbis)
if (VORBIS_FOUND)
add_compile_definitions(HAS_VORBIS)
endif (VORBIS_FOUND)
endif()
if((BUILD_WITH_VORBIS OR BUILD_WITH_TREMOR)
AND NOT VORBIS_FOUND
AND NOT TREMOR_FOUND)
message(STATUS "tremor and vorbis not found")
endif()
if(BUILD_WITH_TREMOR)
pkg_search_module(TREMOR vorbisidec)
if (TREMOR_FOUND)
add_compile_definitions(HAS_TREMOR)
endif (TREMOR_FOUND)
endif()
if(BUILD_WITH_VORBIS)
pkg_search_module(VORBISENC vorbisenc)
if(VORBISENC_FOUND)
add_compile_definitions(HAS_VORBIS_ENC)
else()
message(STATUS "vorbisenc not found")
endif(VORBISENC_FOUND)
endif()
if ((BUILD_WITH_VORBIS OR BUILD_WITH_TREMOR) AND NOT VORBIS_FOUND AND NOT TREMOR_FOUND)
message(STATUS "tremor and vorbis not found")
endif()
if(BUILD_WITH_OPUS)
pkg_search_module(OPUS opus)
if(OPUS_FOUND)
add_compile_definitions(HAS_OPUS)
else()
message(STATUS "opus not found")
endif(OPUS_FOUND)
endif()
if(BUILD_WITH_VORBIS)
pkg_search_module(VORBISENC vorbisenc)
if (VORBISENC_FOUND)
add_compile_definitions(HAS_VORBIS_ENC)
else()
message(STATUS "vorbisenc not found")
endif(VORBISENC_FOUND)
endif()
if(BUILD_WITH_OPUS)
pkg_search_module(OPUS opus)
if (OPUS_FOUND)
add_compile_definitions(HAS_OPUS)
else()
message(STATUS "opus not found")
endif (OPUS_FOUND)
endif()
if(BUILD_WITH_EXPAT)
pkg_search_module(EXPAT expat)
if (EXPAT_FOUND)
add_compile_definitions(HAS_EXPAT)
else()
message(STATUS "expat not found")
endif (EXPAT_FOUND)
endif()
if(BUILD_WITH_EXPAT)
pkg_search_module(EXPAT expat)
if(EXPAT_FOUND)
add_compile_definitions(HAS_EXPAT)
else()
message(STATUS "expat not found")
endif(EXPAT_FOUND)
endif()
endif()
if(NOT ANDROID)
find_package(Boost 1.74 REQUIRED)
find_package(Boost 1.74 REQUIRED)
else()
find_package(oboe REQUIRED CONFIG)
find_package(flac REQUIRED CONFIG)
find_package(ogg REQUIRED CONFIG)
find_package(opus REQUIRED CONFIG)
find_package(soxr REQUIRED CONFIG)
find_package(tremor REQUIRED CONFIG)
find_package(boost REQUIRED CONFIG)
find_package(oboe REQUIRED CONFIG)
find_package(flac REQUIRED CONFIG)
find_package(ogg REQUIRED CONFIG)
find_package(opus REQUIRED CONFIG)
find_package(soxr REQUIRED CONFIG)
find_package(tremor REQUIRED CONFIG)
find_package(boost REQUIRED CONFIG)
add_compile_definitions(HAS_OBOE)
add_compile_definitions(HAS_OPENSL)
add_compile_definitions(HAS_FLAC)
add_compile_definitions(HAS_OGG)
add_compile_definitions(HAS_OPUS)
add_compile_definitions(HAS_SOXR)
add_compile_definitions(HAS_TREMOR)
add_compile_definitions(HAS_OBOE)
add_compile_definitions(HAS_OPENSL)
add_compile_definitions(HAS_FLAC)
add_compile_definitions(HAS_OGG)
add_compile_definitions(HAS_OPUS)
add_compile_definitions(HAS_SOXR)
add_compile_definitions(HAS_TREMOR)
endif()
add_compile_definitions(BOOST_ERROR_CODE_HEADER_ONLY BOOST_ASIO_NO_TS_EXECUTORS)
if(WIN32)
include(FindPackageHandleStandardArgs)
SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
find_path(FLAC_INCLUDE_DIRS FLAC/all.h)
find_library(FLAC_LIBRARIES FLAC)
find_package_handle_standard_args(FLAC REQUIRED FLAC_INCLUDE_DIRS FLAC_LIBRARIES)
include(FindPackageHandleStandardArgs)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
find_path(OGG_INCLUDE_DIRS ogg/ogg.h)
find_library(OGG_LIBRARIES ogg)
find_package_handle_standard_args(Ogg REQUIRED OGG_INCLUDE_DIRS OGG_LIBRARIES)
find_path(FLAC_INCLUDE_DIRS FLAC/all.h)
find_library(FLAC_LIBRARIES FLAC)
find_package_handle_standard_args(FLAC REQUIRED FLAC_INCLUDE_DIRS
FLAC_LIBRARIES)
find_path(VORBIS_INCLUDE_DIRS vorbis/vorbisenc.h)
find_library(VORBIS_LIBRARIES vorbis)
find_package_handle_standard_args(Vorbis REQUIRED VORBIS_INCLUDE_DIRS VORBIS_LIBRARIES)
find_path(OGG_INCLUDE_DIRS ogg/ogg.h)
find_library(OGG_LIBRARIES ogg)
find_package_handle_standard_args(Ogg REQUIRED OGG_INCLUDE_DIRS OGG_LIBRARIES)
find_path(OPUS_INCLUDE_DIRS opus/opus.h)
find_library(OPUS_LIBRARIES opus)
find_package_handle_standard_args(Opus REQUIRED OPUS_INCLUDE_DIRS OPUS_LIBRARIES)
find_path(VORBIS_INCLUDE_DIRS vorbis/vorbisenc.h)
find_library(VORBIS_LIBRARIES vorbis)
find_package_handle_standard_args(Vorbis REQUIRED VORBIS_INCLUDE_DIRS
VORBIS_LIBRARIES)
find_path(SOXR_INCLUDE_DIRS soxr.h)
find_library(SOXR_LIBRARIES soxr)
find_package_handle_standard_args(Soxr REQUIRED SOXR_INCLUDE_DIRS SOXR_LIBRARIES)
find_path(OPUS_INCLUDE_DIRS opus/opus.h)
find_library(OPUS_LIBRARIES opus)
find_package_handle_standard_args(Opus REQUIRED OPUS_INCLUDE_DIRS
OPUS_LIBRARIES)
add_compile_definitions(NTDDI_VERSION=0x06020000 _WIN32_WINNT=0x0602 WINVER=0x0602 WINDOWS WIN32_LEAN_AND_MEAN UNICODE _UNICODE _CRT_SECURE_NO_WARNINGS)
add_compile_definitions(HAS_OGG HAS_VORBIS HAS_FLAC HAS_VORBIS_ENC HAS_OPUS HAS_WASAPI HAS_SOXR)
find_path(SOXR_INCLUDE_DIRS soxr.h)
find_library(SOXR_LIBRARIES soxr)
find_package_handle_standard_args(Soxr REQUIRED SOXR_INCLUDE_DIRS
SOXR_LIBRARIES)
add_compile_definitions(
NTDDI_VERSION=0x06020000
_WIN32_WINNT=0x0602
WINVER=0x0602
WINDOWS
WIN32_LEAN_AND_MEAN
UNICODE
_UNICODE
_CRT_SECURE_NO_WARNINGS)
add_compile_definitions(
HAS_OGG
HAS_VORBIS
HAS_FLAC
HAS_VORBIS_ENC
HAS_OPUS
HAS_WASAPI
HAS_SOXR)
endif()
list(APPEND CMAKE_REQUIRED_INCLUDES "${INCLUDE_DIRS}")
#include(${CMAKE_SOURCE_DIR}/cmake/SystemdService.cmake)
# include(${CMAKE_SOURCE_DIR}/cmake/SystemdService.cmake)
add_subdirectory(common)
if (BUILD_SERVER)
add_subdirectory(server)
if(BUILD_SERVER)
add_subdirectory(server)
endif()
if (BUILD_CLIENT)
add_subdirectory(client)
if(BUILD_CLIENT)
add_subdirectory(client)
endif()
if (BUILD_TESTS)
add_subdirectory(test)
endif (BUILD_TESTS)
if(BUILD_TESTS)
add_subdirectory(test)
endif(BUILD_TESTS)
FIND_PROGRAM(CLANG_FORMAT "clang-format")
IF(CLANG_FORMAT)
FILE(GLOB_RECURSE
CHECK_CXX_SOURCE_FILES
common/*.[ch]pp
client/*.[ch]pp
server/*.[ch]pp
)
find_program(CLANG_FORMAT "clang-format")
if(CLANG_FORMAT)
file(GLOB_RECURSE CHECK_CXX_SOURCE_FILES common/*.[ch]pp client/*.[ch]pp
server/*.[ch]pp)
list(REMOVE_ITEM CHECK_CXX_SOURCE_FILES "${CMAKE_SOURCE_DIR}/common/json.hpp")
list(REMOVE_ITEM CHECK_CXX_SOURCE_FILES "${CMAKE_SOURCE_DIR}/common/json.hpp")
ADD_CUSTOM_TARGET(
reformat-source
COMMAND
${CLANG_FORMAT}
-i
-style=file
${CHECK_CXX_SOURCE_FILES}
COMMENT "Auto formatting of all source files"
)
ENDIF()
add_custom_target(
reformat-source
COMMAND ${CLANG_FORMAT} -i -style=file ${CHECK_CXX_SOURCE_FILES}
COMMENT "Auto formatting of all source files")
endif()
find_program(CMAKE_FORMAT "cmake-format")
if(CMAKE_FORMAT)
file(GLOB_RECURSE CHECK_CMAKE_SOURCE_FILES CMakeLists.txt)
FIND_PROGRAM(CMAKE_FORMAT "cmake-format")
IF(CMAKE_FORMAT)
FILE(GLOB_RECURSE
CHECK_CMAKE_SOURCE_FILES
CMakeLists.txt
)
add_custom_target(
reformat-cmake
COMMAND ${CMAKE_FORMAT} -i ${CHECK_CMAKE_SOURCE_FILES}
COMMENT "Auto formatting of all CMakeLists.txt files")
endif()
ADD_CUSTOM_TARGET(
reformat-cmake
COMMAND
${CMAKE_FORMAT}
-i
${CHECK_CMAKE_SOURCE_FILES}
COMMENT "Auto formatting of all CMakeLists.txt files"
)
ENDIF()
add_custom_target(reformat
DEPENDS reformat-source reformat-cmake)
add_custom_target(reformat DEPENDS reformat-source reformat-cmake)

View file

@ -10,105 +10,118 @@ set(CLIENT_SOURCES
set(CLIENT_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ${ATOMIC_LIBRARY} common)
set(CLIENT_INCLUDE
${Boost_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/client
${CMAKE_SOURCE_DIR}/common)
set(CLIENT_INCLUDE ${Boost_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/client
${CMAKE_SOURCE_DIR}/common)
if(MACOSX)
# Bonjour
if (BONJOUR_FOUND)
list(APPEND CLIENT_SOURCES browseZeroConf/browse_bonjour.cpp)
endif (BONJOUR_FOUND)
# Bonjour
if(BONJOUR_FOUND)
list(APPEND CLIENT_SOURCES browseZeroConf/browse_bonjour.cpp)
endif(BONJOUR_FOUND)
# CoreAudio
add_compile_definitions(HAS_COREAUDIO)
list(APPEND CLIENT_SOURCES player/coreaudio_player.cpp)
find_library(COREAUDIO_LIB CoreAudio)
find_library(COREFOUNDATION_LIB CoreFoundation)
find_library(IOKIT_LIB IOKit)
find_library(AUDIOTOOLBOX_LIB AudioToolbox)
list(APPEND CLIENT_LIBRARIES ${COREAUDIO_LIB} ${COREFOUNDATION_LIB} ${IOKIT_LIB} ${AUDIOTOOLBOX_LIB})
elseif (WIN32)
list(APPEND CLIENT_SOURCES player/wasapi_player.cpp)
list(APPEND CLIENT_LIBRARIES wsock32 ws2_32 avrt ksuser iphlpapi)
# CoreAudio
add_compile_definitions(HAS_COREAUDIO)
list(APPEND CLIENT_SOURCES player/coreaudio_player.cpp)
find_library(COREAUDIO_LIB CoreAudio)
find_library(COREFOUNDATION_LIB CoreFoundation)
find_library(IOKIT_LIB IOKit)
find_library(AUDIOTOOLBOX_LIB AudioToolbox)
list(APPEND CLIENT_LIBRARIES ${COREAUDIO_LIB} ${COREFOUNDATION_LIB}
${IOKIT_LIB} ${AUDIOTOOLBOX_LIB})
elseif(WIN32)
list(APPEND CLIENT_SOURCES player/wasapi_player.cpp)
list(
APPEND
CLIENT_LIBRARIES
wsock32
ws2_32
avrt
ksuser
iphlpapi)
elseif(NOT ANDROID)
# Avahi
if (AVAHI_FOUND)
list(APPEND CLIENT_SOURCES browseZeroConf/browse_avahi.cpp)
list(APPEND CLIENT_LIBRARIES ${AVAHI_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${AVAHI_INCLUDE_DIRS})
endif (AVAHI_FOUND)
# Avahi
if(AVAHI_FOUND)
list(APPEND CLIENT_SOURCES browseZeroConf/browse_avahi.cpp)
list(APPEND CLIENT_LIBRARIES ${AVAHI_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${AVAHI_INCLUDE_DIRS})
endif(AVAHI_FOUND)
# ALSA
if (ALSA_FOUND)
list(APPEND CLIENT_SOURCES player/alsa_player.cpp)
list(APPEND CLIENT_LIBRARIES ${ALSA_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${ALSA_INCLUDE_DIRS})
endif (ALSA_FOUND)
# ALSA
if(ALSA_FOUND)
list(APPEND CLIENT_SOURCES player/alsa_player.cpp)
list(APPEND CLIENT_LIBRARIES ${ALSA_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${ALSA_INCLUDE_DIRS})
endif(ALSA_FOUND)
if (PULSE_FOUND)
list(APPEND CLIENT_SOURCES player/pulse_player.cpp)
list(APPEND CLIENT_LIBRARIES ${PULSE_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${PULSE_INCLUDE_DIRS})
endif (PULSE_FOUND)
endif (MACOSX)
if(PULSE_FOUND)
list(APPEND CLIENT_SOURCES player/pulse_player.cpp)
list(APPEND CLIENT_LIBRARIES ${PULSE_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${PULSE_INCLUDE_DIRS})
endif(PULSE_FOUND)
endif(MACOSX)
if (ANDROID)
list(APPEND CLIENT_LIBRARIES oboe::oboe)
list(APPEND CLIENT_LIBRARIES boost::boost)
list(APPEND CLIENT_LIBRARIES flac::flac)
list(APPEND CLIENT_LIBRARIES opus::opus)
list(APPEND CLIENT_LIBRARIES tremor::tremor)
list(APPEND CLIENT_LIBRARIES ogg::ogg)
list(APPEND CLIENT_SOURCES player/oboe_player.cpp)
list(APPEND CLIENT_SOURCES player/opensl_player.cpp)
list(APPEND CLIENT_SOURCES decoder/flac_decoder.cpp)
list(APPEND CLIENT_SOURCES decoder/ogg_decoder.cpp)
list(APPEND CLIENT_SOURCES decoder/opus_decoder.cpp)
list(APPEND CLIENT_LIBRARIES OpenSLES)
if(ANDROID)
list(APPEND CLIENT_LIBRARIES oboe::oboe)
list(APPEND CLIENT_LIBRARIES boost::boost)
list(APPEND CLIENT_LIBRARIES flac::flac)
list(APPEND CLIENT_LIBRARIES opus::opus)
list(APPEND CLIENT_LIBRARIES tremor::tremor)
list(APPEND CLIENT_LIBRARIES ogg::ogg)
list(APPEND CLIENT_SOURCES player/oboe_player.cpp)
list(APPEND CLIENT_SOURCES player/opensl_player.cpp)
list(APPEND CLIENT_SOURCES decoder/flac_decoder.cpp)
list(APPEND CLIENT_SOURCES decoder/ogg_decoder.cpp)
list(APPEND CLIENT_SOURCES decoder/opus_decoder.cpp)
list(APPEND CLIENT_LIBRARIES OpenSLES)
else()
# if OGG then tremor or vorbis
if (OGG_FOUND)
list(APPEND CLIENT_SOURCES decoder/ogg_decoder.cpp)
list(APPEND CLIENT_LIBRARIES ${OGG_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${OGG_INCLUDE_DIRS})
endif (OGG_FOUND)
# if OGG then tremor or vorbis
if(OGG_FOUND)
list(APPEND CLIENT_SOURCES decoder/ogg_decoder.cpp)
list(APPEND CLIENT_LIBRARIES ${OGG_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${OGG_INCLUDE_DIRS})
endif(OGG_FOUND)
# Tremor (fixed-point) or libvorbis (floating-point)
if (TREMOR_FOUND)
list(APPEND CLIENT_LIBRARIES ${TREMOR_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${TREMOR_INCLUDE_DIRS})
elseif (VORBIS_FOUND)
list(APPEND CLIENT_LIBRARIES ${VORBIS_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${VORBIS_INCLUDE_DIRS})
endif (TREMOR_FOUND)
# Tremor (fixed-point) or libvorbis (floating-point)
if(TREMOR_FOUND)
list(APPEND CLIENT_LIBRARIES ${TREMOR_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${TREMOR_INCLUDE_DIRS})
elseif(VORBIS_FOUND)
list(APPEND CLIENT_LIBRARIES ${VORBIS_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${VORBIS_INCLUDE_DIRS})
endif(TREMOR_FOUND)
if (FLAC_FOUND)
list(APPEND CLIENT_SOURCES decoder/flac_decoder.cpp)
list(APPEND CLIENT_LIBRARIES ${FLAC_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${FLAC_INCLUDE_DIRS})
endif (FLAC_FOUND)
if(FLAC_FOUND)
list(APPEND CLIENT_SOURCES decoder/flac_decoder.cpp)
list(APPEND CLIENT_LIBRARIES ${FLAC_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${FLAC_INCLUDE_DIRS})
endif(FLAC_FOUND)
if (OPUS_FOUND)
list(APPEND CLIENT_SOURCES decoder/opus_decoder.cpp)
list(APPEND CLIENT_LIBRARIES ${OPUS_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${OPUS_INCLUDE_DIRS})
endif (OPUS_FOUND)
if(OPUS_FOUND)
list(APPEND CLIENT_SOURCES decoder/opus_decoder.cpp)
list(APPEND CLIENT_LIBRARIES ${OPUS_LIBRARIES})
list(APPEND CLIENT_INCLUDE ${OPUS_INCLUDE_DIRS})
endif(OPUS_FOUND)
endif()
include_directories(${CLIENT_INCLUDE})
if (ANDROID)
add_executable(libsnapclient.so ${CLIENT_SOURCES})
target_link_libraries(libsnapclient.so ${CLIENT_LIBRARIES} log OpenSLES)
if(ANDROID)
add_executable(libsnapclient.so ${CLIENT_SOURCES})
target_link_libraries(libsnapclient.so ${CLIENT_LIBRARIES} log OpenSLES)
else()
add_executable(snapclient ${CLIENT_SOURCES})
target_link_libraries(snapclient ${CLIENT_LIBRARIES})
add_executable(snapclient ${CLIENT_SOURCES})
target_link_libraries(snapclient ${CLIENT_LIBRARIES})
install(TARGETS snapclient COMPONENT client DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(FILES snapclient.1 COMPONENT client DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
install(FILES etc/snapcast.svg COMPONENT client DESTINATION ${CMAKE_INSTALL_DATADIR}/pixmaps)
install(
TARGETS snapclient
COMPONENT client
DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(
FILES snapclient.1
COMPONENT client
DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
install(
FILES etc/snapcast.svg
COMPONENT client
DESTINATION ${CMAKE_INSTALL_DATADIR}/pixmaps)
endif()

View file

@ -1,19 +1,17 @@
set(SOURCES
resampler.cpp
sample_format.cpp)
set(SOURCES resampler.cpp sample_format.cpp)
if(NOT WIN32 AND NOT ANDROID)
list(APPEND SOURCES daemon.cpp)
list(APPEND SOURCES daemon.cpp)
endif()
if (SOXR_FOUND)
include_directories(${SOXR_INCLUDE_DIRS})
endif (SOXR_FOUND)
if(SOXR_FOUND)
include_directories(${SOXR_INCLUDE_DIRS})
endif(SOXR_FOUND)
add_library(common STATIC ${SOURCES})
if (ANDROID)
target_link_libraries(common soxr::soxr)
if(ANDROID)
target_link_libraries(common soxr::soxr)
elseif(SOXR_FOUND)
target_link_libraries(common ${SOXR_LIBRARIES})
target_link_libraries(common ${SOXR_LIBRARIES})
endif()

View file

@ -31,92 +31,112 @@ set(SERVER_SOURCES
streamreader/metadata.cpp
streamreader/process_stream.cpp)
set(SERVER_LIBRARIES
${CMAKE_THREAD_LIBS_INIT}
${ATOMIC_LIBRARY}
common)
set(SERVER_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ${ATOMIC_LIBRARY} common)
set(SERVER_INCLUDE
${Boost_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/server
${CMAKE_SOURCE_DIR}/common)
set(SERVER_INCLUDE ${Boost_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/server
${CMAKE_SOURCE_DIR}/common)
if (ANDROID)
find_package(vorbis REQUIRED CONFIG)
list(APPEND SERVER_LIBRARIES boost::boost)
list(APPEND SERVER_LIBRARIES flac::flac)
list(APPEND SERVER_LIBRARIES opus::opus)
list(APPEND SERVER_LIBRARIES ogg::ogg)
list(APPEND SERVER_LIBRARIES vorbis::vorbis)
list(APPEND SERVER_SOURCES encoder/flac_encoder.cpp)
list(APPEND SERVER_SOURCES encoder/ogg_encoder.cpp)
list(APPEND SERVER_SOURCES encoder/opus_encoder.cpp)
if(ANDROID)
find_package(vorbis REQUIRED CONFIG)
list(APPEND SERVER_LIBRARIES boost::boost)
list(APPEND SERVER_LIBRARIES flac::flac)
list(APPEND SERVER_LIBRARIES opus::opus)
list(APPEND SERVER_LIBRARIES ogg::ogg)
list(APPEND SERVER_LIBRARIES vorbis::vorbis)
list(APPEND SERVER_SOURCES encoder/flac_encoder.cpp)
list(APPEND SERVER_SOURCES encoder/ogg_encoder.cpp)
list(APPEND SERVER_SOURCES encoder/opus_encoder.cpp)
else()
# Avahi
if (AVAHI_FOUND)
list(APPEND SERVER_SOURCES publishZeroConf/publish_avahi.cpp)
list(APPEND SERVER_LIBRARIES ${AVAHI_LIBRARIES})
list(APPEND SERVER_INCLUDE ${AVAHI_INCLUDE_DIRS})
endif (AVAHI_FOUND)
# Avahi
if(AVAHI_FOUND)
list(APPEND SERVER_SOURCES publishZeroConf/publish_avahi.cpp)
list(APPEND SERVER_LIBRARIES ${AVAHI_LIBRARIES})
list(APPEND SERVER_INCLUDE ${AVAHI_INCLUDE_DIRS})
endif(AVAHI_FOUND)
if (BONJOUR_FOUND)
list(APPEND SERVER_SOURCES publishZeroConf/publish_bonjour.cpp)
# list(APPEND SERVER_LIBRARIES ${BONJOUR_LIBRARIES})
# list(APPEND SERVER_INCLUDE ${BONJOUR_INCLUDE_DIRS})
endif (BONJOUR_FOUND)
if(BONJOUR_FOUND)
list(APPEND SERVER_SOURCES publishZeroConf/publish_bonjour.cpp)
# list(APPEND SERVER_LIBRARIES ${BONJOUR_LIBRARIES}) list(APPEND
# SERVER_INCLUDE ${BONJOUR_INCLUDE_DIRS})
endif(BONJOUR_FOUND)
if (OGG_FOUND AND VORBIS_FOUND AND VORBISENC_FOUND)
list(APPEND SERVER_SOURCES encoder/ogg_encoder.cpp)
list(APPEND SERVER_LIBRARIES
${OGG_LIBRARIES}
${VORBIS_LIBRARIES}
${VORBISENC_LIBRARIES})
list(APPEND SERVER_INCLUDE
${OGG_INCLUDE_DIRS}
${VORBIS_INCLUDE_DIRS}
${VORBISENC_INCLUDE_DIRS})
endif (OGG_FOUND AND VORBIS_FOUND AND VORBISENC_FOUND)
if(OGG_FOUND
AND VORBIS_FOUND
AND VORBISENC_FOUND)
list(APPEND SERVER_SOURCES encoder/ogg_encoder.cpp)
list(APPEND SERVER_LIBRARIES ${OGG_LIBRARIES} ${VORBIS_LIBRARIES}
${VORBISENC_LIBRARIES})
list(APPEND SERVER_INCLUDE ${OGG_INCLUDE_DIRS} ${VORBIS_INCLUDE_DIRS}
${VORBISENC_INCLUDE_DIRS})
endif(
OGG_FOUND
AND VORBIS_FOUND
AND VORBISENC_FOUND)
if (FLAC_FOUND)
list(APPEND SERVER_SOURCES encoder/flac_encoder.cpp)
list(APPEND SERVER_LIBRARIES ${FLAC_LIBRARIES})
list(APPEND SERVER_INCLUDE ${FLAC_INCLUDE_DIRS})
endif (FLAC_FOUND)
if(FLAC_FOUND)
list(APPEND SERVER_SOURCES encoder/flac_encoder.cpp)
list(APPEND SERVER_LIBRARIES ${FLAC_LIBRARIES})
list(APPEND SERVER_INCLUDE ${FLAC_INCLUDE_DIRS})
endif(FLAC_FOUND)
if (OPUS_FOUND)
list(APPEND SERVER_SOURCES encoder/opus_encoder.cpp)
list(APPEND SERVER_LIBRARIES ${OPUS_LIBRARIES})
list(APPEND SERVER_INCLUDE ${OPUS_INCLUDE_DIRS})
endif (OPUS_FOUND)
if(OPUS_FOUND)
list(APPEND SERVER_SOURCES encoder/opus_encoder.cpp)
list(APPEND SERVER_LIBRARIES ${OPUS_LIBRARIES})
list(APPEND SERVER_INCLUDE ${OPUS_INCLUDE_DIRS})
endif(OPUS_FOUND)
if (ALSA_FOUND)
list(APPEND SERVER_SOURCES streamreader/alsa_stream.cpp)
list(APPEND SERVER_LIBRARIES ${ALSA_LIBRARIES})
list(APPEND SERVER_INCLUDE ${ALSA_INCLUDE_DIRS})
endif (ALSA_FOUND)
if(ALSA_FOUND)
list(APPEND SERVER_SOURCES streamreader/alsa_stream.cpp)
list(APPEND SERVER_LIBRARIES ${ALSA_LIBRARIES})
list(APPEND SERVER_INCLUDE ${ALSA_INCLUDE_DIRS})
endif(ALSA_FOUND)
if (EXPAT_FOUND)
list(APPEND SERVER_LIBRARIES ${EXPAT_LIBRARIES})
list(APPEND SERVER_INCLUDE ${EXPAT_INCLUDE_DIRS})
endif (EXPAT_FOUND)
if(EXPAT_FOUND)
list(APPEND SERVER_LIBRARIES ${EXPAT_LIBRARIES})
list(APPEND SERVER_INCLUDE ${EXPAT_INCLUDE_DIRS})
endif(EXPAT_FOUND)
endif()
#list(APPEND SERVER_LIBRARIES Boost::boost)
# list(APPEND SERVER_LIBRARIES Boost::boost)
include_directories(${SERVER_INCLUDE})
if (ANDROID)
add_executable(libsnapserver.so ${SERVER_SOURCES})
target_link_libraries(libsnapserver.so ${SERVER_LIBRARIES} log)
if(ANDROID)
add_executable(libsnapserver.so ${SERVER_SOURCES})
target_link_libraries(libsnapserver.so ${SERVER_LIBRARIES} log)
else()
add_executable(snapserver ${SERVER_SOURCES})
target_link_libraries(snapserver ${SERVER_LIBRARIES})
add_executable(snapserver ${SERVER_SOURCES})
target_link_libraries(snapserver ${SERVER_LIBRARIES})
install(TARGETS snapserver COMPONENT server DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES snapserver.1 COMPONENT server DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
install(FILES etc/snapserver.conf COMPONENT server DESTINATION ${CMAKE_INSTALL_SYSCONFDIR})
install(FILES etc/index.html COMPONENT server DESTINATION ${CMAKE_INSTALL_DATADIR}/snapserver)
install(DIRECTORY etc/snapweb/ DESTINATION ${CMAKE_INSTALL_DATADIR}/snapserver/snapweb)
install(FILES etc/plug-ins/meta_mpd.py PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE DESTINATION ${CMAKE_INSTALL_DATADIR}/snapserver/plug-ins/)
#install(FILES ../debian/snapserver.service DESTINATION ${SYSTEMD_SERVICES_INSTALL_DIR})
install(
TARGETS snapserver
COMPONENT server
DESTINATION ${CMAKE_INSTALL_BINDIR})
install(
FILES snapserver.1
COMPONENT server
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
install(
FILES etc/snapserver.conf
COMPONENT server
DESTINATION ${CMAKE_INSTALL_SYSCONFDIR})
install(
FILES etc/index.html
COMPONENT server
DESTINATION ${CMAKE_INSTALL_DATADIR}/snapserver)
install(DIRECTORY etc/snapweb/
DESTINATION ${CMAKE_INSTALL_DATADIR}/snapserver/snapweb)
install(
FILES etc/plug-ins/meta_mpd.py
PERMISSIONS
OWNER_READ
OWNER_WRITE
OWNER_EXECUTE
GROUP_READ
GROUP_EXECUTE
WORLD_READ
WORLD_EXECUTE
DESTINATION ${CMAKE_INSTALL_DATADIR}/snapserver/plug-ins/)
# install(FILES ../debian/snapserver.service DESTINATION
# ${SYSTEMD_SERVICES_INSTALL_DIR})
endif()

View file

@ -1,16 +1,17 @@
# Prepare "Catch" library for other executables
set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
add_library(Catch INTERFACE)
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR} ${CMAKE_SOURCE_DIR} ${Boost_INCLUDE_DIR})
target_include_directories(
Catch INTERFACE ${CATCH_INCLUDE_DIR} ${CMAKE_SOURCE_DIR} ${Boost_INCLUDE_DIR})
set(TEST_LIBRARIES Catch)
if (ANDROID)
list(APPEND TEST_LIBRARIES log)
endif (ANDROID)
if(ANDROID)
list(APPEND TEST_LIBRARIES log)
endif(ANDROID)
# Make test executable
set(TEST_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/test_main.cpp
set(TEST_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/test_main.cpp
${CMAKE_SOURCE_DIR}/server/streamreader/control_error.cpp
${CMAKE_SOURCE_DIR}/server/streamreader/properties.cpp
${CMAKE_SOURCE_DIR}/server/streamreader/metadata.cpp
@ -18,4 +19,3 @@ set(TEST_SOURCES
add_executable(snapcast_test ${TEST_SOURCES})
target_link_libraries(snapcast_test ${TEST_LIBRARIES})