Skip to content

Commit dfa4dd8

Browse files
authored
Update usage of SQLITECPP_USE_STATIC_RUNTIME (#438)
- Replace the set() of "/MT" to REPLACE "/MD" "/MT" inspired from Zlib licensed glfw https://github.com/glfw/glfw/blob/master/CMakeLists.txt - Don't set SQLITECPP_USE_STATIC_RUNTIME by default when building with unit tests. Use gtest_force_shared_crt to force googletest to link against the default dynamic C++ runtime Relates to #417
2 parents 7a1649c + 2a43ce0 commit dfa4dd8

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

CMakeLists.txt

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,30 @@ if (MSVC)
3636
# disable Visual Studio warnings for fopen() used in the example
3737
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
3838
# Flags for linking with multithread static C++ runtime, required by internal googletest
39-
option(SQLITECPP_USE_STATIC_RUNTIME "Use MSVC static runtime (default for internal googletest)." ${SQLITECPP_BUILD_TESTS})
39+
option(SQLITECPP_USE_STATIC_RUNTIME "Use MSVC static runtime (default for internal googletest)." FALSE)
4040
if (SQLITECPP_USE_STATIC_RUNTIME)
4141
message(STATUS "Linking against multithread static C++ runtime")
42-
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
43-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
44-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
45-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
42+
# inspired from Zlib licensed glfw https://github.com/glfw/glfw/blob/master/CMakeLists.txt
43+
foreach (flag CMAKE_C_FLAGS
44+
CMAKE_C_FLAGS_DEBUG
45+
CMAKE_C_FLAGS_RELEASE
46+
CMAKE_C_FLAGS_MINSIZEREL
47+
CMAKE_C_FLAGS_RELWITHDEBINFO
48+
CMAKE_CXX_FLAGS
49+
CMAKE_CXX_FLAGS_DEBUG
50+
CMAKE_CXX_FLAGS_RELEASE
51+
CMAKE_CXX_FLAGS_MINSIZEREL
52+
CMAKE_CXX_FLAGS_RELWITHDEBINFO)
53+
54+
string(REGEX REPLACE "/MDd" "/MTd" ${flag} "${${flag}}")
55+
string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
56+
57+
endforeach()
58+
else (SQLITECPP_USE_STATIC_RUNTIME)
59+
if (SQLITECPP_BUILD_TESTS)
60+
message(STATUS "Force googletest to link against dynamic C++ runtime")
61+
set(gtest_force_shared_crt ON CACHE BOOL "Use shared (DLL) run-time lib even when Google Test is built as static lib.")
62+
endif (SQLITECPP_BUILD_TESTS)
4663
endif (SQLITECPP_USE_STATIC_RUNTIME)
4764
# MSVC versions prior to 2015 are not supported anymore by SQLiteC++ 3.x
4865
if (MSVC_VERSION LESS 1900) # OR MSVC_TOOLSET_VERSION LESS 140)

0 commit comments

Comments
 (0)