On Mon, May 12, 2008 at 2:46 PM, Glenn Pierce <<a href="mailto:glennpierce@gmail.com" target="_blank">glennpierce@gmail.com</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi I have a library that I compile with visual studio and I would like to make sure it is compiled with the option of the runtime library set too multi-threaded /MT.<br><br>Also I would like it only linked to "user32.lib gdi32.lib"<br>
<br>i have tried using<br><br>SET(CMAKE_CXX_STANDARD_LIBRARIES, "user32.lib gdi32.lib")<br><br>but it seems to have no effect.<br>I don't know what to set to get the runtime library to be multi-threaded /MT.<br>
<br>Does anyone have any ideas ?<b></b></blockquote><div><br>I know of two ways to do this but both have drawbacks (hopefully someone who understands the innards of CMake better can suggest a better alternative):<br><br>
1. Use the FORCE option to force the cache variables to be the way you want them to. This will probably work for your setup, it does have the minor drawback of not allowing your users to change the compile flags from within CMake's cache editor without modifying the CMakeLists.txt file.<br>
<br>PROJECT(foo)<br>IF(MSVC)<br> SET(CMAKE_C_FLAGS_DEBUG "/D_DEBUG /MTd /Zi /Ob0 /Od /GZ" CACHE STRING<br> "Flags used by the compiler during debug builds." FORCE)<br> SET(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /MTd /Zi /Ob0 /Od /GZ" CACHE STRING<br>
"Flags used by the compiler during debug builds." FORCE)<br> SET(CMAKE_C_FLAGS_MINSIZEREL "/MT /O1 /Ob1 /D NDEBUG" CACHE STRING<br> "Flags used by the compiler during release minsize builds." FORCE)<br>
SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /O1 /Ob1 /D NDEBUG" CACHE STRING<br> "Flags used by the compiler during release minsize builds." FORCE)<br> SET(CMAKE_C_FLAGS_RELEASE "/MT /O2 /Ob2 /D NDEBUG" CACHE STRING<br>
"Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files)." FORCE)<br> SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /D NDEBUG" CACHE STRING<br>
"Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files)." FORCE)<br> SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/MT /Zi /O2 /Ob1 /D NDEBUG" CACHE STRING<br>
"Flags used by the compiler during Release with Debug Info builds." FORCE)<br> SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MT /Zi /O2 /Ob1 /D NDEBUG" CACHE STRING<br> "Flags used by the compiler during Release with Debug Info builds." FORCE)<br>
ENDIF()<br><br><br>2. I'm not sure if this is recommended but I discovered you can set CMAKE_NOT_USING_CONFIG_FLAGS to 1 prior to calling PROJECT(). This will let you define the default compiler options you want to use and users will be able to change them in the cache later but I haven't been able to find a way to conditionally assign the variables so you can use more than one compiler. In other words, you could assign them for Visual Studio's CL compiler but the flags would never work if you went to use GCC to compile your project.<br>
</div></div><br>I recommend something similar to the former option.<br clear="all"><br>-- <br>Philip Lowman