From f51232ed892f43eb8ce02f4c62d28172d181a109 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Wed, 27 May 2020 12:50:49 +0800 Subject: [PATCH] build: able to build it without TagLib --- CMakeLists.txt | 9 +++++++++ mainwindow.cpp | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ebc5cb1..782543b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt5 COMPONENTS Widgets Multimedia Network REQUIRED) find_package(PkgConfig) +if (PKG_CONFIG_FOUND) pkg_check_modules(TagLib REQUIRED taglib) +endif () set (EXE_NAME pmusic) @@ -38,6 +40,13 @@ add_executable(${EXE_NAME} 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_link_libraries(${EXE_NAME} PRIVATE Qt5::Widgets Qt5::Multimedia Qt5::Network ${TagLib_LINK_LIBRARIES}) diff --git a/mainwindow.cpp b/mainwindow.cpp index b96ac62..56804d9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -7,7 +7,9 @@ #include "FlacPic.h" // taglib +#ifndef NO_TAGLIB #include +#endif // NO_TAGLIB #include #include @@ -431,6 +433,7 @@ void MainWindow::initConnections() QString suffix(filePath.mid(filePath.lastIndexOf('.') + 1)); suffix = suffix.toUpper(); +#ifndef NO_TAGLIB TagLib::FileRef fileRef(filePath.toLocal8Bit().data()); if (!fileRef.isNull() && fileRef.audioProperties()) { @@ -444,6 +447,7 @@ void MainWindow::initConnections() QString::fromStdString(tag->artist().to8Bit(true)), QString::fromStdString(tag->album().to8Bit(true))); } +#endif // NO_TAGLIB using namespace spID3; using namespace spFLAC;