views:

378

answers:

1

Hello all :)

I'm building a file using the CMake Build System and Microsoft's Visual C++ compiler. When I have CMake generate the visual studio project, the project contains the commandline to build a "Multi Threaded DLL" type of runtime -- one which depends on msvcrt.dll. For various reasons I'm not going into right now, I cannot depend on msvcrt.

Is there a way to tell CMake to modify this option in it's construction process?

Thank you!

Billy3

+1  A: 

I use the following piece of code to link to the static CRT:

if(MSVC)
#We statically link to reduce dependancies
foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
    if(${flag_var} MATCHES "/MD")
        string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
    endif(${flag_var} MATCHES "/MD")
    if(${flag_var} MATCHES "/MDd")
        string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
    endif(${flag_var} MATCHES "/MDd")
endforeach(flag_var)
endif(MSVC)
SteveL
This is overkill isn't it? Wouldn't "foreach() string(replace, /md, /mt) endforeach()" work just as well? (i.e. get rid of the if() and the /MDd). The first replace will match the second one anyway, and there is no point searching for a match before you just do the replacement.
brofield