Skip to content

Commit 501556e

Browse files
committed
fix(windows/linux): fix dirent.h compat, add Windows/Linux CMake branches, correct Core lib paths
1 parent 21c4a31 commit 501556e

5 files changed

Lines changed: 118 additions & 0 deletions

File tree

.github/workflows/build_live2d.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ jobs:
6767
- name: Setup MSVC & CMake
6868
uses: ilammy/msvc-dev-cmd@v1
6969

70+
- name: Install GLEW
71+
run: choco install glew --yes
72+
7073
- name: Build Windows dll
7174
shell: bash
7275
run: ./shared/core-native/scripts/build_windows.sh

shared/core-native/scripts/build_linux.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ rm -rf "${BUILD_DIR}"
2727

2828
cmake -S "${SCRIPT_DIR}/src/cpp" -B "${BUILD_DIR}" \
2929
"${EXTRA_CMAKE_FLAGS[@]}" \
30+
-DLINUX_DESKTOP_BUILD=ON \
3031
-DCMAKE_BUILD_TYPE=Release
3132
cmake --build "${BUILD_DIR}" --config Release
3233

shared/core-native/scripts/build_windows.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ rm -rf "${BUILD_DIR}"
2727

2828
cmake -S "${SCRIPT_DIR}/src/cpp" -B "${BUILD_DIR}" \
2929
"${EXTRA_CMAKE_FLAGS[@]}" \
30+
-DWINDOWS_DESKTOP_BUILD=ON \
3031
-DCMAKE_BUILD_TYPE=Release
3132
cmake --build "${BUILD_DIR}" --config Release
3233

shared/core-native/src/cpp/CMakeLists.txt

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,94 @@ elseif(MACOS_DESKTOP_BUILD)
8282
Live2DCubismCore
8383
${OPENGL_LIBRARIES}
8484
)
85+
elseif(WINDOWS_DESKTOP_BUILD OR (WIN32 AND NOT ANDROID))
86+
add_compile_definitions(CSM_TARGET_WIN_GL WINDOWS_DESKTOP_BUILD)
87+
88+
find_package(OpenGL REQUIRED)
89+
include_directories(${OPENGL_INCLUDE_DIR})
90+
91+
if(DEFINED ENV{JAVA_HOME})
92+
include_directories(
93+
"$ENV{JAVA_HOME}/include"
94+
"$ENV{JAVA_HOME}/include/win32"
95+
)
96+
else()
97+
find_package(JNI QUIET)
98+
if(JNI_FOUND)
99+
include_directories(${JNI_INCLUDE_DIRS})
100+
endif()
101+
endif()
102+
103+
find_package(GLEW QUIET)
104+
105+
add_library(Live2DCubismCore STATIC IMPORTED)
106+
set_target_properties(Live2DCubismCore PROPERTIES IMPORTED_LOCATION
107+
"${SDK_ROOT}/Core/lib/windows/x86_64/143/Live2DCubismCore_MD.lib"
108+
)
109+
110+
add_library(live2d_native SHARED
111+
live2d_renderer.cpp
112+
live2d_jni.cpp
113+
miniz.c
114+
${FRAMEWORK_SOURCES}
115+
)
116+
117+
if(GLEW_FOUND)
118+
include_directories(${GLEW_INCLUDE_DIRS})
119+
target_link_libraries(live2d_native
120+
Live2DCubismCore
121+
${OPENGL_LIBRARIES}
122+
${GLEW_LIBRARIES}
123+
opengl32
124+
)
125+
else()
126+
target_link_libraries(live2d_native
127+
Live2DCubismCore
128+
${OPENGL_LIBRARIES}
129+
opengl32
130+
)
131+
endif()
132+
133+
elseif(LINUX_DESKTOP_BUILD OR (UNIX AND NOT APPLE AND NOT ANDROID))
134+
add_compile_definitions(CSM_TARGET_LINUX_GL LINUX_DESKTOP_BUILD)
135+
136+
find_package(OpenGL REQUIRED)
137+
find_package(X11 REQUIRED)
138+
include_directories(${OPENGL_INCLUDE_DIR} ${X11_INCLUDE_DIR})
139+
140+
if(DEFINED ENV{JAVA_HOME})
141+
include_directories(
142+
"$ENV{JAVA_HOME}/include"
143+
"$ENV{JAVA_HOME}/include/linux"
144+
)
145+
else()
146+
find_package(JNI QUIET)
147+
if(JNI_FOUND)
148+
include_directories(${JNI_INCLUDE_DIRS})
149+
endif()
150+
endif()
151+
152+
add_library(Live2DCubismCore STATIC IMPORTED)
153+
set_target_properties(Live2DCubismCore PROPERTIES IMPORTED_LOCATION
154+
"${SDK_ROOT}/Core/lib/linux/x86_64/libLive2DCubismCore.a"
155+
)
156+
157+
add_library(live2d_native SHARED
158+
live2d_renderer.cpp
159+
live2d_jni.cpp
160+
miniz.c
161+
${FRAMEWORK_SOURCES}
162+
)
163+
164+
target_link_libraries(live2d_native
165+
Live2DCubismCore
166+
${OPENGL_LIBRARIES}
167+
${X11_LIBRARIES}
168+
GL
169+
)
170+
85171
else()
172+
# Android
86173
add_compile_definitions(CSM_TARGET_ANDROID_ES2)
87174

88175
add_library(Live2DCubismCore STATIC IMPORTED)

shared/core-native/src/cpp/live2d_renderer.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
#include <cstdlib>
1111
#include <sys/stat.h>
1212
#include <sys/types.h>
13+
#if defined(_WIN32)
14+
#include <windows.h>
15+
#else
1316
#include <dirent.h>
17+
#endif
1418
#include "miniz.h"
1519

1620
#include <mutex>
@@ -33,6 +37,18 @@
3337
#include <cstdio>
3438
#define LOGI(...) do { printf("[Live2DNative] "); printf(__VA_ARGS__); printf("\n"); fflush(stdout); } while(0)
3539
#define LOGE(...) do { fprintf(stderr, "[Live2DNative] "); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); fflush(stderr); } while(0)
40+
#elif defined(WINDOWS_DESKTOP_BUILD) || defined(_WIN32)
41+
#include <GL/glew.h>
42+
#include <GL/gl.h>
43+
#include <cstdio>
44+
#define LOGI(...) do { printf("[Live2DNative] "); printf(__VA_ARGS__); printf("\n"); fflush(stdout); } while(0)
45+
#define LOGE(...) do { fprintf(stderr, "[Live2DNative] "); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); fflush(stderr); } while(0)
46+
#elif defined(LINUX_DESKTOP_BUILD) || defined(__linux__)
47+
#include <GL/glew.h>
48+
#include <GL/gl.h>
49+
#include <cstdio>
50+
#define LOGI(...) do { printf("[Live2DNative] "); printf(__VA_ARGS__); printf("\n"); fflush(stdout); } while(0)
51+
#define LOGE(...) do { fprintf(stderr, "[Live2DNative] "); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); fflush(stderr); } while(0)
3652
#else
3753
#include <OpenGLES/ES2/gl.h>
3854
#include <cstdio>
@@ -864,6 +880,15 @@ bool live2d_load_model_from_zip(Live2DHandle handle, const char* zip_file_path,
864880
if (stat(checkExpectedPath.c_str(), &st) == 0) {
865881
jsonFilename = expectedJson;
866882
} else {
883+
#if defined(_WIN32)
884+
std::string searchPath = targetDir + "\\*.model3.json";
885+
WIN32_FIND_DATAA findData;
886+
HANDLE hFind = FindFirstFileA(searchPath.c_str(), &findData);
887+
if (hFind != INVALID_HANDLE_VALUE) {
888+
jsonFilename = findData.cFileName;
889+
FindClose(hFind);
890+
}
891+
#else
867892
DIR* dir = opendir(targetDir.c_str());
868893
if (dir) {
869894
struct dirent* entry;
@@ -876,6 +901,7 @@ bool live2d_load_model_from_zip(Live2DHandle handle, const char* zip_file_path,
876901
}
877902
closedir(dir);
878903
}
904+
#endif
879905
}
880906

881907
if (jsonFilename.empty()) {

0 commit comments

Comments
 (0)