<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3492" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=433174522-01022009><FONT face=Arial
color=#0000ff size=2>Setting <FONT face="Times New Roman" color=#000000
size=3>set_target_properties(foo PROPERTIES LINK_FLAGS ...) does not
work. The other libraries just come after these
flags.</FONT></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=433174522-01022009></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=433174522-01022009><FONT face=Arial
color=#0000ff size=2>- Ross</FONT></SPAN></DIV><BR>
<BLOCKQUOTE
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> philiplowman@gmail.com
[mailto:philiplowman@gmail.com] <B>On Behalf Of </B>Philip
Lowman<BR><B>Sent:</B> Friday, January 30, 2009 11:25 AM<BR><B>To:</B>
Bartlett, Roscoe A<BR><B>Cc:</B> cmake@cmake.org; Perschbacher, Brent
M<BR><B>Subject:</B> Re: [CMake] How to append arbitrary linker
options?<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV class=gmail_quote>On Fri, Jan 30, 2009 at 12:56 PM, Bartlett, Roscoe A
<SPAN dir=ltr><<A
href="mailto:rabartl@sandia.gov">rabartl@sandia.gov</A>></SPAN> wrote:<BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<DIV><FONT face="Arial, sans-serif" size=2>
<DIV>Hello,</DIV>
<DIV> </DIV>
<DIV>I would like to be able to append arbitrary linker options to the end
of my link lines on Unix/Linux systems. However, the options set in
the CMAKE_EXE_LINKER_FLAGS variable are listed *before* all of the libraries
that CMake knows about. I need to be able to append a bunch of nasty
options like Fortran libraries, MPI libraries (in some nasty cases) and
other libraries that must come after all other libraries.</DIV>
<DIV> </DIV>
<DIV>The problem is that while I could carefully list the libraries that
need to be appended and I could use find_library(...) to get them correctly
I may just have a glob of libraries and other linker options that someone
gives me and I just want to apply them without having to parse everything
out.</DIV>
<DIV> </DIV>
<DIV>Is there some way to force CMake on Unix/Linux systems to append
arbitrary linker options?</DIV></FONT></DIV></BLOCKQUOTE>
<DIV><BR>You can use set_target_properties(foo PROPERTIES LINK_FLAGS ...) on
your targets. The LINK_FLAGS property will not contain CMAKE_EXE_LINKER_FLAGS,
it's merely for special flags to be appended to linking a particular
target. If you need to apply the same linking flags to many targets you
can create a function() to ease your pain. <BR> <BR>Also, be aware
if you set the LINK_FLAGS property twice, the second call will overwrite the
first. If you need to append to LINK_FLAGS (lets say you want one function to
add fortran linking options and the other for MPI) you must first use
get_target_property() and check to see if the property existed, and then
append to it.<BR><BR>function(add_my_mpi_ldflags
_target)<BR>
if(CMAKE_COMPILER_IS_GNUCC)<BR>
set(new_link_flags "-Whatever")<BR>
get_target_property(existing_link_flags ${_target}
LINK_FLAGS)<BR>
if(existing_link_flags)<BR>
set(new_link_flags "${existing_link_flags}
${new_link_flags}")<BR>
endif()<BR>
set_target_properties(${_target} PROPERTIES LINK_FLAGS
${new_link_flags})<BR>
endif()<BR>endfunction()<BR><BR>add_executable(foo
foo.cc)<BR>add_my_mpi_ldflags(foo)<BR></DIV></DIV><BR>-- <BR>Philip
Lowman<BR></BLOCKQUOTE></BODY></HTML>