From d8a0944810d5ad51889e968889f8b7902574a8b1 Mon Sep 17 00:00:00 2001 From: TaurusXin Date: Sun, 24 Mar 2024 17:27:41 +0800 Subject: [PATCH] feat: add dynamic library build --- CMakeLists.txt | 37 ++++++++++++++++++++++++++++++------- src/lib/libncmdump.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 src/lib/libncmdump.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e7f652..e0038aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,20 +15,33 @@ if(MSVC) endif() FILE(GLOB HEADERS ./src/include/*.h) -FILE(GLOB COMMON_SOURCES ./src/*.cpp ./src/utils/*.cpp) -FILE(GLOB WIN_SOURCES ./src/platform/win32_init.cpp) - +FILE(GLOB COMMON_SOURCES ./src/ncmcrypt.cpp ./src/utils/*.cpp) +FILE(GLOB EXECUTABLE_SOURCES ./src/main.cpp) +FILE(GLOB LIBRARY_SOURCES ./src/lib/libncmdump.cpp) +FILE(GLOB WIN_EXEC_SOURCES ./src/platform/win32_init.cpp) if(WIN32) - set(SOURCES ${COMMON_SOURCES} ${WIN_SOURCES}) + add_executable(ncmdump + ${HEADERS} + ${COMMON_SOURCES} + ${EXECUTABLE_SOURCES} + ${WIN_EXEC_SOURCES} + ) else() - set(SOURCES ${COMMON_SOURCES}) + add_executable(ncmdump + ${HEADERS} + ${COMMON_SOURCES} + ${EXECUTABLE_SOURCES} + ) endif() -add_executable(ncmdump + +add_library(libncmdump SHARED ${HEADERS} - ${SOURCES} + ${COMMON_SOURCES} + ${LIBRARY_SOURCES} ) +# executable target target_include_directories(ncmdump PRIVATE src/include) target_link_libraries(ncmdump tag) @@ -37,9 +50,19 @@ target_include_directories(ncmdump PRIVATE taglib/taglib) target_include_directories(ncmdump PRIVATE taglib/taglib/toolkit) target_include_directories(ncmdump PRIVATE taglib/taglib/mpeg/id3v2) +# library target +target_include_directories(libncmdump PRIVATE src/include) + +target_link_libraries(libncmdump tag) +target_include_directories(libncmdump PRIVATE taglib) +target_include_directories(libncmdump PRIVATE taglib/taglib) +target_include_directories(libncmdump PRIVATE taglib/taglib/toolkit) +target_include_directories(libncmdump PRIVATE taglib/taglib/mpeg/id3v2) + if(WIN32) if(CMAKE_COMPILER_IS_GNUCXX) target_link_options(ncmdump PRIVATE -static) + target_link_options(libncmdump PRIVATE -static) endif() endif() diff --git a/src/lib/libncmdump.cpp b/src/lib/libncmdump.cpp new file mode 100644 index 0000000..496cb8f --- /dev/null +++ b/src/lib/libncmdump.cpp @@ -0,0 +1,29 @@ +#include "ncmcrypt.h" + +#define API __declspec(dllexport) + +extern "C" { + API NeteaseCrypt* CreateNeteaseCrypt(const char* path) { + return new NeteaseCrypt(std::string(path)); + } + + API int Dump(NeteaseCrypt* neteaseCrypt) { + try + { + neteaseCrypt->Dump(); + } + catch (const std::invalid_argument& e) + { + return 1; + } + return 0; + } + + API void FixMetadata(NeteaseCrypt* neteaseCrypt) { + neteaseCrypt->FixMetadata(); + } + + API void DestroyNeteaseCrypt(NeteaseCrypt* neteaseCrypt) { + delete neteaseCrypt; + } +} \ No newline at end of file