Add cmake setting to build as dll

This commit is contained in:
James 2025-03-18 18:22:19 +00:00
parent e0b55a9cb1
commit 9eb4ee69fe

View file

@ -12,6 +12,8 @@ option(LUAU_BUILD_WEB "Build Web module" OFF)
option(LUAU_WERROR "Warnings as errors" OFF)
option(LUAU_STATIC_CRT "Link with the static CRT (/MT)" OFF)
option(LUAU_EXTERN_C "Use extern C for all APIs" OFF)
option(LUAU_EXPORT_DLL "Exports to DLL" OFF)
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0091 NEW)
@ -25,13 +27,24 @@ project(Luau LANGUAGES CXX C)
add_library(Luau.Common INTERFACE)
add_library(Luau.CLI.lib STATIC)
add_library(Luau.Ast STATIC)
add_library(Luau.Compiler STATIC)
add_library(Luau.Config STATIC)
add_library(Luau.Analysis STATIC)
add_library(Luau.EqSat STATIC)
add_library(Luau.CodeGen STATIC)
add_library(Luau.VM STATIC)
add_library(isocline STATIC)
if(LUAU_EXPORT_DLL)
add_library(Luau.Compiler SHARED)
add_library(Luau.Config SHARED)
add_library(Luau.Analysis SHARED)
add_library(Luau.EqSat SHARED)
add_library(Luau.CodeGen SHARED)
add_library(Luau.VM SHARED)
add_library(isocline SHARED)
else()
add_library(Luau.Compiler STATIC)
add_library(Luau.Config STATIC)
add_library(Luau.Analysis STATIC)
add_library(Luau.EqSat STATIC)
add_library(Luau.CodeGen STATIC)
add_library(Luau.VM STATIC)
add_library(isocline STATIC)
endif()
if(LUAU_BUILD_CLI)
add_executable(Luau.Repl.CLI)
@ -161,9 +174,25 @@ if(LUAU_EXTERN_C)
# enable extern "C" for VM (lua.h, lualib.h) and Compiler (luacode.h) to make Luau friendlier to use from non-C++ languages
# 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
target_compile_definitions(Luau.VM PUBLIC LUA_USE_LONGJMP=1)
target_compile_definitions(Luau.VM PUBLIC LUA_API=extern\"C\")
target_compile_definitions(Luau.Compiler PUBLIC LUACODE_API=extern\"C\")
target_compile_definitions(Luau.CodeGen PUBLIC LUACODEGEN_API=extern\"C\")
if(LUAU_EXPORT_DLL)
if(MSVC)
target_compile_definitions(Luau.VM PUBLIC "LUA_API=extern \"C\" __declspec(dllexport)")
target_compile_definitions(Luau.Compiler PUBLIC "LUACODE_API=extern \"C\" __declspec(dllexport)")
target_compile_definitions(Luau.CodeGen PUBLIC "LUACODEGEN_API=extern \"C\" __declspec(dllexport)")
else()
# GCC/Clang
target_compile_definitions(Luau.VM PUBLIC "LUA_API=extern \"C\" __attribute__((visibility(\"default\")))")
target_compile_definitions(Luau.Compiler PUBLIC "LUACODE_API=extern \"C\" __attribute__((visibility(\"default\")))")
target_compile_definitions(Luau.CodeGen PUBLIC "LUACODEGEN_API=extern \"C\" __attribute__((visibility(\"default\")))")
endif()
else()
# For static builds (or if not exporting) just use extern "C"
target_compile_definitions(Luau.VM PUBLIC "LUA_API=extern \"C\"")
target_compile_definitions(Luau.Compiler PUBLIC "LUACODE_API=extern \"C\"")
target_compile_definitions(Luau.CodeGen PUBLIC "LUACODEGEN_API=extern \"C\"")
endif()
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER_EQUAL 1924)