-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
65 lines (52 loc) · 2.14 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
cmake_minimum_required(VERSION 3.13)
project(LAppModelWrapper)
# set(CMAKE_BUILD_TYPE "Release")
message("${CMAKE_BUILD_TYPE}")
set(LIB_NAME LAppModelWrapper)
set(PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
set(RES_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Resources)
# prevent python root dir being shadowed by registry
set(Python3_FIND_REGISTRY "NEVER")
if(DEFINED PYTHON_INSTALLATION_PATH)
message("Found PYTHON_INSTALLATION_PATH in environment variables")
set(CMAKE_PREFIX_PATH ${PYTHON_INSTALLATION_PATH})
else()
# 寻找Python
message("Not found PYTHON_INSTALLATION_PATH in environment variables. \nUse default path.")
set(CMAKE_PREFIX_PATH D:/Python/x64/3.12)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/static)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi")
add_compile_options("/utf-8" "/wd4018" "/wd4244" "/wd4996")
add_link_options("/NODEFAULTLIB:LIBCMT" "/DEBUG")
else()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/static/${CMAKE_BUILD_TYPE})
endif()
find_package(Python3 REQUIRED Development)
message("Python_LIBRARIES " ${Python_LIBRARIES})
add_subdirectory(Main)
# 创建Python扩展模块
add_library(LAppModelWrapper SHARED LAppModelWrapper.cpp)
target_link_libraries(LAppModelWrapper PRIVATE Python3::Python live2d)
# Configure for Linux / Windows
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(MODULE_NAME lib${LIB_NAME}.so)
set(OUTPUT_NAME live2d.so)
else(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(MODULE_NAME ${LIB_NAME}.dll)
set(OUTPUT_NAME live2d.pyd)
endif()
# Post build commands
add_custom_command(
TARGET ${LIB_NAME}
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E
copy $<TARGET_FILE_DIR:${LIB_NAME}>/${MODULE_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/package/live2d/v3/${OUTPUT_NAME}
)