diff --git a/.gitignore b/.gitignore index 567609b..a4fb4fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build/ +.cache/ diff --git a/.vscode/settings.json b/.vscode/settings.json index a34bb45..5466a6b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,12 +1,11 @@ -{ - "Lua.diagnostics.globals": [ - "_bllua_ts", - "_bllua_requiresecure", - "_bllua_on_unload" - ], - "Lua.runtime.version": "Lua 5.1", - "Lua.diagnostics.disable": [ - "lowercase-global", - "undefined-global" - ] -} \ No newline at end of file +{ + "Lua.diagnostics.globals": [ + "_bllua_ts", + "_bllua_requiresecure", + "_bllua_on_unload" + ], + "Lua.runtime.version": "Lua 5.1", + "Lua.diagnostics.disable": ["lowercase-global", "undefined-global"], + "C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json", + "C_Cpp.default.compilerPath": "C:/msys64/mingw32/bin/g++.exe" +} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5d38335 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,56 @@ +cmake_minimum_required(VERSION 3.10) + +project(BlockLua CXX) + +# Export compile_commands.json for VSCode IntelliSense +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# Output directories to mirror compile.bat's build folder +set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/build) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIR}) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIR}) + +# Global compile options to mirror compile.bat +add_compile_options( + -Wall + -Werror + -m32 + -static-libgcc + -static-libstdc++ +) + +# Include paths +include_directories( + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/inc/tsfuncs + ${CMAKE_SOURCE_DIR}/inc/lua +) + +# Link directories (for -L.) and libraries from compile.bat +link_directories( + ${CMAKE_SOURCE_DIR} +) + +# Safe DLL +add_library(BlockLua SHARED src/bllua4.cpp) +# Ensure output name matches compile.bat +set_target_properties(BlockLua PROPERTIES OUTPUT_NAME "BlockLua") +# Linker flags and libraries +if(MSVC) + # Not expected with mingw, but keep placeholder +else() + target_link_libraries(BlockLua PRIVATE psapi lua5.1) +endif() + +# Unsafe DLL (with BLLUA_UNSAFE definition) +add_library(BlockLuaUnsafe SHARED src/bllua4.cpp) +set_target_properties(BlockLuaUnsafe PROPERTIES OUTPUT_NAME "BlockLua-Unsafe") + +target_compile_definitions(BlockLuaUnsafe PRIVATE BLLUA_UNSAFE) + +if(MSVC) + # Not expected with mingw, but keep placeholder +else() + target_link_libraries(BlockLuaUnsafe PRIVATE psapi lua5.1) +endif() diff --git a/make.bat b/make.bat new file mode 100644 index 0000000..1884ee2 --- /dev/null +++ b/make.bat @@ -0,0 +1,27 @@ +@echo off +cd /d %~dp0 + +REM Ensure MinGW32 toolchain is first in PATH (matches compile.bat) +set "PATH=C:\msys64\mingw32\bin;%PATH%" + +REM Configure CMake (generate into build/) +cmake -S . -B build -G "MinGW Makefiles" +if errorlevel 1 goto :error + +REM Build (Release by default) +cmake --build build --config Release -j +if errorlevel 1 goto :error + +echo. +echo Build completed. +echo Outputs in .\build : +echo - BlockLua.dll + +echo - BlockLua-Unsafe.dll + +exit /b 0 + +:error +echo. +echo Build failed. See errors above. +exit /b 1