Z
Z
z0rc2010-10-02 19:21:40
C++ / C#
z0rc, 2010-10-02 19:21:40

CMake and static linking

There is a small self-written cross-platform toy using SDL. C++ language. Under Win32 and Win64 builds in mingw-w64, gcc 4.5.1.

I would like the following: in assemblies under Windows, link dependencies statically. I don't feel like lugging around a good dozen libraries. Now in the build environment there are both versions of libraries: for static and dynamic linking. By default, gcc prefers to link dynamically. In order for it to select static versions of libraries, you need to add the -static key before them. And then you need to add the -dynamic key before the libraries that are linked dynamically (OpenGL).

Question: how to force/teach cmake to build the required command line?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
VaiMR, 2010-10-04
@VaiMR

if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
Your code...
else()
Your code...
endif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
www.paraview.org/Wiki/CMake_Useful_Variables

Y
yse, 2013-12-02
@yse

If my memory serves me, then for target_link_libraries it doesn't matter if the link is static or dynamic.
If you want some specific option to the compiler or linker, then in these cases use set_target_properties. There are COMPILE_FLAGS and LINK_FLAGS and a bunch of other things (see www.cmake.org/cmake/help/v2.8.12/cmake.html#section_PropertiesonTargets )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question