Check for libraries and fail fast if not found.

This commit is contained in:
casey langen 2021-04-10 20:59:05 -07:00
parent a28d14717d
commit 229b282aec
17 changed files with 85 additions and 36 deletions

View File

@ -0,0 +1,10 @@
function(ensure_library_exists libname)
unset(__TEMP_ENSURE_LIBRARY CACHE)
find_library(__TEMP_ENSURE_LIBRARY ${libname})
if(NOT __TEMP_ENSURE_LIBRARY)
message(FATAL_ERROR "\n\n[check-dependencies] ${libname} not found\n\n")
else()
message(STATUS "[check-dependencies] ${libname} found at ${__TEMP_ENSURE_LIBRARY}")
endif()
unset(__TEMP_ENSURE_LIBRARY CACHE)
endfunction(ensure_library_exists)

View File

@ -13,10 +13,10 @@ set (musikcube_VERSION "${musikcube_VERSION_MAJOR}.${musikcube_VERSION_MINOR}.${
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/.cmake)
include(CMakeToolsHelpers OPTIONAL)
include(CheckDependencies)
include(CheckAtomic)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wno-unused-result -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -g -frtti -fexceptions")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
@ -25,6 +25,27 @@ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -frtti -fexceptions")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
# our include directories
include_directories (
"${musikcube_SOURCE_DIR}/src"
"${musikcube_SOURCE_DIR}/src/musikcore"
"${musikcube_SOURCE_DIR}/src/musikcube"
"${musikcube_SOURCE_DIR}/src/musikcube/cursespp"
"${musikcube_SOURCE_DIR}/src/3rdparty/include")
# our library directories
link_directories ("${musikcube_SOURCE_DIR}/bin/plugins")
# custom include/library directories for BSDs
if (CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
link_directories ("/usr/local/lib")
link_directories ("/usr/local/opt/openssl/lib")
link_directories ("/usr/local/opt/ncurses/lib")
include_directories("/usr/local/include")
include_directories("/usr/local/opt/openssl/include")
include_directories("/usr/local/opt/ncurses/include")
endif ()
if (${LINK_STATICALLY} MATCHES "true")
set(Boost_USE_STATIC_LIBS ON)
endif()
@ -45,8 +66,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/Mo
set (LIBRARY_OUTPUT_PATH ${musikcube_SOURCE_DIR}/bin/plugins)
set (EXECUTABLE_OUTPUT_PATH ${musikcube_SOURCE_DIR}/bin)
link_directories ("${musikcube_SOURCE_DIR}/bin/plugins")
ensure_library_exists(curl)
ensure_library_exists(pthread)
ensure_library_exists(ssl)
ensure_library_exists(crypto)
ensure_library_exists(z)
set(COMMON_LINK_LIBS ${BOOST_LINK_LIBS} curl pthread ssl crypto)
if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
@ -72,16 +96,8 @@ else()
message(STATUS "[build] ENABLE_BUNDLED_TAGLIB specified as '${ENABLE_BUNDLED_TAGLIB}'")
endif()
message(STATUS "[build] link libraries are: ${musikcube_LINK_LIBS}")
include_directories (
"${musikcube_SOURCE_DIR}/src"
"${musikcube_SOURCE_DIR}/src/musikcore"
"${musikcube_SOURCE_DIR}/src/musikcube"
"${musikcube_SOURCE_DIR}/src/musikcube/cursespp"
"${musikcube_SOURCE_DIR}/src/3rdparty/include")
# ensure the binaries can find libmusikcore.so, which lives in the
# same directory.
if (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
@ -89,17 +105,6 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
endif()
# "/usr/local" doesn't seem to be included by default on macOS 10.12+
# "/opt/local" is the default installation location for MacPorts
if (CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
link_directories ("/usr/local/lib")
link_directories ("/usr/local/opt/openssl/lib")
link_directories ("/usr/local/opt/ncurses/lib")
include_directories("/usr/local/include")
include_directories("/usr/local/opt/openssl/include")
include_directories("/usr/local/opt/ncurses/include")
endif ()
if (EXISTS "/etc/arch-release" OR EXISTS "/etc/manjaro-release" OR NO_NCURSESW)
add_definitions (-DNO_NCURSESW)
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "OpenBSD" )

View File

@ -2,6 +2,9 @@ set (DAEMON_SRCS
./main.cpp
)
ensure_library_exists(ev)
ensure_library_exists(libev.a)
set(musikcube_INSTALL_DIR ${HOMEBREW_PREFIX})
if (NOT DEFINED musikcube_INSTALL_DIR)
set(musikcube_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})

View File

@ -3,10 +3,8 @@ set (alsaout_SOURCES
AlsaOut.cpp
)
add_definitions(
-D_DEBUG
)
ensure_library_exists(asound)
add_library( alsaout SHARED ${alsaout_SOURCES} )
target_link_libraries( alsaout ${musikcube_LINK_LIBS} asound)
add_library(alsaout SHARED ${alsaout_SOURCES} )
target_link_libraries(alsaout ${musikcube_LINK_LIBS} asound)

View File

@ -10,6 +10,11 @@ set (ffmpegdecoder_SOURCES
include_directories("/usr/include/ffmpeg")
include_directories("/usr/local/include/ffmpeg")
ensure_library_exists(avcodec)
ensure_library_exists(avutil)
ensure_library_exists(avformat)
ensure_library_exists(swresample)
# note: static linking is a no-go (too many dependencies). sorry macOS.
add_library(ffmpegdecoder SHARED ${ffmpegdecoder_SOURCES})
target_link_libraries(ffmpegdecoder ${musikcube_LINK_LIBS} avcodec avutil avformat swresample)

View File

@ -5,6 +5,9 @@ set (flacdecoder_SOURCES
FlacDecoder.cpp
)
ensure_library_exists(FLAC)
ensure_library_exists(libFLAC.a)
add_library(flacdecoder SHARED ${flacdecoder_SOURCES})
# prefer static libraries on mac to make redist easier

View File

@ -5,10 +5,6 @@ set (httpdatastream_SOURCES
LruDiskCache.cpp
)
# add_definitions(-DFPM_DEFAULT)
# add_definitions(-DASO_ZEROCHECK)
# add_definitions(-DHAVE_CONFIG_H)
add_library(httpdatastream SHARED ${httpdatastream_SOURCES})
target_link_libraries(httpdatastream ${musikcube_LINK_LIBS} -lcurl)

View File

@ -6,10 +6,13 @@ set (openmptdecoder_SOURCES
Utility.cpp
)
ensure_library_exists(openmpt)
add_library(openmptdecoder SHARED ${openmptdecoder_SOURCES})
# prefer static libraries on mac to make redist easier
if (${LINK_STATICALLY} MATCHES "true")
ensure_library_exists(mpg123)
find_library(OPENMPTLIB NAMES libopenmpt.a openmpt)
find_library(MPG123LIB NAMES libmpg123.a mpg123)
find_library(ZLIB NAMES libz.a z)

View File

@ -16,6 +16,9 @@ include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}/mp4ff"
)
ensure_library_exists(faad)
ensure_library_exists(libfaad.a)
add_library(m4adecoder SHARED ${m4adecoder_SOURCES})
# prefer static libraries on mac to make redist easier

View File

@ -5,5 +5,7 @@ set (mpg123decoder_SOURCES
Mpg123Decoder.cpp
)
ensure_library_exists(mpg123)
add_library(mpg123decoder SHARED ${mpg123decoder_SOURCES})
target_link_libraries(mpg123decoder ${musikcube_LINK_LIBS} mpg123)

View File

@ -5,6 +5,13 @@ set (oggdecoder_SOURCES
stdafx.cpp
)
ensure_library_exists(ogg)
ensure_library_exists(libogg.a)
ensure_library_exists(vorbis)
ensure_library_exists(libvorbis.a)
ensure_library_exists(vorbisfile)
ensure_library_exists(libvorbisfile.a)
add_library(oggdecoder SHARED ${oggdecoder_SOURCES})
# prefer static libraries on mac to make redist easier

View File

@ -3,6 +3,8 @@ set (pipewireout_SOURCES
PipeWireOut.cpp
)
ensure_library_exists(pipewire-0.3)
message(STATUS "[pipewireout] plugin enabled")
include_directories("/usr/include/spa-0.2")

View File

@ -4,9 +4,7 @@ set (pulseout_SOURCES
PulseOut.cpp
)
add_definitions(
-D_DEBUG
)
ensure_library_exists(pulse)
add_library( pulseout SHARED ${pulseout_SOURCES} )
target_link_libraries( pulseout ${musikcube_LINK_LIBS} pulse)
add_library(pulseout SHARED ${pulseout_SOURCES})
target_link_libraries(pulseout ${musikcube_LINK_LIBS} pulse)

View File

@ -23,6 +23,8 @@ set (server_LINK_LIBS ${BOOST_LINK_LIBS})
include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/include")
ensure_library_exists(microhttpd)
if (${LINK_STATICALLY} MATCHES "true")
# libmicrohttpd on macOS now depends on `gnutls`. when we build statically,
# we also need to build libmicrohttpd ourselves and disable TLS to avoid this

View File

@ -3,5 +3,7 @@ set (sndioout_SOURCES
SndioOut.cpp
)
ensure_library_exists(sndio)
add_library(sndioout SHARED ${sndioout_SOURCES})
target_link_libraries(sndioout ${musikcube_LINK_LIBS} sndio)

View File

@ -6,14 +6,23 @@ set (stockencoders_SOURCES
add_library(stockencoders SHARED ${stockencoders_SOURCES})
ensure_library_exists(mp3lame)
if (${ENABLE_FFMPEG} MATCHES "false")
message(STATUS "[stockencoders] *not* defining ENABLE_FFMPEG")
else()
message(STATUS "[stockencoders] defining ENABLE_FFMPEG")
add_definitions(-DENABLE_FFMPEG)
# fedora (and probably other RPM-based distros) put ffmpeg includes here...
include_directories("/usr/include/ffmpeg")
include_directories("/usr/local/include/ffmpeg")
ensure_library_exists(avcodec)
ensure_library_exists(avutil)
ensure_library_exists(avformat)
ensure_library_exists(swresample)
# note: static linking is a no-go (too many dependencies). sorry macOS.
target_link_libraries(stockencoders avcodec avutil avformat swresample)
endif()

View File

@ -31,5 +31,6 @@ if (NOT ${ENABLE_BUNDLED_TAGLIB} MATCHES "false")
message(STATUS "[taglibmetadatareader] using ${musikcube_SOURCE_DIR}/src/plugins/taglib_plugin/taglib-1.11/stage/lib/libtag.a")
else()
message(STATUS "[taglibmetadatareader] using bundled taglib = false")
ensure_library_exists(tag)
target_link_libraries(taglibreader ${BOOST_LINK_LIBS} tag z)
endif()