Skip to content

Commit

Permalink
feat: add dynamic library build
Browse files Browse the repository at this point in the history
  • Loading branch information
taurusxin committed Mar 24, 2024
1 parent aa7ae61 commit d8a0944
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
37 changes: 30 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand Down
29 changes: 29 additions & 0 deletions src/lib/libncmdump.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit d8a0944

Please sign in to comment.