Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a build option to link with the static CRT #343

Merged
merged 2 commits into from
Feb 7, 2022

Conversation

mikejsavage
Copy link
Contributor

I'm not 100% sure if this is the right approach but atm you can't link Luau into an app that uses /MT(d)

@zeux
Copy link
Collaborator

zeux commented Feb 7, 2022

Do you need this for CMake versions older than 3.15? The handling of this in earlier versions seems a little messy. For 3.15 to work I think you need to opt into CMP0091 like this:

if(POLICY CMP0091)
    cmake_policy(SET CMP0091 NEW) # Enables use of MSVC_RUNTIME_LIBRARY
endif()

CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
Copy link
Collaborator

@zeux zeux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks! I double checked locally and this appears to work well on Luau project at least.

@mikejsavage
Copy link
Contributor Author

mikejsavage commented Feb 7, 2022

Thanks for the quick reviews, to be honest I don't really know cmake so my first commit was copy pasted from curl

I've changed it to just use CMAKE_MSVC_RUNTIME_LIBRARY. It's a little awkward because you have to set the policy before you call project, and MSVC doesn't get set until you call project, so now it's a valid option for all platforms.

If that's not ok then another approach would be to use if(POLICY) to unconditionally set the policy, something like

if(POLICY CMP0091)
    cmake_policy(SET CMP0091 NEW)
endif()
...
project(Luau ...)
...
if(MSVC)
    option(LUAU_STATIC_CRT "Link with the static CRT (/MT)" OFF)
    if(LUAU_STATIC_CRT)
        set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
    endif()
endif()

Btw if this is too much back and forth for a ~5 line change then feel free to just close this/resolve it without me

@zeux
Copy link
Collaborator

zeux commented Feb 7, 2022

I think it's fine to set up the project after options, if we need to move it back we can do this separately

@zeux zeux merged commit 324bc4b into luau-lang:master Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants