Skip to content

Commit e6941b8

Browse files
Merge pull request #133 from bernardladenthin/claude/static-linking-msvcp140-TCpZ1
Use static MSVC runtime (/MT) for Windows builds
2 parents a412480 + 9690385 commit e6941b8

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
cmake_minimum_required(VERSION 3.14)
1+
cmake_minimum_required(VERSION 3.15)
22

33
project(jllama CXX)
44

5+
# Use static MSVC runtime (/MT) instead of the default DLL runtime (/MD).
6+
# This embeds the C++ runtime into jllama.dll so msvcp140.dll / vcruntime140.dll
7+
# are not required on the end-user's machine.
8+
# Must be set before any FetchContent_MakeAvailable() so that llama.cpp and all
9+
# other subprojects inherit the same CRT choice (mixing /MT and /MD in a single
10+
# link is a linker error).
11+
if(MSVC)
12+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "" FORCE)
13+
endif()
14+
515
include(FetchContent)
616

717
set(BUILD_SHARED_LIBS ON)
@@ -273,8 +283,9 @@ if(BUILD_TESTING)
273283
GIT_REPOSITORY https://github.com/google/googletest.git
274284
GIT_TAG v1.15.2
275285
)
276-
# Prevent GTest from overriding our compiler/linker settings on Windows
277-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
286+
# Keep GTest on the same CRT as the rest of the project.
287+
# OFF means GTest respects CMAKE_MSVC_RUNTIME_LIBRARY (static /MT here).
288+
set(gtest_force_shared_crt OFF CACHE BOOL "" FORCE)
278289
FetchContent_MakeAvailable(googletest)
279290

280291
enable_testing()

0 commit comments

Comments
 (0)