From 28c4088bdcc4e9802aa8b2f72c5fd54e1a1591d3 Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Wed, 27 Jan 2021 16:05:46 -0600 Subject: [PATCH] Allow non-lua builds --- CMakeLists.txt | 14 +++++++++++--- core/CMakeLists.txt | 6 +++++- core/Scripting/Lua.cpp | 9 +++++---- scripting/CMakeLists.txt | 25 +++++++++++++------------ 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b39097b..70a7750 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,14 +2,19 @@ cmake_minimum_required(VERSION 3.13) project(Couch) set(CMAKE_MODULE_PATH, ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR/cmake.}) -add_compile_definitions(LUA_SCRIPTING) +option(LUA_ENABLED "Lua scripting support" ON) +if (LUA_ENABLED) + add_compile_definitions(LUA_SCRIPTING) +endif () add_executable(couch core/couch.cpp) add_subdirectory(core) target_link_libraries(couch couchlib) add_subdirectory(scripting) -target_link_libraries(couch couchlua) +if (LUA_ENABLED) + target_link_libraries(couch couchlua) +endif() add_subdirectory(thirdparty) @@ -24,4 +29,7 @@ if(WIN32) set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") endif(WIN32) -install(TARGETS couch couchlib couchlua) +install(TARGETS couch couchlib) +if (LUA_ENABLED) + install(TARGETS couch couchlua) +endif () diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 019c0c1..7c92e62 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -8,8 +8,10 @@ find_package(glfw3 3.3 REQUIRED) ## Find Bullet find_package(Bullet REQUIRED) +if (LUA_ENABLED) ## Find Lua find_package(Lua REQUIRED) +endif () add_library(couchlib SHARED) target_sources(couchlib PUBLIC @@ -74,7 +76,9 @@ if(NOT WIN32) endif() target_link_libraries(couchlib OpenGL::GL) target_link_libraries(couchlib GLEW::GLEW) -target_link_libraries(couchlib ${LUA_LIBRARIES}) +if (LUA_ENABLED) + target_link_libraries(couchlib ${LUA_LIBRARIES}) +endif () target_link_libraries(couchlib ${BULLET_LIBRARIES}) ## Add documentation diff --git a/core/Scripting/Lua.cpp b/core/Scripting/Lua.cpp index da41237..d2b87ab 100644 --- a/core/Scripting/Lua.cpp +++ b/core/Scripting/Lua.cpp @@ -85,8 +85,9 @@ bool Lua::HasHook(const char *name) { return exists; } -void Lua::LuaKeyHandler(Window *window, int key, int code, int action, int mods) { #ifdef LUA_SCRIPTING + +void Lua::LuaKeyHandler(Window *window, int key, int code, int action, int mods) { // lua_State *L = (lua_State*) glfwGetWindowUserPointer(window); lua_getglobal(L, "onkey"); lua_pushinteger(L, key); @@ -97,11 +98,9 @@ void Lua::LuaKeyHandler(Window *window, int key, int code, int action, int mods) if (err != LUA_OK) { Error(); } -#endif // LUA_SCRIPTING } void Lua::LuaMousePositionHandler(Window *window, double xpos, double ypos, double relx, double rely) { -#ifdef LUA_SCRIPTING // lua_State *L = (lua_State*) glfwGetWindowUserPointer(window); lua_getglobal(L, "onmousemotion"); lua_pushnumber(L, xpos); @@ -112,5 +111,7 @@ void Lua::LuaMousePositionHandler(Window *window, double xpos, double ypos, doub if (err != LUA_OK) { Error(); } -#endif // LUA_SCRIPTING } + +#endif // LUA_SCRIPTING + diff --git a/scripting/CMakeLists.txt b/scripting/CMakeLists.txt index dd78bfd..65c5d43 100644 --- a/scripting/CMakeLists.txt +++ b/scripting/CMakeLists.txt @@ -2,21 +2,22 @@ include(UseSWIG) set_property(SOURCE couch.i PROPERTY CPLUSPLUS ON) set_property(SOURCE couch.i PROPERTY USE_TARGET_INCLUDE_DIRECTORIES ON) -if (NOT WIN32) -swig_add_library(couchlua - TYPE SHARED - LANGUAGE lua - SOURCES couch.i lua/helpers.i) -else() - swig_add_library(couchlua - TYPE STATIC - LANGUAGE lua - SOURCES couch.i lua/helpers.i) -endif() - +if (LUA_ENABLED) + if (NOT WIN32) + swig_add_library(couchlua + TYPE SHARED + LANGUAGE lua + SOURCES couch.i lua/helpers.i) + else() + swig_add_library(couchlua + TYPE STATIC + LANGUAGE lua + SOURCES couch.i lua/helpers.i) + endif() target_include_directories(couchlua PRIVATE "${PROJECT_SOURCE_DIR}/core") swig_link_libraries(couchlua PRIVATE couchlib ${LUA_LIBRARIES}) +endif ()