Messing around with linkers & CMake

Koop Mast kwm at rainbow-runner.nl
Sat Apr 15 11:36:40 UTC 2017


On Thu, 2017-03-09 at 00:42 +0100, Adriaan de Groot wrote:
> In some cases, we end up with shared-libs that are too big to include
> debug 
> info; webkit2, webengine come to mind. Here's one way to mess with
> the linking 
> step (bear in mind, I haven't played at *all* with the consequences
> this has 
> nor how variable-scope affects generation).
> 
> Consider
> 
> 	add_library(foo SHARED foo.c)
> 
> Build this in verbose mode:
> 	cmake .
> 	make foo VERBOSE=1
> See how the compiler is invoked at the end to link the library?
> 
> 
> Now consider this:
> 
> 	set(CMAKE_C_CREATE_SHARED_LIBRARY
> 		"<CMAKE_LINKER> <CMAKE_SHARED_LIBRARY_C_FLAGS> 
> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS>
> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> 
> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
> 	add_library(foo SHARED foo.c)
> 
> This messes with the command that CMake uses -- and later expands --
> to create 
> shared libraries from C code; the standard definition is in 
> ./Modules/CMakeCInformation.cmake , and uses <CMAKE_C_COMPILER> while
> setting 
> the variable ourselves lets us choose the linker instead. Note that
> this 
> *won't* compile, since the flags for the linker are seriously
> different from 
> what the C compiler expects (in particular, you'll see -Wl,-soname in
> there 
> where the linker invoked directly wants -soname).
> 
> 
> Probably by massaging this variable in a suitable manner you can
> stuff in any 
> particular tool you want.
> 
> [ade]

Hi,

I'm interested in this because of webkitgtk. Like Adriaan said above we
can't currently build it with debug support. This is not a problem on
Linux because binutils have something called thin archives. I don't
know anything about it apart from that it works :)

So I was looking into using binutils from ports to build webkitgtk when
debug is enabled. With the CMAKE_AR and CMAKE_RANLIB variables I can
set the binutils ar and ranlib. However the problem is that for some
reason cmake doesn't have a LINKER variable, which results in it using
ld from base which doesn't understand thin archives. I tried
CMAKE_LINKER a while back and that didn't seem to work.

My question is now does cmake have a variable, or another way, that I
can set so it uses ld from binutils instead of ld from base?

-Koop



More information about the kde-freebsd mailing list