Skip to content

Commit 811888f

Browse files
authored
CXX-2977 Support generator expressions in MSVC_RUNTIME_LIBRARY (#1106)
1 parent 360767b commit 811888f

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

cmake/BsoncxxUtil.cmake

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,15 @@ function(bsoncxx_add_library TARGET OUTPUT_NAME LINK_TYPE)
9393
if(1)
9494
get_target_property(runtime ${TARGET} MSVC_RUNTIME_LIBRARY)
9595

96+
set(runtime_str "")
97+
9698
if(runtime)
97-
if(runtime STREQUAL "MultiThreaded")
98-
set(runtime_str "mt")
99-
elseif(runtime STREQUAL "MultiThreadedDebug")
100-
set(runtime_str "mtd")
101-
elseif(runtime STREQUAL "MultiThreadedDLL")
102-
set(runtime_str "md")
103-
elseif(runtime STREQUAL "MultiThreadedDebugDLL")
104-
set(runtime_str "mdd")
105-
endif()
99+
# MSVC_RUNTIME_LIBRARY may contain generator expressions.
100+
# Therefore the comparison must be evaluated during the build generation step.
101+
string(APPEND runtime_str "$<$<STREQUAL:${runtime},MultiThreaded>:mt>")
102+
string(APPEND runtime_str "$<$<STREQUAL:${runtime},MultiThreadedDebug>:mtd>")
103+
string(APPEND runtime_str "$<$<STREQUAL:${runtime},MultiThreadedDLL>:md>")
104+
string(APPEND runtime_str "$<$<STREQUAL:${runtime},MultiThreadedDebugDLL>:mdd>")
106105
else()
107106
# Per CMake documentation: if MSVC_RUNTIME_LIBRARY is not set, then
108107
# CMake uses the default value MultiThreaded$<$<CONFIG:Debug>:Debug>DLL

0 commit comments

Comments
 (0)