I did some research, and although I could not find a satisfactory solution to the problem, I found half the solution.
The problem of static builds boils down to 3 things:
Creating and linking internal project libraries.
Pretty simple, you just have to turn the BUILD_SHARED_LIBS OFF switch.
Search for static versions of external libraries.
The only way, apparently, is to set CMAKE_FIND_LIBRARY_SUFFIXES to contain the desired file suffix (its list of priorities).
This solution is rather dirty and very similar to CMake's cross-platform ambition. IMHO this should be handled behind the scenes of CMake, but as I understand it, because of the ".lib" confusion in Windows, it seems that CMake developers prefer the current implementation.
Linking statically with system libraries.
CMake provides the LINK_SEARCH_END_STATIC option, which is based on the documentation: "Complete the link line to use static system libraries." It would seem, that’s all, the problem is solved. However, it seems that the current implementation is not up to the task. If this option is enabled, CMake generates an implicit linker call with an argument list that ends with parameters passed to the linker, including -Wl,-Bstatic . However, this is not enough. Only linking the linker statically results in an error, in my case: /usr/bin/ld: cannot find -lgcc_s . What is missing tells gcc that we need a static binding via the -static argument, which is not generated by invoking the linker using CMake. I think this is a mistake, but so far I have not been able to get confirmation from the developers.
Finally, I think that all this could and should be done by CMake backstage, because it is not so difficult, except that it is impossible in Windows - if it is considered difficult ...
pszilard Nov 09 '10 at 12:29 2010-11-09 12:29
source share