[CMake] /STACK:10000000 being added to linker in Visual Studio?

Yuri Timenkov yuri at timenkov.ru
Wed Jun 27 23:31:40 EDT 2012


As an option you can set up all these flags manually. In my current
project we don't have many compilers to support but we need
fine-grained control over compiler options (due to legacy and
compatibility reasons). CMake allows to set precisely required
options:

# Override default Compiler flags
set(CMAKE_USER_MAKE_RULES_OVERRIDE MyCompilerFlags)

project(MyProject)

Where MyCompilerFlags contains something like this:
if(MSVC)
       # Set default linker options.
       set(CMAKE_SHARED_LINKER_FLAGS_INIT "/MACHINE:X86 /DEBUG")
       set(CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT "/INCREMENTAL:NO")
       set(CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT "/INCREMENTAL:NO")

   # Now use same options for all dynamic modules.
       set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_SHARED_LINKER_FLAGS_INIT}")
       set(CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT}")
       set(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT
"${CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT}")

       set(CMAKE_MODULE_LINKER_FLAGS_INIT "${CMAKE_SHARED_LINKER_FLAGS_INIT}")
       set(CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT}")
       set(CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT
"${CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT}")

       set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} /Zi
/D_WIN32_WINNT=0x0501")

   if(MSVC_VERSION GREATER 1200)
       set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} /WX
/D_SCL_SECURE_NO_DEPRECATE /wd4251 /wd4275 /wd4503")
   endif()
endif(MSVC)

#
# Tune compiler and linker flags.
#
if(CMAKE_COMPILER_IS_GNUCXX)
       # Our default policy: Treat all warnings as errors.
       # Build multi-threaded libraries and applications.
       set(CMAKE_C_FLAGS_INIT "-fmessage-length=0 -pthread -D_REENTRANT -ggdb")

       # Enable C++ 0x support.
       set(CMAKE_CXX_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -std=c++0x")
endif(CMAKE_COMPILER_IS_GNUCXX)

On Wed, Jun 27, 2012 at 11:38 PM, Robert Dailey
<rcdailey.lists at gmail.com> wrote:
> Yeah certainly, especially since multicore is pretty much everywhere now and
> most applications are designed with parallelization in mind.
>
> Like every other compiler and linker flag out there, have the user manually
> set that up if they want it. CMake doesn't automatically add any other
> compiler flags for me, so /STACK shouldn't be any different IMHO.
>
> Thanks for your help, I will try using those new global variables.
>
>
> On Wed, Jun 27, 2012 at 2:35 PM, David Cole <david.cole at kitware.com> wrote:
>>
>> Ah. I just read through Windows-cl.cmake again to refresh my memory....
>>
>> Also do the same thing with these two variables:
>> CMAKE_SHARED_LINKER_FLAGS for SHARED dll targets, and
>> CMAKE_MODULE_LINKER_FLAGS for MODULE dll targets. That should take
>> care of it.
>>
>> Whew. Maybe we should just remove it from CMake one of these days.
>> Seems like a bit of an excessive stack size to have by default,
>> doesn't it? :-)
>>
>>
>> David
>>
>>
>> On Wed, Jun 27, 2012 at 3:27 PM, Robert Dailey <rcdailey.lists at gmail.com>
>> wrote:
>> > I just tried your code and unfortunately /STACK still shows up for DLL
>> > targets, although for EXE targets it seems to be gone.
>> >
>> >
>> > On Wed, Jun 27, 2012 at 2:24 PM, David Cole <david.cole at kitware.com>
>> > wrote:
>> >>
>> >> Try my code, and tell us if it removes the generated /STACK from all
>> >> your linker calls or not...
>> >>
>> >> Thx,
>> >> David
>> >>
>> >> On Wed, Jun 27, 2012 at 3:22 PM, Robert Dailey
>> >> <rcdailey.lists at gmail.com>
>> >> wrote:
>> >> > Apparently this won't work... /STACK doesn't show up in any of the
>> >> > compile
>> >> > flags retrieved this way. However, CMAKE_EXE_COMPILER_FLAGS doesn't
>> >> > apply to
>> >> > library targets, right?
>> >> >
>> >> >
>> >> > On Wed, Jun 27, 2012 at 2:19 PM, Robert Dailey
>> >> > <rcdailey.lists at gmail.com>
>> >> > wrote:
>> >> >>
>> >> >> This flag is appended to DLL targets too, so I created this (i
>> >> >> haven't
>> >> >> tested it yet though):
>> >> >>
>> >> >> function( _remove_stack_flag target_name )
>> >> >> get_property( flags TARGET ${target_name} PROPERTY COMPILE_FLAGS )
>> >> >> string( REGEX REPLACE "/STACK:[0-9]+" "" flags ${flags} )
>> >> >> set_property( TARGET ${target_name} PROPERTY COMPILE_FLAGS ${flags}
>> >> >> )
>> >> >> endfunction()
>> >> >>
>> >> >> I call this once for each target I define.
>> >> >>
>> >> >>
>> >> >> On Wed, Jun 27, 2012 at 2:17 PM, David Cole <david.cole at kitware.com>
>> >> >> wrote:
>> >> >>>
>> >> >>> You could do:
>> >> >>>
>> >> >>>  string(REPLACE "/STACK:10000000 " "" CMAKE_EXE_LINKER_FLAGS
>> >> >>> "${CMAKE_EXE_LINKER_FLAGS}")
>> >> >>>
>> >> >>> after the first project command in the top level CMakeLists file.
>> >> >>> (Or
>> >> >>> "/STACK:some other number" to change it, instead of the empty
>> >> >>> string
>> >> >>> to just remove it...)
>> >> >>>
>> >> >>> The /STACK string only appears in the two files:
>> >> >>>
>> >> >>>  Modules/Platform/Windows-Intel.cmake
>> >> >>>  Modules/Platform/Windows-cl.cmake
>> >> >>>
>> >> >>>
>> >> >>> HTH,
>> >> >>> David
>> >> >>>
>> >> >>>
>> >> >>> On Wed, Jun 27, 2012 at 3:11 PM, Robert Dailey
>> >> >>> <rcdailey.lists at gmail.com>
>> >> >>> wrote:
>> >> >>> > This is added to every generated visual studio project from
>> >> >>> > version
>> >> >>> > 7.1
>> >> >>> > to
>> >> >>> > 9. How can I tell CMake not to modify the stack size?
>> >> >>> > --
>> >> >>> >
>> >> >>> > Powered by www.kitware.com
>> >> >>> >
>> >> >>> > Visit other Kitware open-source projects at
>> >> >>> > http://www.kitware.com/opensource/opensource.html
>> >> >>> >
>> >> >>> > Please keep messages on-topic and check the CMake FAQ at:
>> >> >>> > http://www.cmake.org/Wiki/CMake_FAQ
>> >> >>> >
>> >> >>> > Follow this link to subscribe/unsubscribe:
>> >> >>> > http://www.cmake.org/mailman/listinfo/cmake
>> >> >>
>> >> >>
>> >> >
>> >
>> >
>
>
>
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list