2021-10-30 04:25:12 +08:00
|
|
|
# This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
if(EXT_PLATFORM_STRING)
|
|
|
|
include(EXTLuau.cmake)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 3.0)
|
|
|
|
|
|
|
|
option(LUAU_BUILD_CLI "Build CLI" ON)
|
|
|
|
option(LUAU_BUILD_TESTS "Build tests" ON)
|
2021-11-23 01:59:15 +08:00
|
|
|
option(LUAU_BUILD_WEB "Build Web module" OFF)
|
2021-11-12 22:56:25 +08:00
|
|
|
option(LUAU_WERROR "Warnings as errors" OFF)
|
2022-02-08 05:51:57 +08:00
|
|
|
option(LUAU_STATIC_CRT "Link with the static CRT (/MT)" OFF)
|
|
|
|
|
|
|
|
if(LUAU_STATIC_CRT)
|
|
|
|
cmake_minimum_required(VERSION 3.15)
|
|
|
|
cmake_policy(SET CMP0091 NEW)
|
|
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
|
|
|
endif()
|
2021-10-30 04:25:12 +08:00
|
|
|
|
2022-02-08 05:51:57 +08:00
|
|
|
project(Luau LANGUAGES CXX C)
|
2021-10-30 04:25:12 +08:00
|
|
|
add_library(Luau.Ast STATIC)
|
|
|
|
add_library(Luau.Compiler STATIC)
|
|
|
|
add_library(Luau.Analysis STATIC)
|
|
|
|
add_library(Luau.VM STATIC)
|
2022-02-05 00:45:57 +08:00
|
|
|
add_library(isocline STATIC)
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
if(LUAU_BUILD_CLI)
|
|
|
|
add_executable(Luau.Repl.CLI)
|
2021-11-23 01:59:15 +08:00
|
|
|
add_executable(Luau.Analyze.CLI)
|
2022-02-08 04:08:43 +08:00
|
|
|
add_executable(Luau.Ast.CLI)
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
# This also adds target `name` on Linux/macOS and `name.exe` on Windows
|
|
|
|
set_target_properties(Luau.Repl.CLI PROPERTIES OUTPUT_NAME luau)
|
2021-11-23 01:59:15 +08:00
|
|
|
set_target_properties(Luau.Analyze.CLI PROPERTIES OUTPUT_NAME luau-analyze)
|
2022-02-08 04:08:43 +08:00
|
|
|
set_target_properties(Luau.Ast.CLI PROPERTIES OUTPUT_NAME luau-ast)
|
2021-10-30 04:25:12 +08:00
|
|
|
endif()
|
|
|
|
|
2021-11-23 01:59:15 +08:00
|
|
|
if(LUAU_BUILD_TESTS)
|
2021-10-30 04:25:12 +08:00
|
|
|
add_executable(Luau.UnitTest)
|
|
|
|
add_executable(Luau.Conformance)
|
2022-01-28 07:46:05 +08:00
|
|
|
add_executable(Luau.CLI.Test)
|
2021-10-30 04:25:12 +08:00
|
|
|
endif()
|
2021-11-11 00:40:46 +08:00
|
|
|
|
2021-11-23 01:59:15 +08:00
|
|
|
if(LUAU_BUILD_WEB)
|
|
|
|
add_executable(Luau.Web)
|
|
|
|
endif()
|
|
|
|
|
2021-10-30 04:25:12 +08:00
|
|
|
include(Sources.cmake)
|
|
|
|
|
|
|
|
target_compile_features(Luau.Ast PUBLIC cxx_std_17)
|
|
|
|
target_include_directories(Luau.Ast PUBLIC Ast/include)
|
|
|
|
|
|
|
|
target_compile_features(Luau.Compiler PUBLIC cxx_std_17)
|
|
|
|
target_include_directories(Luau.Compiler PUBLIC Compiler/include)
|
|
|
|
target_link_libraries(Luau.Compiler PUBLIC Luau.Ast)
|
|
|
|
|
|
|
|
target_compile_features(Luau.Analysis PUBLIC cxx_std_17)
|
|
|
|
target_include_directories(Luau.Analysis PUBLIC Analysis/include)
|
|
|
|
target_link_libraries(Luau.Analysis PUBLIC Luau.Ast)
|
|
|
|
|
|
|
|
target_compile_features(Luau.VM PRIVATE cxx_std_11)
|
|
|
|
target_include_directories(Luau.VM PUBLIC VM/include)
|
|
|
|
|
2022-02-05 00:45:57 +08:00
|
|
|
target_include_directories(isocline PUBLIC extern/isocline/include)
|
|
|
|
|
2021-10-30 04:25:12 +08:00
|
|
|
set(LUAU_OPTIONS)
|
|
|
|
|
|
|
|
if(MSVC)
|
|
|
|
list(APPEND LUAU_OPTIONS /D_CRT_SECURE_NO_WARNINGS) # We need to use the portable CRT functions.
|
|
|
|
list(APPEND LUAU_OPTIONS /MP) # Distribute single project compilation across multiple cores
|
|
|
|
else()
|
|
|
|
list(APPEND LUAU_OPTIONS -Wall) # All warnings
|
2021-11-12 22:56:25 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Enabled in CI; we should be warning free on our main compiler versions but don't guarantee being warning free everywhere
|
|
|
|
if(LUAU_WERROR)
|
|
|
|
if(MSVC)
|
|
|
|
list(APPEND LUAU_OPTIONS /WX) # Warnings are errors
|
|
|
|
else()
|
|
|
|
list(APPEND LUAU_OPTIONS -Werror) # Warnings are errors
|
|
|
|
endif()
|
2021-10-30 04:25:12 +08:00
|
|
|
endif()
|
|
|
|
|
2021-11-23 01:59:15 +08:00
|
|
|
if(LUAU_BUILD_WEB)
|
|
|
|
# add -fexceptions for emscripten to allow exceptions to be caught in C++
|
|
|
|
list(APPEND LUAU_OPTIONS -fexceptions)
|
|
|
|
endif()
|
|
|
|
|
2022-02-05 00:45:57 +08:00
|
|
|
set(ISOCLINE_OPTIONS)
|
|
|
|
|
|
|
|
if (NOT MSVC)
|
|
|
|
list(APPEND ISOCLINE_OPTIONS -Wno-unused-function)
|
|
|
|
endif()
|
|
|
|
|
2021-10-30 04:25:12 +08:00
|
|
|
target_compile_options(Luau.Ast PRIVATE ${LUAU_OPTIONS})
|
|
|
|
target_compile_options(Luau.Analysis PRIVATE ${LUAU_OPTIONS})
|
|
|
|
target_compile_options(Luau.VM PRIVATE ${LUAU_OPTIONS})
|
2022-02-05 00:45:57 +08:00
|
|
|
target_compile_options(isocline PRIVATE ${LUAU_OPTIONS} ${ISOCLINE_OPTIONS})
|
2021-10-30 04:25:12 +08:00
|
|
|
|
2022-01-22 01:00:19 +08:00
|
|
|
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1924)
|
|
|
|
# disable partial redundancy elimination which regresses interpreter codegen substantially in VS2022:
|
|
|
|
# https://developercommunity.visualstudio.com/t/performance-regression-on-a-complex-interpreter-lo/1631863
|
|
|
|
set_source_files_properties(VM/src/lvmexecute.cpp PROPERTIES COMPILE_FLAGS /d2ssa-pre-)
|
|
|
|
endif()
|
|
|
|
|
2021-10-30 04:25:12 +08:00
|
|
|
if(LUAU_BUILD_CLI)
|
|
|
|
target_compile_options(Luau.Repl.CLI PRIVATE ${LUAU_OPTIONS})
|
2021-11-23 01:59:15 +08:00
|
|
|
target_compile_options(Luau.Analyze.CLI PRIVATE ${LUAU_OPTIONS})
|
2022-02-08 04:08:43 +08:00
|
|
|
target_compile_options(Luau.Ast.CLI PRIVATE ${LUAU_OPTIONS})
|
2021-10-30 04:25:12 +08:00
|
|
|
|
2022-02-05 00:45:57 +08:00
|
|
|
target_include_directories(Luau.Repl.CLI PRIVATE extern extern/isocline/include)
|
|
|
|
|
|
|
|
target_link_libraries(Luau.Repl.CLI PRIVATE Luau.Compiler Luau.VM isocline)
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
if(UNIX)
|
2021-11-16 07:01:36 +08:00
|
|
|
find_library(LIBPTHREAD pthread)
|
|
|
|
if (LIBPTHREAD)
|
|
|
|
target_link_libraries(Luau.Repl.CLI PRIVATE pthread)
|
|
|
|
endif()
|
2021-10-30 04:25:12 +08:00
|
|
|
endif()
|
|
|
|
|
2021-11-23 01:59:15 +08:00
|
|
|
target_link_libraries(Luau.Analyze.CLI PRIVATE Luau.Analysis)
|
2022-02-08 04:08:43 +08:00
|
|
|
|
|
|
|
target_link_libraries(Luau.Ast.CLI PRIVATE Luau.Ast Luau.Analysis)
|
2021-10-30 04:25:12 +08:00
|
|
|
endif()
|
|
|
|
|
2021-11-23 01:59:15 +08:00
|
|
|
if(LUAU_BUILD_TESTS)
|
2021-10-30 04:25:12 +08:00
|
|
|
target_compile_options(Luau.UnitTest PRIVATE ${LUAU_OPTIONS})
|
|
|
|
target_include_directories(Luau.UnitTest PRIVATE extern)
|
|
|
|
target_link_libraries(Luau.UnitTest PRIVATE Luau.Analysis Luau.Compiler)
|
|
|
|
|
|
|
|
target_compile_options(Luau.Conformance PRIVATE ${LUAU_OPTIONS})
|
|
|
|
target_include_directories(Luau.Conformance PRIVATE extern)
|
|
|
|
target_link_libraries(Luau.Conformance PRIVATE Luau.Analysis Luau.Compiler Luau.VM)
|
2022-01-28 07:46:05 +08:00
|
|
|
|
|
|
|
target_compile_options(Luau.CLI.Test PRIVATE ${LUAU_OPTIONS})
|
|
|
|
target_include_directories(Luau.CLI.Test PRIVATE extern CLI)
|
2022-02-05 00:45:57 +08:00
|
|
|
target_link_libraries(Luau.CLI.Test PRIVATE Luau.Compiler Luau.VM isocline)
|
2022-01-28 07:46:05 +08:00
|
|
|
if(UNIX)
|
|
|
|
find_library(LIBPTHREAD pthread)
|
|
|
|
if (LIBPTHREAD)
|
|
|
|
target_link_libraries(Luau.CLI.Test PRIVATE pthread)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-10-30 04:25:12 +08:00
|
|
|
endif()
|
2021-11-23 01:59:15 +08:00
|
|
|
|
|
|
|
if(LUAU_BUILD_WEB)
|
|
|
|
target_compile_options(Luau.Web PRIVATE ${LUAU_OPTIONS})
|
|
|
|
target_link_libraries(Luau.Web PRIVATE Luau.Compiler Luau.VM)
|
|
|
|
|
|
|
|
# declare exported functions to emscripten
|
|
|
|
target_link_options(Luau.Web PRIVATE -sEXPORTED_FUNCTIONS=['_executeScript'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap'])
|
|
|
|
|
|
|
|
# add -fexceptions for emscripten to allow exceptions to be caught in C++
|
|
|
|
target_link_options(Luau.Web PRIVATE -fexceptions)
|
|
|
|
|
|
|
|
# the output is a single .js file with an embedded wasm blob
|
|
|
|
target_link_options(Luau.Web PRIVATE -sSINGLE_FILE=1)
|
|
|
|
endif()
|