[CMake] creating a shared and static library of the same name

Xavier Delannoy xavier.delannoy at netasq.com
Mon May 15 09:51:57 EDT 2006


it's possible with CMake greater to 2.3.4. I used two diferent destination directories for the static and shared libs.

assuming you're working in the 'libfoo' directory : 

libfoo/sources.txt
      /CMakeLists.txt
      /static/CMakeLists.txt
      /shared/CMakeLists/txt
      *.c

>cat sources.txt
#include common src file
AUX_SOURCE_DIRECTORY( ../ LIBFOO_SRCS)

>cat CMakeLists.txt
PROJECT(LIBFOO C)

SUBDIRS(static)
SUBDIRS(shared)

>cat static/CMakeLists.txt
INCLUDE(${LIBFOO_SOURCE_DIR}/sources.txt)

# I used BUILDDESTLIB from an environment var, I think it's better to use a CMake Variable.
SET(LIBRARY_OUTPUT_PATH "$ENV{BUILDDESTLIB}/static")	

ADD_LIBRARY(foo_static STATIC ${LIBFOO_SRCS})
SET_TARGET_PROPERTIES(foo_static PROPERTIES OUTPUT_NAME foo)

>cat shared/CMakeLists.txt
INCLUDE(${LIBFOO_SOURCE_DIR}/sources.txt)

SET(LIBRARY_OUTPUT_PATH "$ENV{BUILDDESTLIB}")

ADD_LIBRARY(foo_shared SHARED ${LIBFOO_SRCS})

SET_TARGET_PROPERTIES(foo_shared PROPERTIES OUTPUT_NAME foo)

Hope this will help you.


On Mon, 15 May 2006 12:43:52 +0200
"Michael Biebl" <mbiebl at gmail.com> wrote:

> Hi everybody,
> 
> is it possible to create a shared and static library with the same name?
> I tried the folllowing:
> 
> ADD_LIBRARY(foo SHARED foo.c)
> 
> ADD_LIBRARY(foo_static STATIC foo.c)
> SET_TARGET_PROPERTIES(foo_static PROPERTIES OUTPUT_NAME foo)
> 
> But if I then add
> 
> ADD_EXECUTABLE(bar bar.c)
> TARGET_LINK_LIBRARIES(bar foo)  (I want to link it dynamically against
> libfoo.so)
> 
> I get the error:
> 
> make[2]: *** No rule to make target `libfoo.so', needed by `bar'.  Stop.
> 
> Can anyone tell me, what I'm doing wrong and how I can fix this.
> 
> TIA,
> Michael
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
> 


-- 
Xavier Delannoy

R&D engineer
xavier.delannoy at netasq.com
http://www.netasq.com
Tél : +33 320 619 742
Fax : +33 320 619 639

-----------------------------------------------------------------------
This communication may contain information that is proprietary, 
privileged or confidential or otherwise legally exempt from disclosure.
The information contained in this e-mail is intended solely for the
addressee. Access to this e-mail by anyone else or any unauthorized
review, use, disclosure or distribution is unauthorized and prohibited.
If you are not the named addressee indicated in this message (or
responsible for delivery of the message to such person), you are not
authorized to read, print, retain, copy or disseminate this message
or any part of it. If you have received this message in error, please
notify the sender immediately by fax or e-mail and delete and destroy
all copies of the message. If you are the intended recipient but do not
wish to receive communications through this medium, please advise the
sender immediately. The views expressed in this e-mail are not 
necessarily the views of NetASQ. The company, its directors, officers
or employees make no representation or accept any liability for its
accuracy or completeness unless expressly stated to the contrary.
------------------------------------------------------------------------


More information about the CMake mailing list