[CMake] sip, pyqt, and linking

Michael Wild themiwi at gmail.com
Thu Dec 9 00:50:29 EST 2010


On 12/09/2010 12:08 AM, luxInteg wrote:
> Greetings 
> 
> consider my small   'learn  cmake/qt4  project' 
> It generates a  library   testLIB-static   in $CMAKE_SOURCE_DIR}/testLIB
> and an executible testBIN in  ${CMAKE_SOURCE_DIR}/upstream/bin
> 
> 
> A) For the library I used
> add_library(testLIB-static    testLIB.cpp )
> 
> 
> B) For the executible 
> I use the sip generator to  generate  code like so
> 
> 
> add_custom_command(OUTPUT 
>  ${CMAKE_CURRENT_BINARY_DIR}/generatedfile1.cpp
>   ----
>   ---
>  COMMAND ${SIP_EXECUTABLE} 
> -c${CMAKE_CURRENT_BINARY_DIR}    
> -I${SIP_PATH} 
> -s ".cpp"
> -t WS_X11 -t Qt$version -w
> 
>   ${CMAKE_SOURCE_DIR}/path/to/generator.sip
> DEPENDS ${CMAKE_SOURCE_DIR}/path/to/generator.sip
> MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/path/to/generator.sip
>   COMMENT "Processing ${CMAKE_SOURCE_DIR}/path/to/generator.sip" 
> VERBATIM )
> 
> 
> add_execitible(testBIN 
> testBIN.cpp
> generatedfile1.cpp )
> 
> target_link_libraries(testLIB-static)

Again, doing some RTFM, you'll find that the signature of
TARGET_LINK_LIBRARIES is like this:

target_link_libraries(<target> [item1 [item2 [...]]]
                      [[debug|optimized|general] <item>] ...)


So, for your example, this means:

target_link_libraries(testBIN testLIB-static)

> 
> ###############  these are my findings
> 
> ----If I add   find_library(XXX  testLIB-static)  before I use the 
> add_executible()  command cmake contends  that  testLIB-static is set to 
> NOTFOUND.

You don't do find_library on targets you create.

> ----If I do not use find_library(XXX  testLIB-static)  and run make,   make 
> goes to 100 per cent and then all hell breaks  loose with  linking problems.

Of course. As I explained above, you need to first pass the TARGET that
is to be linked against the library to TARGET_LINK_LIBRARIES. Otherwise
CMake thinks that you want to link the library target against nothing...
(that probably should be prevented by cmake.)

> 
> If I  change the second line of the add_custom_command()  statement to use 
> 'absolute paths that I can understand such as:-
> 
> ${CMAKE_SOURCE_DIR}/upstream/bin/generatedfile1.cpp  the SIP generator fails  
> to generate  generatedfile1.cpp
> 

Well, then clearly the two are not equivalent. Are you doing in-source
builds? NEVER do that. Don't. Period. And if you do out-of-source
builds, then it is obvious that they are not the same (the former is in
the BUILD tree, whereas the latter is in the SOURCE tree). Really, read
http://www.cmake.org/Wiki/CMake_FAQ#Out-of-source_build_trees.

> 
> 
> Advice ould be appreciated.
> 
> luxInteg

Michael



More information about the CMake mailing list