Skip to content

Commit 8c0f5e3

Browse files
committed
Set API definition if compile language is C++
`extern "C"` is only valid in C++, other languages may incorrectly interpret it or outright fail compilation.
1 parent 0084576 commit 8c0f5e3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ if(LUAU_EXTERN_C)
172172
# enable extern "C" for VM (lua.h, lualib.h) and Compiler (luacode.h) to make Luau friendlier to use from non-C++ languages
173173
# note that we enable LUA_USE_LONGJMP=1 as well; otherwise functions like luaL_error will throw C++ exceptions, which can't be done from extern "C" functions
174174
target_compile_definitions(Luau.VM PUBLIC LUA_USE_LONGJMP=1)
175-
target_compile_definitions(Luau.VM PUBLIC LUA_API=extern\"C\")
176-
target_compile_definitions(Luau.Compiler PUBLIC LUACODE_API=extern\"C\")
177-
target_compile_definitions(Luau.CodeGen PUBLIC LUACODEGEN_API=extern\"C\")
175+
target_compile_definitions(Luau.VM PUBLIC $<$<COMPILE_LANGUAGE:CXX>:LUA_API=extern\"C\">)
176+
target_compile_definitions(Luau.Compiler PUBLIC $<$<COMPILE_LANGUAGE:CXX>:LUACODE_API=extern\"C\">)
177+
target_compile_definitions(Luau.CodeGen PUBLIC $<$<COMPILE_LANGUAGE:CXX>:LUACODEGEN_API=extern\"C\">)
178178
endif()
179179

180180
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER_EQUAL 1924)

0 commit comments

Comments
 (0)