Skip to content

Commit 28b7fd3

Browse files
authored
Merge pull request #89 from semanux/choice-between-mt-and-md
Choice between `\MT` and `\MD` on Windows
2 parents b627c27 + 7c47ad3 commit 28b7fd3

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set(OPENPNP_CAPTURE_LIB_SOVERSION "0" CACHE STRING "openpnp-capture library sove
1818
# Library type options
1919
option(BUILD_SHARED_LIBS "Build shared library" ON)
2020
option(BUILD_STATIC_LIBS "Build static library" OFF)
21+
option(LINK_DYNAMIC_MSVC_RUNTIME "Link MSVC runtime statically" OFF)
2122

2223
# Validate library type options
2324
if(BUILD_STATIC_LIBS AND BUILD_SHARED_LIBS)
@@ -93,10 +94,13 @@ set_target_properties(openpnp-capture PROPERTIES
9394

9495
IF (WIN32)
9596
if(MSVC)
96-
# build with static runtime rather than DLL based so that we
97-
# don't have to distribute it
98-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
99-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
97+
if(LINK_DYNAMIC_MSVC_RUNTIME)
98+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
99+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
100+
else()
101+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
102+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
103+
endif()
100104
endif()
101105

102106
# set the platform identification string

README_BUILD.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -G
4545

4646
- `BUILD_SHARED_LIBS`: Build shared library (default: ON)
4747
- `BUILD_STATIC_LIBS`: Build static library (default: OFF)
48+
- `LINK_DYNAMIC_MSVC_RUNTIME`: Link MSVC runtime statically, aka `\MD`. Otherwise `\MT`. (default: OFF)
4849

4950
**Note**: If both options are enabled, the build will default to static library with a warning.
5051

0 commit comments

Comments
 (0)