[CMake] Proper way to build static binaries
Simon Sasburg
simon.sasburg at gmail.com
Fri Sep 16 03:36:54 EDT 2011
For MSVC I use something like this to allow linking statically to the
C/C++ runtime:
IF(MSVC)
SET(LINK_STATIC_RUNTIME OFF CACHE BOOL "Link statically against
C/C++ runtime")
IF(LINK_STATIC_RUNTIME)
foreach(cfgtype ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
string(TOUPPER "CMAKE_C_FLAGS_${cfgtype}" flag_var)
string(REGEX REPLACE "/MD" "/MT" ${flag_var}
"${${flag_var}}")
string(TOUPPER "CMAKE_CXX_FLAGS_${cfgtype}" flag_var)
string(REGEX REPLACE "/MD" "/MT" ${flag_var}
"${${flag_var}}")
endforeach()
ENDIF()
ENDIF()
On Thu, Sep 15, 2011 at 15:07, David Demelier <demelier.david at gmail.com> wrote:
> Hi,
>
> I'm surprised to see that there is no optional [STATIC] argument in
> add_executable cmake command. I think it should be very important to have
> this because a lot of people like having static binaries.
>
> Thus for the moment what is the best way and more portable way to set a
> binary to be build as static ?
>
> Cheers,
>
> --
> David Demelier
> _______________________________________________
> 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