<div class="gmail_quote">On Fri, Jan 30, 2009 at 12:56 PM, Bartlett, Roscoe A <span dir="ltr">&lt;<a href="mailto:rabartl@sandia.gov">rabartl@sandia.gov</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">







<div>
<font size="2" face="Arial, sans-serif">
<div>Hello,</div>
<div>&nbsp;</div>
<div>I would like to be able to append arbitrary linker options to the end of my link lines on Unix/Linux systems.&nbsp; However, the options set in the CMAKE_EXE_LINKER_FLAGS variable are listed *before* all of the libraries that CMake knows about.&nbsp; 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>&nbsp;</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>&nbsp;</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&#39;s
merely for special flags to be appended to linking a particular target.&nbsp;  If you need to apply the same linking flags to many targets you can create a function() to ease your pain.&nbsp; <br>&nbsp;
<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>&nbsp;&nbsp;&nbsp; if(CMAKE_COMPILER_IS_GNUCC)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set(new_link_flags &quot;-Whatever&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get_target_property(existing_link_flags ${_target} LINK_FLAGS)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(existing_link_flags)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set(new_link_flags &quot;${existing_link_flags} ${new_link_flags}&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; endif()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set_target_properties(${_target} PROPERTIES LINK_FLAGS ${new_link_flags})<br>&nbsp;&nbsp;&nbsp; endif()<br>endfunction()<br>
<br>
add_executable(foo foo.cc)<br>add_my_mpi_ldflags(foo)<br></div></div><br>-- <br>Philip Lowman<br>