Re: [CMake] Static linking and find_library

2009-05-13 Thread S. Levent Yilmaz
On Mon, May 11, 2009 at 1:39 PM, Brad King brad.k...@kitware.com wrote:
 Bill Hoffman wrote:

 Marcel Loose wrote:

 2) How can I persuade find_library() to only search for static
 libraries?

 You can't.

 Yes, you can:

  find_library(MATH_LIB NAMES libm.a)

 If you specify a valid library name then CMake will look for it directly
 instead of prepending 'lib' and appending library extensions.

 The reason there is no generic find a static library option is because
 it is almost impossible to implement on windows where one cannot
distinguish
 import libraries and static libraries by their name.


Based on my experience, the necessity to enforce static links is almost
always a platform specific issue (cf. computing clusters). And therefore,
dare I say, CMakeLists.txt is not the place to enforce this, and certainly
having to input platform specific stuff in my CMakeLists.txt is quite
tiresome to say the least. (moreover, in such setting, the complication with
windows and friends is irrelevant).

So, if I may, let me shift the question a little bit: How can one enforce
static linkage on a per platform basis (not the whole project)? In other
words, what setting can we insert into a toolchain
filehttp://www.vtk.org/Wiki/CMake_Cross_Compilingto make this
possible?

Let me identify a problem here with find_library(). Here is a repeatable
scenario; take the following 3 line CMakeLists.txt:
project( foo CXX )
cmake_minimum_required(VERSION 2.6)
find_library( FOO_LIBRARY foo ENV LD_LIBRARY_PATH )

where somewhere in the list LD_LIBRARY_PATH there exists libfoo.so and libfoo.a
(replace foo with an actual lib in your environment). Then with CMake 2.6.x
or today's HEAD version, run cmake in the following 4 different ways:

   1. cmake ..
   2. cmake -DCMAKE_SYSTEM_NAME=Generic ..
   3. cmake -DCMAKE_SYSTEM_NAME=Catamount ..
   4. cmake -DCMAKE_TOOLCHAIN_FILE=sysbar.cmake ..

Case (1) will yield libfoo.so, case (2) will yield libfoo.so, and case (3)
will yield libfoo.a.  Case (4) uses a custom crafted toolchain file, let's
leave that for later.

Confusion grows deeper once one digs into the Platform files.. Take the line
(and the only line) in share/cmake-2.x/Modules/Platform/Generic.cmake:

SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)

and it seems to have no effect. [..]Platform/Catamount.cmake  also has this
line along with bunch of other stuff, and it successfully forces
find_library() to get to the static library. In Case(4) the custom toolchain
file sysbar.cmake is nothing but  set(CMAKE_SYSTEM_NAME Generic) followed by
the rest of the stuff in Catamount.cmake. Case(4), quite confusingly, finds
libfoo.so!!

Sorry for the long message, but I really tried to condense it as much as I
could. Any ideas?


- Levent
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Static linking and find_library

2009-05-13 Thread Brad King

S. Levent Yilmaz wrote:
How can one enforce static linkage on a per platform basis (not the whole project)? 
In other words, what setting can we insert into a toolchain file 
http://www.vtk.org/Wiki/CMake_Cross_Compiling to make this possible?


Let me identify a problem here with find_library(). Here is a repeatable 
scenario; take the following 3 line CMakeLists.txt: 


project( foo CXX )
cmake_minimum_required(VERSION 2.6)
find_library( FOO_LIBRARY foo ENV LD_LIBRARY_PATH )

^^^
This is almost certainly a bad idea.  The find_library command already
provides lots of customization features.  See its documentation.
Also, if you're trying to build static libs then why search in dynamic
loader paths for libraries?

What happens in your cases when it is not done?


   2. cmake -DCMAKE_SYSTEM_NAME=Generic ..
   3. cmake -DCMAKE_SYSTEM_NAME=Catamount ..


I don't think direct definition of CMAKE_SYSTEM_NAME is supported.
It's supposed to be detected and set by the platform files.  Only
through a toolchain file should it be customized.  (Alex?)


line (and the only line) in share/cmake-2.x/Modules/Platform/Generic.cmake:

SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)


It's mostly for reference by CMakeLists.txt code in the project.

and it seems to have no effect. [..]Platform/Catamount.cmake  also has 
this line along with bunch of other stuff, and it successfully forces 
find_library() to get to the static library. In Case(4) the custom 
toolchain file sysbar.cmake is nothing but  set(CMAKE_SYSTEM_NAME 
Generic) followed by the rest of the stuff in Catamount.cmake. Case(4), 
quite confusingly, finds libfoo.so!!  


Your file sets CMAKE_FIND_LIBRARY_SUFFIXES but CMake loads the module
CMakeGenericSystem.cmake *after* the toolchain file and changes it back
to putting .so in the list.  The toolchain file is just supposed to
specify some very basic information which triggers loading of platform-
specific configuration.

The documentation you reference at

  http://www.cmake.org/Wiki/CMake_Cross_Compiling

says that a ${CMAKE_SYSTEM_NAME}.cmake module is mandatory.
The module will be loaded after CMakeGenericSystem.cmake so it gets
the final say in values of variables like CMAKE_FIND_LIBRARY_SUFFIXES.
This is why it works for Catamount.  You need to create a module like
Catamount.cmake for your own target platform, and put it somewhere
referenced by CMAKE_MODULE_PATH (Alex, can you confirm this?).

-Brad

___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Static linking and find_library

2009-05-13 Thread Alexander Neundorf
On Wednesday 13 May 2009, Brad King wrote:
 S. Levent Yilmaz wrote:
  How can one enforce static linkage on a per platform basis (not the whole
  project)? In other words, what setting can we insert into a toolchain
  file http://www.vtk.org/Wiki/CMake_Cross_Compiling to make this
  possible?
 
  Let me identify a problem here with find_library(). Here is a repeatable
  scenario; take the following 3 line CMakeLists.txt:
 
  project( foo CXX )
  cmake_minimum_required(VERSION 2.6)
  find_library( FOO_LIBRARY foo ENV LD_LIBRARY_PATH )

  ^^^
 This is almost certainly a bad idea.  The find_library command already
 provides lots of customization features.  See its documentation.
 Also, if you're trying to build static libs then why search in dynamic
 loader paths for libraries?

 What happens in your cases when it is not done?

 2. cmake -DCMAKE_SYSTEM_NAME=Generic ..
 3. cmake -DCMAKE_SYSTEM_NAME=Catamount ..

 I don't think direct definition of CMAKE_SYSTEM_NAME is supported.
 It's supposed to be detected and set by the platform files.  Only
 through a toolchain file should it be customized.  (Alex?)

Well, after all, it's just a cmake variable, so it can also be set from the 
command line.
If it is already set when cmake would try to determine the system, it 
interprets this as cross compiling, i.e. CMAKE_SYSTEM is already set because 
the system you want to build for is not the current host system, but a 
different one, and that's why (and only that's why) it should be set.

  line (and the only line) in
  share/cmake-2.x/Modules/Platform/Generic.cmake:
 
  SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)

 It's mostly for reference by CMakeLists.txt code in the project.

This disables the building of shared libraries and produces warnings 
for add_library(SHARED).

  and it seems to have no effect. [..]Platform/Catamount.cmake  also has
  this line along with bunch of other stuff, and it successfully forces
  find_library() to get to the static library. In Case(4) the custom
  toolchain file sysbar.cmake is nothing but  set(CMAKE_SYSTEM_NAME
  Generic) followed by the rest of the stuff in Catamount.cmake. Case(4),
  quite confusingly, finds libfoo.so!!

 Your file sets CMAKE_FIND_LIBRARY_SUFFIXES but CMake loads the module
 CMakeGenericSystem.cmake *after* the toolchain file and changes it back
 to putting .so in the list.  The toolchain file is just supposed to
 specify some very basic information which triggers loading of platform-
 specific configuration.

Yes.
It should only preset the things cmake can not automatically detect when cross 
compiling, i.e. the target system name, where the target environment is 
located, and which compiler to use.

 The documentation you reference at

http://www.cmake.org/Wiki/CMake_Cross_Compiling

 says that a ${CMAKE_SYSTEM_NAME}.cmake module is mandatory.
 The module will be loaded after CMakeGenericSystem.cmake so it gets
 the final say in values of variables like CMAKE_FIND_LIBRARY_SUFFIXES.
 This is why it works for Catamount.  You need to create a module like
 Catamount.cmake for your own target platform, and put it somewhere
 referenced by CMAKE_MODULE_PATH (Alex, can you confirm this?).

Yes.

Alex
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Static linking and find_library

2009-05-13 Thread S. Levent Yilmaz
On Wed, May 13, 2009 at 4:09 PM, Brad King brad.k...@kitware.com wrote:

 S. Levent Yilmaz wrote:

 How can one enforce static linkage on a per platform basis (not the whole
 project)? In other words, what setting can we insert into a toolchain file 
 http://www.vtk.org/Wiki/CMake_Cross_Compiling to make this possible?

 Let me identify a problem here with find_library(). Here is a repeatable
 scenario; take the following 3 line CMakeLists.txt:
 project( foo CXX )
 cmake_minimum_required(VERSION 2.6)
 find_library( FOO_LIBRARY foo ENV LD_LIBRARY_PATH )

^^^
 This is almost certainly a bad idea.  The find_library command already
 provides lots of customization features.  Seeits documentation.


Don't get hang up on this, it is just an example (although I'd really love
to hear you describe why it is a bad idea, and pls dont' rtfm me -- no
rhetoric intended). That said, a simple find_library( FOO_LIBRARY foo )
won't find libfoo.a since libfoo is not at some standard location, as is
usually the case with cross compiling; that is, unless one sets a proper
CMAKE_FIND_ROOT_PATH for a given system.. and we're back to this being a
simple example.. (And yes, I was referring to cross compiling scenarios
throughout; sorry if that wasn't clear enough in my post).


 Also, if you're trying to build static libs then why search in dynamic
 loader paths for libraries?


Because static libs are usually under the same directory as dynamic libs.
And dynamic libs ARE installed by the administrator, even though users
aren't supposed to use them. I can dwell more on this point, but rather not.
Let's just say these are the kind of systems I have to deal with..


 Your file sets CMAKE_FIND_LIBRARY_SUFFIXES but CMake loads the module
 CMakeGenericSystem.cmake *after* the toolchain file and changes it back
 to putting .so in the list.  The toolchain file is just supposed to
 specify some very basic information which triggers loading of platform-
 specific configuration.


I see. that's good to know. looking back at the wiki on cross compiling,
this info is indeed there. I just didn't realize the
CMakeGenericSystem.cmake is part of the distribution already.. anyways.


-- Levent
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Static linking and find_library

2009-05-13 Thread S. Levent Yilmaz
  I don't think direct definition of CMAKE_SYSTEM_NAME is supported.
  It's supposed to be detected and set by the platform files.  Only
  through a toolchain file should it be customized.  (Alex?)

 Well, after all, it's just a cmake variable, so it can also be set from the
 command line.


Quoting http://www.vtk.org/Wiki/CMake_Cross_Compiling


 -- The toolchain file --
 Defining all the variables mentioned above using -DCMAKE_SYSTEM_NAME etc.
would be quite tedious and error prone. To make things easier, there is
 another cmake variable you can set:


so, it just convenience (and good design) to put these in a file, right?

 [..]  The toolchain file is just supposed to
  specify some very basic information which triggers loading of platform-
  specific configuration.

 Yes.
 It should only preset the things cmake can not automatically detect when
 cross
 compiling, i.e. the target system name, where the target environment is
 located, and which compiler to use.


Can I argue that the need to build a statically linked executable is also a
cross compiling issue? If yes, then toolchain file should also be able to
set this..


  The documentation you reference at
 
 http://www.cmake.org/Wiki/CMake_Cross_Compiling
 
  says that a ${CMAKE_SYSTEM_NAME}.cmake module is mandatory.
  The module will be loaded after CMakeGenericSystem.cmake so it gets
  the final say in values of variables like CMAKE_FIND_LIBRARY_SUFFIXES.
  This is why it works for Catamount.  You need to create a module like
  Catamount.cmake for your own target platform, and put it somewhere
  referenced by CMAKE_MODULE_PATH (Alex, can you confirm this?).

 Yes.

 Alex


So, to sum it up, is our only option to force find_library() to seek out
static libs is to create a Platform module?


- Levent
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Static linking and find_library

2009-05-12 Thread Marcel Loose
Thanks Brad,

Didn't realize that.
Does that also mean that I could change the default search order by
using:

  find_library(MATH_LIB NAMES libm.a libm.so)


Best regards,
Marcel Loose.

On Mon, 2009-05-11 at 13:39 -0400, Brad King wrote:
 Bill Hoffman wrote:
  Marcel Loose wrote:
  2) How can I persuade find_library() to only search for static
  libraries?
 
  You can't.
 
 Yes, you can:
 
find_library(MATH_LIB NAMES libm.a)
 
 If you specify a valid library name then CMake will look for it directly
 instead of prepending 'lib' and appending library extensions.
 
 The reason there is no generic find a static library option is because
 it is almost impossible to implement on windows where one cannot distinguish
 import libraries and static libraries by their name.
 
 -Brad

___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Static linking and find_library

2009-05-12 Thread Brad King

Marcel Loose wrote:

On Mon, 2009-05-11 at 13:39 -0400, Brad King wrote:

   find_library(MATH_LIB NAMES libm.a)

Does that also mean that I could change the default search order by
using:

  find_library(MATH_LIB NAMES libm.a libm.so)


The search looks for all the names in each directory before moving on
to the next directory, so this will still find the .so if the first
directory does not have the .a archive.

The following should work, though:

  find_library(MATH_LIB NAMES libm.a)
  find_library(MATH_LIB NAMES m)

-Brad
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Static linking and find_library

2009-05-11 Thread Denis Scherbakov

Currently there is no way to do something like
-Wl,-Bstatic -lname -Wl,-Bdynamic

I can assume that some people in some situations may want to do that.

  Marcel Loose wrote:
 ...
   2) How can I persuade find_library() to only
 search for static
   libraries?
 
  You can't.
 
 People ask this a lot. Is there a technical reason or has
 it just not been 
 done ?



  
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Static linking and find_library

2009-05-11 Thread Brad King

Bill Hoffman wrote:

Marcel Loose wrote:

2) How can I persuade find_library() to only search for static
libraries?


You can't.


Yes, you can:

  find_library(MATH_LIB NAMES libm.a)

If you specify a valid library name then CMake will look for it directly
instead of prepending 'lib' and appending library extensions.

The reason there is no generic find a static library option is because
it is almost impossible to implement on windows where one cannot distinguish
import libraries and static libraries by their name.

-Brad
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Static linking and find_library

2009-05-09 Thread Philip Lowman
On Fri, May 8, 2009 at 10:58 AM, Marcel Loose lo...@astron.nl wrote:

 Hi Denis,

 There are definitely cases where you do want to create a statically
 linked executable; for example when running on a massively parallel
 diskless system -- you don't want thousands of compute nodes to load a
 shared library over some NFS link.

 Anyway, the real problem with find_library() is, when you have a shared
 library installed, but not the associated static library. In that case,
 the linker will choke while creating a statically linked executable,
 because it cannot find the library it needs.

 I guess the only way to solve this is to manually set
 CMAKE_FIND_LIBRARY_SUFFIXES, like FindBoost.cmake does. I wish there
 were a more generic, platform-independent way to do this. Maybe worth a
 feature request?


The big problem is WIN32 where static and shared/import libraries have the
same file extension so they obviously can't go in the same directory.  You
could solve the problem with keywords.  If you forced the keywords to have
actual filenames behind them it would probably make it clear to people at
first glance that they only affect WIN32.  For example:

find_library(FOO NAMES foo STATIC:foo_static.lib SHARED:foo.lib )

Then all you would need is a variable with 4 options to control the
searching
1. prefer shared (default)
2. prefer static
3. require shared
4. require static

-- 
Philip Lowman
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Static linking and find_library

2009-05-08 Thread Bill Hoffman

Marcel Loose wrote:

Ping!

I sent this mail more than a week ago, but got no answers. 




Hi all,

I've been searching the documentation, but couldn't find a way to
specify that I want to create a statically linked binary. The only
platform-specific and even compiler-specific answer I could find was to
add -static to CMAKE_EXE_LINKER_FLAGS.

Now this solves only part of the problem. Suppose I want to link against
the static library of some 3rd party package Foo. Suppose that Foo only
supplies a libfoo.so (but I'm unaware of this fact).

When I search for the foo-library using find_library(foo_library foo) I
find a match, so CMake happily trods on. But when I type 'make', I'll
discover to my dismay that the system cannot create a  statically linked
executable, because it cannot find libfoo.a. Bummer!

So my question is twofold:

1) Is there a generic platform- and compiler-independent way to specify
that you want to create a statically linked executable?


No.

2) How can I persuade find_library() to only search for static
libraries?


You can't.

-Bill

--
Bill Hoffman
Kitware, Inc.
28 Corporate Drive
Clifton Park, NY 12065
bill.hoff...@kitware.com
http://www.kitware.com
518 881-4905 (Direct)
518 371-3971 x105
Fax (518) 371-4573
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Static linking and find_library

2009-05-08 Thread Denis Scherbakov


 1) Is there a generic platform- and compiler-independent
 way to specify
 that you want to create a statically linked executable?

find /usr/share/cmake -type f | grep -E '\.cmake$' | xargs grep -i -n -H 
'\-static'

No matches == there is no cross-platform way to specify that you want static 
exectuable.

I think this is a bug, but since, we are talking about static executables, you 
may want to read http://people.redhat.com/drepper/no_static_linking.html

In general, linking statically is a very bad idea.
Moreover, if your code is not GPL, you're not allowed to link against 
libc/libgcc statically. It is direct GPL violation.
 
 2) How can I persuade find_library() to only search for
 static
 libraries?

You don't need to. -static option for gcc will make the trick and gcc will 
automatically pick *.a instead of *.so, if it exists.



  
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Static linking and find_library

2009-05-08 Thread Jed Brown
Denis Scherbakov wrote:

 In general, linking statically is a very bad idea.

Not always though.  There are many reasons for linking statically
including distributing an app that uses a small part of a library
without requiring users to have the whole thing, running on compute
nodes that do not support shared libs, and occasional performance
benefits from position-dependent code.

It is really annoying to have to make sure you have an environment in
which no shared libs can be found just to link statically.  Very few
Find* modules work correctly with static libs anyway, so it's a much
bigger ball of wax than just a tweak to find_library.

 You don't need to. -static option for gcc will make the trick and gcc
 will automatically pick *.a instead of *.so, if it exists.

Sure, if the link line has

  -static -lfoo

but you get an error if you have

  -static /path/to/foo.so

which is the way CMake does it.

Jed



signature.asc
Description: OpenPGP digital signature
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Static linking and find_library

2009-05-08 Thread Marcel Loose
Hi Denis,

There are definitely cases where you do want to create a statically
linked executable; for example when running on a massively parallel
diskless system -- you don't want thousands of compute nodes to load a
shared library over some NFS link.

Anyway, the real problem with find_library() is, when you have a shared
library installed, but not the associated static library. In that case,
the linker will choke while creating a statically linked executable,
because it cannot find the library it needs.

I guess the only way to solve this is to manually set
CMAKE_FIND_LIBRARY_SUFFIXES, like FindBoost.cmake does. I wish there
were a more generic, platform-independent way to do this. Maybe worth a
feature request?

Best regards,
Marcel Loose.


On Fri, 2009-05-08 at 06:33 -0700, Denis Scherbakov wrote:
 
  1) Is there a generic platform- and compiler-independent
  way to specify
  that you want to create a statically linked executable?
 
 find /usr/share/cmake -type f | grep -E '\.cmake$' | xargs grep -i -n -H 
 '\-static'
 
 No matches == there is no cross-platform way to specify that you want static 
 exectuable.
 
 I think this is a bug, but since, we are talking about static executables, 
 you may want to read http://people.redhat.com/drepper/no_static_linking.html
 
 In general, linking statically is a very bad idea.
 Moreover, if your code is not GPL, you're not allowed to link against 
 libc/libgcc statically. It is direct GPL violation.
  
  2) How can I persuade find_library() to only search for
  static
  libraries?
 
 You don't need to. -static option for gcc will make the trick and gcc will 
 automatically pick *.a instead of *.so, if it exists.
 
 
 
   

___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Static linking and find_library

2009-05-08 Thread Micha Renner
Am Freitag, den 08.05.2009, 07:29 -0600 schrieb Bill Hoffman:
 Marcel Loose wrote:
  Ping!
  
  I sent this mail more than a week ago, but got no answers. 
This happens sometimes.
  
  
  
  Hi all,
  
  I've been searching the documentation, but couldn't find a way to
  specify that I want to create a statically linked binary. The only
  platform-specific and even compiler-specific answer I could find was to
  add -static to CMAKE_EXE_LINKER_FLAGS.
I could be completly wrong, but you want link a static library to a
program. You don't need CMAKE_EXE_LINKER_FLAGS.

PROJECT(T)
FIND_LIBRARY(_pathAndNameOfLibrary NAMES foo)
ADD_EXECUTABLE(targetname yourSourcefiles)
TARGET_LINK_LIBRARIES(targetname ${_pathAndNameOfLibrary})
  
  Now this solves only part of the problem. Suppose I want to link against
  the static library of some 3rd party package Foo. Suppose that Foo only
  supplies a libfoo.so (but I'm unaware of this fact).
In this case the program is linked to foo.so.  
  
  When I search for the foo-library using find_library(foo_library foo) I
  find a match, so CMake happily trods on. But when I type 'make', I'll
  discover to my dismay that the system cannot create a  statically linked
  executable, because it cannot find libfoo.a. Bummer!
You have to make sure that FIND_LIBRARY finds the library (paths, names)
See www.cmake.org/cmake/help/cmake2.6docs.html#command:find_library for
a detailed description 

You might come in trouble if both versions (.so .a) exist. If they are
located in different directories, this might help:
www.cmake.org/Wiki/CMake_FAQ#Why_does_find_library_look_in_system_directories_before_its_PATHS_option.3F

  
  So my question is twofold:
  
  1) Is there a generic platform- and compiler-independent way to specify
  that you want to create a statically linked executable?
  
 No.
Is this really necessary? Live is already difficult enough.
  2) How can I persuade find_library() to only search for static
  libraries?
  
 You can't.
 
 -Bill
 

___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake