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

Allow passing CMAKE_MSVC_RUNTIME_LIBRARY #1960

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,25 @@ if(MSVC)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4267>)

# handle msvcrt setting being passed in CMAKE_C_FLAGS
if(DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
# do not support other methods of setting this (it would be more conformant, tho)
message(FATAL_ERROR "please set msvcrt via CMAKE_C_FLAGS")
endif()
if(CMAKE_C_FLAGS MATCHES "[/-]MTd")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebug")
elseif(CMAKE_C_FLAGS MATCHES "[/-]MDd")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebugDLL")
elseif(CMAKE_C_FLAGS MATCHES "[/-]MT")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
elseif(CMAKE_C_FLAGS MATCHES "[/-]MD")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
endif()
if(CMAKE_C_FLAGS MATCHES "[/-]M[TD]d?")
# ensure CMAKE_MSVC_RUNTIME_LIBRARY is not already defined
if(DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
message(FATAL_ERROR "please set the runtime library via either CMAKE_C_FLAGS or CMAKE_MSVC_RUNTIME_LIBRARY, not both")
endif()

# prevent the arg from occurring more than once (not a big deal, just to keep tidy)
string(REGEX REPLACE "[/-]M[TD]d?" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
if(CMAKE_C_FLAGS MATCHES "[/-]MTd")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebug")
elseif(CMAKE_C_FLAGS MATCHES "[/-]MDd")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebugDLL")
elseif(CMAKE_C_FLAGS MATCHES "[/-]MT")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
elseif(CMAKE_C_FLAGS MATCHES "[/-]MD")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
endif()

# prevent the arg from occurring more than once (not a big deal, just to keep tidy)
string(REGEX REPLACE "[/-]M[TD]d?" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
endif()
else()
if(MINGW)
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpmachine
Expand Down
Loading