aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJude Melton-Houghton <jwmhjwmh@gmail.com>2022-04-07 10:54:17 -0400
committerGitHub <noreply@github.com>2022-04-07 15:54:17 +0100
commit21f17e871ea3de419f682a8088337ba6ae1d015e (patch)
treeae0ac3ca448dcbe1436f67124b4ff6c967e757c3 /lib
parent837cea6b4a2315966b9670ae50cff9d3679bcff4 (diff)
downloadhax-minetest-server-21f17e871ea3de419f682a8088337ba6ae1d015e.tar.gz
hax-minetest-server-21f17e871ea3de419f682a8088337ba6ae1d015e.zip
Compile Lua as C++ (#11683)
Co-authored-by: sfan5 <sfan5@live.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/lua/CMakeLists.txt25
-rw-r--r--lib/lua/src/CMakeLists.txt18
-rw-r--r--lib/lua/src/luaconf.h14
3 files changed, 23 insertions, 34 deletions
diff --git a/lib/lua/CMakeLists.txt b/lib/lua/CMakeLists.txt
index 5d0dc0f70..2de4840cb 100644
--- a/lib/lua/CMakeLists.txt
+++ b/lib/lua/CMakeLists.txt
@@ -1,12 +1,10 @@
-project(lua C)
+project(lua CXX)
set(LUA_VERSION_MAJOR 5)
set(LUA_VERSION_MINOR 1)
set(LUA_VERSION_PATCH 4)
set(LUA_VERSION "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}")
-set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
-
set(COMMON_CFLAGS)
set(COMMON_LDFLAGS)
set(LIBS)
@@ -50,19 +48,12 @@ if(LUA_ANSI)
set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_ANSI")
endif(LUA_ANSI)
-# COMMON_CFLAGS has no effect without this line
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_CFLAGS}")
-
-
-# Standard flags to use for each build type.
-if(CMAKE_COMPILER_IS_GNUCC)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -Wall -Wextra -Wshadow -W -pedantic -std=gnu99")
- set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
- set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g")
- set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE} -O1 -g")
- set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2 -g")
-endif(CMAKE_COMPILER_IS_GNUCC)
-
+# Standard flags to use
+if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|(Apple)?Clang")
+ set(COMMON_CFLAGS "${COMMON_CFLAGS} -pipe -Wall -Wextra -Wshadow -W -pedantic")
+endif()
-add_subdirectory(src build)
+# COMMON_CFLAGS has no effect without this line
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_CFLAGS}")
+add_subdirectory(src)
diff --git a/lib/lua/src/CMakeLists.txt b/lib/lua/src/CMakeLists.txt
index 8f6cc1213..2ca4f4168 100644
--- a/lib/lua/src/CMakeLists.txt
+++ b/lib/lua/src/CMakeLists.txt
@@ -31,24 +31,14 @@ set(LUA_CORE_SRC
lvm.c
lzio.c
)
-set(LUA_LIB_HEADERS
- lua.h
- lualib.h
- lauxlib.h
- luaconf.h
-)
-
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_BINARY_DIR})
-# Lua library.
+# Lua library
add_library(lua STATIC ${LUA_CORE_SRC})
target_link_libraries(lua ${LIBS})
-set(LUA_STATIC_LIB lua)
-set(LUA_LIBS lua)
-
-set_target_properties(${LUA_LIBS} PROPERTIES
+set_target_properties(lua PROPERTIES
VERSION ${LUA_VERSION}
CLEAN_DIRECT_OUTPUT 1
)
+# Compile code as C++
+set_source_files_properties(${LUA_CORE_SRC} PROPERTIES LANGUAGE CXX)
diff --git a/lib/lua/src/luaconf.h b/lib/lua/src/luaconf.h
index e2cb26163..1521f0cbc 100644
--- a/lib/lua/src/luaconf.h
+++ b/lib/lua/src/luaconf.h
@@ -143,6 +143,14 @@
#define LUA_INTEGER ptrdiff_t
+/* MINETEST-SPECIFIC CHANGE: make sure API functions conform to the C ABI. */
+#if defined(__cplusplus)
+#define LUAI_API_EXTERN extern "C"
+#else
+#define LUAI_API_EXTERN extern
+#endif
+
+
/*
@@ LUA_API is a mark for all core API functions.
@@ LUALIB_API is a mark for all standard library functions.
@@ -154,14 +162,14 @@
#if defined(LUA_BUILD_AS_DLL)
#if defined(LUA_CORE) || defined(LUA_LIB)
-#define LUA_API __declspec(dllexport)
+#define LUA_API LUAI_API_EXTERN __declspec(dllexport)
#else
-#define LUA_API __declspec(dllimport)
+#define LUA_API LUAI_API_EXTERN __declspec(dllimport)
#endif
#else
-#define LUA_API extern
+#define LUA_API LUAI_API_EXTERN
#endif