feat: add dynamic library build

This commit is contained in:
TaurusXin 2024-03-24 17:27:41 +08:00
parent aa7ae6128d
commit d8a0944810
Signed by: taurusxin
GPG Key ID: C334DCA04AC2D2CC
2 changed files with 59 additions and 7 deletions

View File

@ -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})
else()
set(SOURCES ${COMMON_SOURCES})
endif()
add_executable(ncmdump
add_executable(ncmdump
${HEADERS}
${SOURCES}
${COMMON_SOURCES}
${EXECUTABLE_SOURCES}
${WIN_EXEC_SOURCES}
)
else()
add_executable(ncmdump
${HEADERS}
${COMMON_SOURCES}
${EXECUTABLE_SOURCES}
)
endif()
add_library(libncmdump SHARED
${HEADERS}
${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()

29
src/lib/libncmdump.cpp Normal file
View File

@ -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;
}
}