[CMake] making two targets with similar names
Bill Hoffman
bill.hoffman at kitware.com
Fri Aug 10 14:54:05 EDT 2007
Juan Sanchez wrote:
> I am having the following issue. I want to create both a libFOO.a and a
> libFOO.so. Note that the libFOO.so is composed of more sources than the
> libFOO.a.
>
> I use OUTPUT_NAME in order so they have the same name. I can make the
> FOOSTATIC, libFOO.a, target, just fine. However, making the FOODYNAMIC,
> libFOO.so, target deletes libFOO.a, just before linking against it.
> This causes a build error.
>
> Is there anyway to prevent this from happening?
>
>
> ADD_LIBRARY (FOOSTATIC STATIC ${UDB_SRCS})
> ADD_LIBRARY (FOODYNAMIC SHARED ${PERL_SRCS})
>
> target_link_libraries(FOODYNAMIC FOOSTATIC)
>
> SET_TARGET_PROPERTIES(FOODYNAMIC PROPERTIES
> LINK_FLAGS --whole-archive
> OUTPUT_NAME FOO
> )
>
> SET_TARGET_PROPERTIES(FOOSTATIC PROPERTIES
> OUTPUT_NAME FOO
> )
>
See the documentation for OUTPUT_NAME:
When a library is built CMake by default generates code to remove any
existing library using all possible names. This is needed to support
libraries that switch between STATIC and SHARED by a user option.
However when using OUTPUT_NAME to build a static and shared library of
the same name using different logical target names the two targets will
remove each other's files. This can be prevented by setting the
CLEAN_DIRECT_OUTPUT property to 1.
-Bill
More information about the CMake
mailing list