mirror of
https://gitcode.com/JianFeeeee/LuaCangjia_api.git
synced 2026-09-19 16:42:48 +00:00
57 lines
1.3 KiB
CMake
57 lines
1.3 KiB
CMake
cmake_minimum_required(VERSION 3.12)
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
# 检测目标平台 - 通过编译器名称检测
|
|
set(TARGET_WINDOWS FALSE)
|
|
if(CMAKE_C_COMPILER MATCHES "mingw" OR CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
|
set(TARGET_WINDOWS TRUE)
|
|
endif()
|
|
|
|
project(LuaCJAPILib)
|
|
|
|
if(TARGET_WINDOWS)
|
|
# Windows 平台配置
|
|
list(APPEND EXTRA_LIBS "")
|
|
else()
|
|
# Linux/macOS 配置
|
|
list(APPEND EXTRA_LIBS dl)
|
|
endif()
|
|
|
|
set(ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
include_directories(${ROOT_PATH} ${ROOT_PATH}/lua)
|
|
add_subdirectory(lua)
|
|
|
|
# 方案:使用 OBJECT 库
|
|
add_library(luarunner OBJECT lua_runner.cpp)
|
|
target_include_directories(luarunner PRIVATE ${ROOT_PATH}/lua)
|
|
|
|
# Windows 特定编译定义
|
|
if(TARGET_WINDOWS)
|
|
target_compile_definitions(luarunner PRIVATE LUA_USE_WINDOWS)
|
|
endif()
|
|
|
|
add_library(luacjapi SHARED lua_cj_api.cpp)
|
|
|
|
# 链接阶段 - 根据平台选择不同的链接选项
|
|
if(TARGET_WINDOWS)
|
|
# Windows: 使用 Windows 兼容的链接选项
|
|
target_link_libraries(luacjapi PRIVATE
|
|
luarunner
|
|
"-Wl,--whole-archive"
|
|
lua
|
|
"-Wl,--no-whole-archive"
|
|
m
|
|
)
|
|
else()
|
|
# Linux/macOS: 使用 Unix 链接选项
|
|
target_link_libraries(luacjapi PRIVATE
|
|
luarunner
|
|
"-Wl,--whole-archive"
|
|
lua
|
|
"-Wl,--no-whole-archive"
|
|
m
|
|
${EXTRA_LIBS}
|
|
)
|
|
endif()
|