build: able to build it without TagLib

This commit is contained in:
Gary Wang 2020-05-27 12:50:49 +08:00
parent 16744a9a3a
commit f51232ed89
2 changed files with 13 additions and 0 deletions

View File

@ -16,7 +16,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Widgets Multimedia Network REQUIRED) find_package(Qt5 COMPONENTS Widgets Multimedia Network REQUIRED)
find_package(PkgConfig) find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(TagLib REQUIRED taglib) pkg_check_modules(TagLib REQUIRED taglib)
endif ()
set (EXE_NAME pmusic) set (EXE_NAME pmusic)
@ -38,6 +40,13 @@ add_executable(${EXE_NAME}
ID3v2Pic.h ID3v2Pic.h
) )
if (NOT TagLib_FOUND)
message (WARNING "TagLib not found!")
target_compile_definitions(${EXE_NAME} PRIVATE
NO_TAGLIB=1
)
endif ()
target_include_directories(${EXE_NAME} PRIVATE ${TagLib_INCLUDE_DIRS}) target_include_directories(${EXE_NAME} PRIVATE ${TagLib_INCLUDE_DIRS})
target_link_libraries(${EXE_NAME} PRIVATE Qt5::Widgets Qt5::Multimedia Qt5::Network ${TagLib_LINK_LIBRARIES}) target_link_libraries(${EXE_NAME} PRIVATE Qt5::Widgets Qt5::Multimedia Qt5::Network ${TagLib_LINK_LIBRARIES})

View File

@ -7,7 +7,9 @@
#include "FlacPic.h" #include "FlacPic.h"
// taglib // taglib
#ifndef NO_TAGLIB
#include <fileref.h> #include <fileref.h>
#endif // NO_TAGLIB
#include <QPainter> #include <QPainter>
#include <QMediaPlayer> #include <QMediaPlayer>
@ -431,6 +433,7 @@ void MainWindow::initConnections()
QString suffix(filePath.mid(filePath.lastIndexOf('.') + 1)); QString suffix(filePath.mid(filePath.lastIndexOf('.') + 1));
suffix = suffix.toUpper(); suffix = suffix.toUpper();
#ifndef NO_TAGLIB
TagLib::FileRef fileRef(filePath.toLocal8Bit().data()); TagLib::FileRef fileRef(filePath.toLocal8Bit().data());
if (!fileRef.isNull() && fileRef.audioProperties()) { if (!fileRef.isNull() && fileRef.audioProperties()) {
@ -444,6 +447,7 @@ void MainWindow::initConnections()
QString::fromStdString(tag->artist().to8Bit(true)), QString::fromStdString(tag->artist().to8Bit(true)),
QString::fromStdString(tag->album().to8Bit(true))); QString::fromStdString(tag->album().to8Bit(true)));
} }
#endif // NO_TAGLIB
using namespace spID3; using namespace spID3;
using namespace spFLAC; using namespace spFLAC;