Is there a way to change stack size from the Cmake ?
I only found one forum thread mentioning CMAKE_CXX_STACK_SIZE
but I couldn't find the documentation for this command. Ideally the command should work for both Visual Studio C++ and gcc.
I don't have VS at the moment, but the following three CMake commands all work for me on MinGW/GCC (replace <target>
with what you entered into add_executable()
):
target_link_libraries(<target> PRIVATE "-Wl,--stack,10000000")
OR
set_target_properties(<target> PROPERTIES LINK_FLAGS -Wl,--stack,10000000)
OR
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,10000000")
Note that according to the CMake documentation, each of these should just add linker flags, not replace any that are already set.
In VS, it looks like you should replace -Wl,--stack,
with /STACK:
(more on this below) and use an if/else to have different commands for each compiler.
Regarding CMAKE_CXX_STACK_SIZE
, this thread, which is worth a read, says the command is
in the implementation of the VS generator for historical reasons but is not intended as a first-class way to set the stack size. Instead just pass
/STACK:
... as a linker flag usingtarget_link_libraries
, or theLINK_FLAGS
target property, or inCMAKE_EXE_LINKER_FLAGS
...
Such a command can actually be seen on the page linked in your post (not sure if you saw it) as well as in this one:
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10000000")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With