From 229b282aecc3f6518a678a4ded0275d5094a497c Mon Sep 17 00:00:00 2001 From: casey langen Date: Sat, 10 Apr 2021 20:59:05 -0700 Subject: [PATCH] Check for libraries and fail fast if not found. --- .cmake/CheckDependencies.cmake | 10 ++++ CMakeLists.txt | 49 +++++++++++--------- src/musikcubed/CMakeLists.txt | 3 ++ src/plugins/alsaout/CMakeLists.txt | 8 ++-- src/plugins/ffmpegdecoder/CMakeLists.txt | 5 ++ src/plugins/flacdecoder/CMakeLists.txt | 3 ++ src/plugins/httpdatastream/CMakeLists.txt | 4 -- src/plugins/libopenmptdecoder/CMakeLists.txt | 3 ++ src/plugins/m4adecoder/CMakeLists.txt | 3 ++ src/plugins/mpg123decoder/CMakeLists.txt | 2 + src/plugins/oggdecoder/CMakeLists.txt | 7 +++ src/plugins/pipewireout/CMakeLists.txt | 2 + src/plugins/pulseout/CMakeLists.txt | 8 ++-- src/plugins/server/CMakeLists.txt | 2 + src/plugins/sndioout/CMakeLists.txt | 2 + src/plugins/stockencoders/CMakeLists.txt | 9 ++++ src/plugins/taglib_plugin/CMakeLists.txt | 1 + 17 files changed, 85 insertions(+), 36 deletions(-) create mode 100644 .cmake/CheckDependencies.cmake diff --git a/.cmake/CheckDependencies.cmake b/.cmake/CheckDependencies.cmake new file mode 100644 index 000000000..b8dc6a68d --- /dev/null +++ b/.cmake/CheckDependencies.cmake @@ -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) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dc4bf98c..620c5978c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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" ) diff --git a/src/musikcubed/CMakeLists.txt b/src/musikcubed/CMakeLists.txt index 364a917bb..3d65b8c65 100644 --- a/src/musikcubed/CMakeLists.txt +++ b/src/musikcubed/CMakeLists.txt @@ -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}) diff --git a/src/plugins/alsaout/CMakeLists.txt b/src/plugins/alsaout/CMakeLists.txt index 5074a5472..b67842f4f 100755 --- a/src/plugins/alsaout/CMakeLists.txt +++ b/src/plugins/alsaout/CMakeLists.txt @@ -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) diff --git a/src/plugins/ffmpegdecoder/CMakeLists.txt b/src/plugins/ffmpegdecoder/CMakeLists.txt index 803044bda..b33c8f065 100644 --- a/src/plugins/ffmpegdecoder/CMakeLists.txt +++ b/src/plugins/ffmpegdecoder/CMakeLists.txt @@ -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) diff --git a/src/plugins/flacdecoder/CMakeLists.txt b/src/plugins/flacdecoder/CMakeLists.txt index e990433c1..413e66cb6 100644 --- a/src/plugins/flacdecoder/CMakeLists.txt +++ b/src/plugins/flacdecoder/CMakeLists.txt @@ -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 diff --git a/src/plugins/httpdatastream/CMakeLists.txt b/src/plugins/httpdatastream/CMakeLists.txt index 80ad2ef0e..6c9094fc3 100644 --- a/src/plugins/httpdatastream/CMakeLists.txt +++ b/src/plugins/httpdatastream/CMakeLists.txt @@ -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) diff --git a/src/plugins/libopenmptdecoder/CMakeLists.txt b/src/plugins/libopenmptdecoder/CMakeLists.txt index 1d606fda0..f765e05c7 100644 --- a/src/plugins/libopenmptdecoder/CMakeLists.txt +++ b/src/plugins/libopenmptdecoder/CMakeLists.txt @@ -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) diff --git a/src/plugins/m4adecoder/CMakeLists.txt b/src/plugins/m4adecoder/CMakeLists.txt index d90049061..99aa80b87 100644 --- a/src/plugins/m4adecoder/CMakeLists.txt +++ b/src/plugins/m4adecoder/CMakeLists.txt @@ -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 diff --git a/src/plugins/mpg123decoder/CMakeLists.txt b/src/plugins/mpg123decoder/CMakeLists.txt index aaf6dd04d..449e41658 100644 --- a/src/plugins/mpg123decoder/CMakeLists.txt +++ b/src/plugins/mpg123decoder/CMakeLists.txt @@ -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) diff --git a/src/plugins/oggdecoder/CMakeLists.txt b/src/plugins/oggdecoder/CMakeLists.txt index bcd4f170f..999a5b4ff 100644 --- a/src/plugins/oggdecoder/CMakeLists.txt +++ b/src/plugins/oggdecoder/CMakeLists.txt @@ -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 diff --git a/src/plugins/pipewireout/CMakeLists.txt b/src/plugins/pipewireout/CMakeLists.txt index 5edf57fa8..7c24320d9 100644 --- a/src/plugins/pipewireout/CMakeLists.txt +++ b/src/plugins/pipewireout/CMakeLists.txt @@ -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") diff --git a/src/plugins/pulseout/CMakeLists.txt b/src/plugins/pulseout/CMakeLists.txt index f09dac3fa..026e64d43 100755 --- a/src/plugins/pulseout/CMakeLists.txt +++ b/src/plugins/pulseout/CMakeLists.txt @@ -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) diff --git a/src/plugins/server/CMakeLists.txt b/src/plugins/server/CMakeLists.txt index 7e0969d54..f8cf04a6a 100644 --- a/src/plugins/server/CMakeLists.txt +++ b/src/plugins/server/CMakeLists.txt @@ -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 diff --git a/src/plugins/sndioout/CMakeLists.txt b/src/plugins/sndioout/CMakeLists.txt index 5e5fb13dc..bfd3b3551 100644 --- a/src/plugins/sndioout/CMakeLists.txt +++ b/src/plugins/sndioout/CMakeLists.txt @@ -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) diff --git a/src/plugins/stockencoders/CMakeLists.txt b/src/plugins/stockencoders/CMakeLists.txt index 4ff9ec510..f1e41020b 100644 --- a/src/plugins/stockencoders/CMakeLists.txt +++ b/src/plugins/stockencoders/CMakeLists.txt @@ -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() diff --git a/src/plugins/taglib_plugin/CMakeLists.txt b/src/plugins/taglib_plugin/CMakeLists.txt index 389869d99..629c23808 100644 --- a/src/plugins/taglib_plugin/CMakeLists.txt +++ b/src/plugins/taglib_plugin/CMakeLists.txt @@ -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()