[CMake] Out-of-project link library problem
Christopher Harvey
chris at basementcode.com
Wed Sep 3 19:57:16 EDT 2008
usually, I just do this type of thing:
TARGET_LINK_LIBRARIES(binary SDL GL GLU GLEW)
try getting rid of quotes, and putting them all in a single command.
Andrew Sayman wrote:
> I've been working on linking to some system libraries in a project I'm
> building in Linux and I've run into a problem with CMake adding
> redundant linker arguments.
>
> The simplest case I came down to is this:
> In the Example/Demo/CMakeLists.txt file add the following lines:
> target_link_libraries (helloDemo "m" )
> target_link_libraries (helloDemo "m" )
> target_link_libraries (helloDemo "crypt" "pthread" )
>
> If you turn on verbose makefiles and use the target "Unix Makefiles"
> the generated command line has this portion:
> -lm -lcrypt -lpthread -lm -lcrypt -lpthread
>
> Essentially, it repeats *all* of the system libraries I specified for
> every redundant library that's added.
>
> Changing CMakeLists.txt to something a bit weirder yields the following:
> target_link_libraries (helloDemo "m" )
> target_link_libraries (helloDemo "m" )
> target_link_libraries (helloDemo "crypt" )
> target_link_libraries (helloDemo "pthread" )
> target_link_libraries (helloDemo "crypt" "pthread" )
> -lm -lcrypt -lpthread -lcrypt -lpthread -lm -lcrypt -lpthread -lcrypt -lpthread
>
> The real problem with this is that I use things like FindX11 and
> FindPkgCfg to get generated linking libraries for a bunch of modules
> on the system. Each of these modules often include some redundant
> "base" libraries. For each of those, I end up with this increasingly
> expansive list of libraries when I actually only needed them once.
>
> Any ideas? The current workaround I'm using is to generate my own list
> of the necessary libraries and remove redundancies before adding it to
> the target.
>
More information about the CMake
mailing list