Skip to content

Commit d6d373b

Browse files
committed
Move the MSVC runtime policy above project
1 parent ddecaf7 commit d6d373b

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

CMakeLists.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git")
2525
endif()
2626
endif()
2727

28+
if(VCPKG_TARGET_TRIPLET)
29+
message(STATUS "Using ${VCPKG_TARGET_TRIPLET} triplet with vcpkg")
30+
if(MSVC)
31+
# Match the MSVC runtime if we're using VCPKG with static libraries.
32+
cmake_policy(SET CMP0091 NEW)
33+
if(VCPKG_TARGET_TRIPLET MATCHES [[^.+-static$]])
34+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
35+
else()
36+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
37+
endif()
38+
message(STATUS "Using ${CMAKE_MSVC_RUNTIME_LIBRARY} to match ${VCPKG_TARGET_TRIPLET}")
39+
endif()
40+
endif()
41+
2842
project(cppgraphqlgen VERSION ${LATEST_VERSION})
2943

3044
set(CMAKE_CXX_STANDARD 17)
@@ -36,11 +50,6 @@ set(GRAPHQL_INSTALL_CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES} CACHE STRING "Co
3650

3751
option(BUILD_SHARED_LIBS "Build shared libraries instead of static libs" OFF)
3852

39-
# Match the MSVC runtime if we're using VCPKG with static libraries.
40-
if(MSVC AND VCPKG_TARGET_TRIPLET MATCHES ".*-static$")
41-
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
42-
endif()
43-
4453
function(add_bigobj_flag target)
4554
if(MSVC)
4655
# MSVC requires the /bigobj flag if the number of sections gets too big.

0 commit comments

Comments
 (0)