source: orange/source/orangeqt/modules/SIPMacros.cmake @ 11643:9097e985303b

Revision 11643:9097e985303b, 5.7 KB checked in by janezd <janez.demsar@…>, 9 months ago (diff)

Added parentheses in prints in setup of orangeqt for compatibility with Python 3.0.

Line 
1# Macros for SIP
2# ~~~~~~~~~~~~~~
3# Copyright (c) 2007, Simon Edwards <simon@simonzone.com>
4# Redistribution and use is allowed according to the terms of the BSD license.
5# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
6#
7# SIP website: http://www.riverbankcomputing.co.uk/sip/index.php
8#
9# This file defines the following macros:
10#
11# ADD_SIP_PYTHON_MODULE (MODULE_NAME MODULE_SIP [library1, libaray2, ...])
12#     Specifies a SIP file to be built into a Python module and installed.
13#     MODULE_NAME is the name of Python module including any path name. (e.g.
14#     os.sys, Foo.bar etc). MODULE_SIP the path and filename of the .sip file
15#     to process and compile. libraryN are libraries that the Python module,
16#     which is typically a shared library, should be linked to. The built
17#     module will also be install into Python's site-packages directory.
18#
19# The behaviour of the ADD_SIP_PYTHON_MODULE macro can be controlled by a
20# number of variables:
21#
22# SIP_INCLUDES - List of directories which SIP will scan through when looking
23#     for included .sip files. (Corresponds to the -I option for SIP.)
24#
25# SIP_TAGS - List of tags to define when running SIP. (Corresponds to the -t
26#     option for SIP.)
27#
28# SIP_CONCAT_PARTS - An integer which defines the number of parts the C++ code
29#     of each module should be split into. Defaults to 8. (Corresponds to the
30#     -j option for SIP.)
31#
32# SIP_DISABLE_FEATURES - List of feature names which should be disabled
33#     running SIP. (Corresponds to the -x option for SIP.)
34#
35# SIP_EXTRA_OPTIONS - Extra command line options which should be passed on to
36#     SIP.
37#
38# SIP_EXTRA_SOURCES - Additional source files to compile into the library
39#
40# SIP_EXTRA_LINK_LIBRARIES - Additional libraries to link to
41#
42
43SET(SIP_INCLUDES)
44SET(SIP_TAGS)
45SET(SIP_CONCAT_PARTS 8)
46SET(SIP_DISABLE_FEATURES)
47SET(SIP_EXTRA_OPTIONS)
48SET(SIP_EXTRA_LINK_LIBRARIES)
49SET(SIP_EXTRA_SOURCES)
50
51MACRO(ADD_SIP_PYTHON_MODULE MODULE_NAME MODULE_SIP)
52
53    SET(EXTRA_LINK_LIBRARIES ${ARGN})
54
55    STRING(REPLACE "." "/" _x ${MODULE_NAME})
56    GET_FILENAME_COMPONENT(_parent_module_path ${_x}  PATH)
57    GET_FILENAME_COMPONENT(_child_module_name ${_x} NAME)
58
59    GET_FILENAME_COMPONENT(_module_path ${MODULE_SIP} PATH)
60
61    if(_module_path STREQUAL "")
62        set(CMAKE_CURRENT_SIP_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
63    else(_module_path STREQUAL "")
64        set(CMAKE_CURRENT_SIP_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${_module_path}")
65    endif(_module_path STREQUAL "")
66
67    GET_FILENAME_COMPONENT(_abs_module_sip ${MODULE_SIP} ABSOLUTE)
68
69    # We give this target a long logical target name.
70    # (This is to avoid having the library name clash with any already
71    # install library names. If that happens then cmake dependancy
72    # tracking get confused.)
73    STRING(REPLACE "." "_" _logical_name ${MODULE_NAME})
74    SET(_logical_name "python_module_${_logical_name}")
75
76    FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_SIP_OUTPUT_DIR})    # Output goes in this dir.
77
78    SET(_sip_includes)
79    FOREACH (_inc ${SIP_INCLUDES})
80        GET_FILENAME_COMPONENT(_abs_inc ${_inc} ABSOLUTE)
81        LIST(APPEND _sip_includes -I ${_abs_inc})
82    ENDFOREACH (_inc )
83
84    SET(_sip_tags)
85    FOREACH (_tag ${SIP_TAGS})
86        LIST(APPEND _sip_tags -t ${_tag})
87    ENDFOREACH (_tag)
88
89    SET(_sip_x)
90    FOREACH (_x ${SIP_DISABLE_FEATURES})
91        LIST(APPEND _sip_x -x ${_x})
92    ENDFOREACH (_x ${SIP_DISABLE_FEATURES})
93
94    SET(_message "-DMESSAGE=Generating CPP code for module ${MODULE_NAME}")
95    SET(_sip_output_files)
96    FOREACH(CONCAT_NUM RANGE 0 ${SIP_CONCAT_PARTS} )
97        IF( ${CONCAT_NUM} LESS ${SIP_CONCAT_PARTS} )
98            SET(_sip_output_files ${_sip_output_files} ${CMAKE_CURRENT_SIP_OUTPUT_DIR}/sip${_child_module_name}part${CONCAT_NUM}.cpp )
99        ENDIF( ${CONCAT_NUM} LESS ${SIP_CONCAT_PARTS} )
100    ENDFOREACH(CONCAT_NUM RANGE 0 ${SIP_CONCAT_PARTS} )
101
102    IF(NOT WIN32)
103        SET(TOUCH_COMMAND touch)
104    ELSE(NOT WIN32)
105        SET(TOUCH_COMMAND echo)
106        # instead of a touch command, give out the name and append to the files
107        # this is basically what the touch command does.
108        FOREACH(filename ${_sip_output_files})
109            FILE(APPEND filename "")
110        ENDFOREACH(filename ${_sip_output_files})
111    ENDIF(NOT WIN32)
112    ADD_CUSTOM_COMMAND(
113        OUTPUT ${_sip_output_files}
114        COMMAND ${CMAKE_COMMAND} -E echo ${message}
115        COMMAND ${TOUCH_COMMAND} ${_sip_output_files}
116        COMMAND ${SIP_EXECUTABLE} ${_sip_tags} ${_sip_x} ${SIP_EXTRA_OPTIONS} -j ${SIP_CONCAT_PARTS} -c ${CMAKE_CURRENT_SIP_OUTPUT_DIR} ${_sip_includes} ${_abs_module_sip}
117        DEPENDS ${_abs_module_sip} ${SIP_EXTRA_FILES_DEPEND}
118    )
119    # not sure if type MODULE could be uses anywhere, limit to cygwin for now
120    IF (CYGWIN)
121        ADD_LIBRARY(${_logical_name} MODULE ${SIP_EXTRA_SOURCES} ${_sip_output_files} )
122    ELSE (CYGWIN)
123        ADD_LIBRARY(${_logical_name} SHARED ${SIP_EXTRA_SOURCES} ${_sip_output_files} )
124    ENDIF (CYGWIN)
125
126#   IF (WIN32)
127#       SET_TARGET_PROPERTIES(${_logical_name} PROPERTIES SUFFIX ".pyd")
128#   ENDIF (WIN32)
129
130#   Use sysconfig to get the python module extension
131    execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('SO'))"
132                    RESULT_VARIABLE PYTHON_SOPY_PROCESS
133                    OUTPUT_VARIABLE PY_SO_SUFFIX
134                    OUTPUT_STRIP_TRAILING_WHITESPACE)
135    SET_TARGET_PROPERTIES(${_logical_name} PROPERTIES SUFFIX ${PY_SO_SUFFIX})
136    TARGET_LINK_LIBRARIES(${_logical_name} ${PYTHON_LIBRARY} ${SIP_EXTRA_LINK_LIBRARIES} ${EXTRA_LINK_LIBRARIES})
137    SET_TARGET_PROPERTIES(${_logical_name} PROPERTIES PREFIX "" OUTPUT_NAME ${_child_module_name})
138
139    INSTALL(TARGETS ${_logical_name} DESTINATION "${PYTHON_SITE_PACKAGES_INSTALL_DIR}/${_parent_module_path}")
140
141ENDMACRO(ADD_SIP_PYTHON_MODULE)
Note: See TracBrowser for help on using the repository browser.