From a49bfe7f0a87b773fdd69be44650729f6e4dcd57 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 11 Oct 2024 15:05:18 -0300 Subject: [PATCH] Lua was still being compiled as C (instead of C++) when generating Visual Studio solutions We're compiling Lua as C++, but it seems that target_compile_options() doesn't work for Visual Studio solutions (only for Ninja/makefiles). The proper cmake solution to this issue is using set_source_files_properties() to specify C++ as the language to use to compile all Lua C files. This generates a valid Visual Studio solution. --- third_party/CMakeLists.txt | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 5db887125..d80040fb1 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -204,17 +204,10 @@ if(ENABLE_SCRIPTING) target_compile_definitions(lua PUBLIC LUA_USE_LINUX=1) endif() - # Compile Lua as C++ to control errors with exceptions and have - # stack unwinding (i.e. calling destructors correctly). - if(MSVC) - target_compile_options(lua PRIVATE -TP) - target_compile_options(lualib PRIVATE -TP) - target_compile_options(lauxlib PRIVATE -TP) - else() - target_compile_options(lua PRIVATE -xc++) - target_compile_options(lualib PRIVATE -xc++) - target_compile_options(lauxlib PRIVATE -xc++) - endif() + # Compile Lua C files as C++ to control errors with exceptions and + # have stack unwinding (i.e. calling destructors correctly). + file(GLOB all_lua_source_files lua/*.c) + set_source_files_properties(${all_lua_source_files} PROPERTIES LANGUAGE CXX) target_compile_definitions(lua PUBLIC LUA_FLOORN2I=F2Ifloor) target_compile_definitions(lualib PRIVATE HAVE_SYSTEM)