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.
This commit is contained in:
David Capello 2024-10-11 15:05:18 -03:00
parent 11883a51ff
commit a49bfe7f0a

View File

@ -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)