[CMake] Question about add_custom_command

Michael Wild themiwi at gmail.com
Mon Sep 13 07:29:56 EDT 2010


On 13. Sep, 2010, at 13:03 , David Aldrich wrote:

> Hi Michael
> 
>> set(SRCS a.c b.c d.c e.c)
>> 
>> add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/f.c
>>  COMMAND ...
>>  DEPENDS ${SRCS}
>>  COMMENT "Generating f.c"
>>  VERBATIM)
>> list(APPEND SRCS ${CMAKE_BINARY_DIR}/f.c)
>> 
>> add_executable(main ${SRCS})
> 
> Thanks - that worked nicely.
> 
> Now I have another problem. I need to link to the Python libraries. So I specify:
> 
> FIND_PACKAGE(PythonLibs REQUIRED)
> INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
> 
> <snip>
> 
> message (${PYTHON_LIBRARY})
> add_library( Kernel STATIC ${SRCS} )
> TARGET_LINK_LIBRARIES(Kernel ${PYTHON_LIBRARY})
> 
> The message shows:
> 
> /usr/lib64/libpython2.4.so
> 
> but this path does not appear in the link command so the build fails.
> 
> I am trying to build a static library so am worried why ${PYTHON_LIBRARY} is a shared library.
> 
> By the way, is it normal CMake style to write CMAKE commands in upper or lower case?
> 
> Can you help with these questions please?
> 
> BR
> 
> David

You never link static libraries. They are more like zip files than actual libraries and just contain the compiled object files and for if you ran ranlib on it, also a "table-of-contents" to speed link up.

If you do "target_link_libraries" in CMake, where the target is a static library, CMake just creates the static library archive and remembers internally the transitive link dependency. If you linked that static archive into an executable, the python libraries would then show up on the command line.

HTH

Michael

--
There is always a well-known solution to every human problem -- neat, plausible, and wrong.
H. L. Mencken

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100913/70fc2c2f/attachment.pgp>


More information about the CMake mailing list