I am currently trying to compile some code with Visual Studio 2017 Version 15.7.0
and am having issues changing the run-time library. I know there are similar questions where you would normally right click on the project and then change it through the user interface that appears; however, since I am using CMake this does not work as that user interface does not appear.
The current default for Visual Studios is set to use /MD
run-time library and I want to use /MT
. I have tried setting this variable in the top level CMakeLists.txt
, but it appears to get overwritten. The only way I have found that I can build my project successfully is to change all instances of /MD
in the CMakeCache.txt
. While this is a temporary hack I was wondering what is the proper set this variable so that Visual Studio uses /MT
when compiling.
I have tried this previous answer link, but I am not getting it to work. Here is my current top level CMakeLists.txt
.
cmake_minimum_required (VERSION 3.11)
project ("WindowCMakeProject")
message(STATUS "Using CMake Version " ${CMAKE_VERSION})
#This project heavily uses C++ 17
set (CMAKE_CXX_STANDARD 17)
#Setup Boost
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
if ( WIN32 )
add_definitions( -DBOOST_ALL_NO_LIB )
set(Boost_USE_STATIC_RUNTIME ON)
#Solution from prior answer doesn't work
set(CMAKE_CXX_FLAGS_RELEASE "/MT")
set(CMAKE_CXX_FLAGS_DEBUG "/MTd")
endif()
find_package(Boost 1.66.0 REQUIRED COMPONENTS system)
#Setup OpenSSL
find_package(OpenSSL REQUIRED)
#Setup Google Protobuf
find_package(Protobuf REQUIRED)
if ( DEBUG_PRINT )
set(DEBUG_PRINT_MODE 1)
else()
set(DEBUG_PRINT_MODE 0)
endif()
#Add Util Headers
add_subdirectory(Utils)
set (UTILS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Utils/include)
#Setup Server Library
set (SERVER_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/ServerLibrary/include)
add_subdirectory (ServerLibrary)
include_directories(${SERVER_INCLUDE_DIRS})
#Setup Message Helper Library
set (MESSAGE_HELPER_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/MessageHelperLibrary/include)
add_subdirectory(MessageHelperLibrary)
include_directories(${MESSAGE_HELPER_INCLUDE_DIR})
#Setup Protobufs(These are built by CMake)
add_subdirectory(ProtoFiles)
set (PROTOBUF_MESSAGE_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/ProtoFiles)
add_subdirectory (ExchangeHandlerServer)
add_subdirectory (TestServer)
add_subdirectory (TestClient)