[CMake] Static and shared libraries with the same name

Jorge Rodriguez jrodriguez at xvt.com
Mon Aug 21 20:10:54 EDT 2006


I am trying to create a static, and a shared library, where both have 
the same name and both share the same source code. I was recommended 
previously to use this sort of code:

ADD_LIBRARY(foo SHARED ${FOO_SRCS})
ADD_LIBRARY(foos STATIC ${FOO_SRCS})
SET_TARGET_PROPERTIES(foos PROPERTIES OUTPUT_NAME foo)

This worked great when I tested it under Visual Studio. When I tested it 
under NMake Linux and Mac though, it did not work. I got this error:

make[2]: *** No rule to make target `lib/libfoo.so', needed by 
`bin/bar'.  Stop.

As it turns out, when make goes to build libfoo.a, it runs a clean 
target first that cleans (deletes) libfoo.so. The file in the build tree 
src/foo/CMakeFiles/foos.dir/cmake_clean_target.cmake reads like so:

FILE(REMOVE
"../../lib/libfoo.a"
"../../lib/libfoo.so"
"../../lib/foo"
)

That's not right! It should only clean libfoo.a! Looks like I can't 
accomplish this that way. What else can I do?

Also, could we make the Visual Studio generator and the nmake generator 
match behavior? If the foos target cleans libfoo.so in nmake then it 
should also clean it in Visual Studio. But I don't see why it should 
clean that in the first place.

-- 
Jorge Rodriguez
XVT Software Development
Email: jrodriguez at xvt.com
Phone: (919) 854-1800 x222




More information about the CMake mailing list