[CMake] cmake PyQT/SIP

Michael Wild themiwi at gmail.com
Thu Dec 2 02:48:55 EST 2010


On 12/02/2010 08:25 AM, Alan W. Irwin wrote:
> On 2010-12-02 06:32+0100 Michael Wild wrote:
> 
>> On 12/02/2010 12:37 AM, luxInteg wrote:
>>> On Tuesday 30 November 2010 22:43:34 luxInteg wrote:
>>>> Greetings
>>>>
>>>> I an learnig cmake.
>>>
>>> My test project is as follows:-
>>> linux machine with pyQt4, sip-4.10.2,qt-4.6.2 and cmake-2.8.2
>>>
>>> ---stepA: I have a file -fileA.sip.
>>> ---stepB: Upon execution of fileA.sip  two files  files -fileC.cpp and
>>> fileD.cpp    result,
>>> ---stepC: fileC.cpp and fileD,cpp are compiled into  a shared library.
>>>
>>> I am ok with stepC.  I do not know how to carry out step B  
>>> execution  within
>>> cmake.
>>>
>>> advice would be appreciated.
>>>
>>> sincerely
>>> luxInteg
>>
>>
>> Use ADD_CUSTOM_COMMAND.
> 
> @Michael: that advice is not correct.  add_custom_command sets up a
> command to be run at "make" time. Instead, the execute_process command
> should be used to run a command at "CMake" time which is what the OP
> needs to generate his *.cpp files.
> 
> @LuxInteg:  See the CMakeLists.txt file at
> http://plplot.svn.sourceforge.net/viewvc/plplot/trunk/bindings/qt_gui/pyqt4/
> 
> for an example of generating source code with sip.
> 
> Alan

Huh, why can't he run sip at build time? If you do:

find_program(SIP_EXECUTABLE sip)

add_custom_command(OUTPUT
    ${CMAKE_CURRENT_BINARY_DIR}/fileC.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/fileD.cpp
  COMMAND ${SIP_EXECUTABLE} -c ${CMAKE_CURRENT_BINARY_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/fileA.sip
  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/fileA.sip
  COMMENT "Processing ${CMAKE_CURRENT_SOURCE_DIR}/fileA.sip"
  VERBATIM)

add_library(myPythonExtension SHARED
  ${CMAKE_CURRENT_BINARY_DIR}/fileC.cpp
  ${CMAKE_CURRENT_BINARY_DIR}/fileD.cpp)

# possibly link with required libraries here...

That should perfectly work. IMHO generating the C++ files at CMake time
is definitely the wrong approach, since running the sip processor IS a
build step. Additionally, if you do it with EXECUTE_PROCESS, you'll have
to re-run CMake manually when you change any of the .sip files. Using
the ADD_CUSTOM_COMMAND, sip will be re-run automatically thanks to the
DEPENDS option.

Michael


More information about the CMake mailing list