aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Montel <montel@kde.org>2008-10-20 07:15:30 +0000
committerLaurent Montel <montel@kde.org>2008-10-20 07:15:30 +0000
commit12593fe0ab3dc6587ea965a8c287735200f9b084 (patch)
treee2d6eecc2a12123dd40977bf4d537f85a3f37fe3
parent61326e9dd53472ec764a1e4223838b00e3ffc870 (diff)
downloadextra-cmake-modules-12593fe0ab3dc6587ea965a8c287735200f9b084.tar.gz
extra-cmake-modules-12593fe0ab3dc6587ea965a8c287735200f9b084.tar.bz2
Move here (used by kdeedu/kdebase)
svn path=/trunk/KDE/kdelibs/; revision=873785
-rw-r--r--modules/FindSIP.cmake53
-rw-r--r--modules/FindSIP.py14
-rw-r--r--modules/SIPMacros.cmake117
3 files changed, 184 insertions, 0 deletions
diff --git a/modules/FindSIP.cmake b/modules/FindSIP.cmake
new file mode 100644
index 00000000..afe8b7b1
--- /dev/null
+++ b/modules/FindSIP.cmake
@@ -0,0 +1,53 @@
+# Find SIP
+# ~~~~~~~~
+# Copyright (c) 2007, Simon Edwards <simon@simonzone.com>
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+#
+# SIP website: http://www.riverbankcomputing.co.uk/sip/index.php
+#
+# Find the installed version of SIP. FindSIP should be called after Python
+# has been found.
+#
+# This file defines the following variables:
+#
+# SIP_VERSION - The version of SIP found expressed as a 6 digit hex number
+# suitable for comparision as a string.
+#
+# SIP_VERSION_STR - The version of SIP found as a human readable string.
+#
+# SIP_EXECUTABLE - Path and filename of the SIP command line executable.
+#
+# SIP_INCLUDE_DIR - Directory holding the SIP C++ header file.
+#
+# SIP_DEFAULT_SIP_DIR - Default directory where .sip files should be installed
+# into.
+
+IF(SIP_VERSION)
+ # Already in cache, be silent
+ SET(SIP_FOUND TRUE)
+ELSE(SIP_VERSION)
+
+ FIND_FILE(_find_sip_py FindSIP.py PATHS ${CMAKE_MODULE_PATH})
+
+ EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_sip_py} OUTPUT_VARIABLE sip_config)
+ IF(sip_config)
+ STRING(REGEX REPLACE "^sip_version:([^\n]+).*$" "\\1" SIP_VERSION ${sip_config})
+ STRING(REGEX REPLACE ".*\nsip_version_str:([^\n]+).*$" "\\1" SIP_VERSION_STR ${sip_config})
+ STRING(REGEX REPLACE ".*\nsip_bin:([^\n]+).*$" "\\1" SIP_EXECUTABLE ${sip_config})
+ STRING(REGEX REPLACE ".*\ndefault_sip_dir:([^\n]+).*$" "\\1" SIP_DEFAULT_SIP_DIR ${sip_config})
+ STRING(REGEX REPLACE ".*\nsip_inc_dir:([^\n]+).*$" "\\1" SIP_INCLUDE_DIR ${sip_config})
+ SET(SIP_FOUND TRUE)
+ ENDIF(sip_config)
+
+ IF(SIP_FOUND)
+ IF(NOT SIP_FIND_QUIETLY)
+ MESSAGE(STATUS "Found SIP version: ${SIP_VERSION_STR}")
+ ENDIF(NOT SIP_FIND_QUIETLY)
+ ELSE(SIP_FOUND)
+ IF(SIP_FIND_REQUIRED)
+ MESSAGE(FATAL_ERROR "Could not find SIP")
+ ENDIF(SIP_FIND_REQUIRED)
+ ENDIF(SIP_FOUND)
+
+ENDIF(SIP_VERSION)
diff --git a/modules/FindSIP.py b/modules/FindSIP.py
new file mode 100644
index 00000000..18db89b3
--- /dev/null
+++ b/modules/FindSIP.py
@@ -0,0 +1,14 @@
+# FindSIP.py
+#
+# Copyright (c) 2007, Simon Edwards <simon@simonzone.com>
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+import sys
+import sipconfig
+
+sipcfg = sipconfig.Configuration()
+print("sip_version:%06.0x" % sipcfg.sip_version)
+print("sip_version_str:%s" % sipcfg.sip_version_str)
+print("sip_bin:%s" % sipcfg.sip_bin)
+print("default_sip_dir:%s" % sipcfg.default_sip_dir)
+print("sip_inc_dir:%s" % sipcfg.sip_inc_dir)
diff --git a/modules/SIPMacros.cmake b/modules/SIPMacros.cmake
new file mode 100644
index 00000000..5cbb168d
--- /dev/null
+++ b/modules/SIPMacros.cmake
@@ -0,0 +1,117 @@
+# Macros for SIP
+# ~~~~~~~~~~~~~~
+# Copyright (c) 2007, Simon Edwards <simon@simonzone.com>
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+#
+# SIP website: http://www.riverbankcomputing.co.uk/sip/index.php
+#
+# This file defines the following macros:
+#
+# ADD_SIP_PYTHON_MODULE (MODULE_NAME MODULE_SIP [library1, libaray2, ...])
+# Specifies a SIP file to be built into a Python module and installed.
+# MODULE_NAME is the name of Python module including any path name. (e.g.
+# os.sys, Foo.bar etc). MODULE_SIP the path and filename of the .sip file
+# to process and compile. libraryN are libraries that the Python module,
+# which is typically a shared library, should be linked to. The built
+# module will also be install into Python's site-packages directory.
+#
+# The behaviour of the ADD_SIP_PYTHON_MODULE macro can be controlled by a
+# number of variables:
+#
+# SIP_INCLUDES - List of directories which SIP will scan through when looking
+# for included .sip files. (Corresponds to the -I option for SIP.)
+#
+# SIP_TAGS - List of tags to define when running SIP. (Corresponds to the -t
+# option for SIP.)
+#
+# SIP_CONCAT_PARTS - An integer which defines the number of parts the C++ code
+# of each module should be split into. Defaults to 8. (Corresponds to the
+# -j option for SIP.)
+#
+# SIP_DISABLE_FEATURES - List of feature names which should be disabled
+# running SIP. (Corresponds to the -x option for SIP.)
+#
+# SIP_EXTRA_OPTIONS - Extra command line options which should be passed on to
+# SIP.
+
+SET(SIP_INCLUDES)
+SET(SIP_TAGS)
+SET(SIP_CONCAT_PARTS 8)
+SET(SIP_DISABLE_FEATURES)
+SET(SIP_EXTRA_OPTIONS)
+
+MACRO(ADD_SIP_PYTHON_MODULE MODULE_NAME MODULE_SIP)
+
+ FIND_FILE(_print_status_cmake print_status.cmake PATHS ${CMAKE_MODULE_PATH})
+
+ # FIXME this removes -fvisibility=hidden from the compiler flags and has global affect.
+ STRING(REPLACE "-fvisibility=hidden" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
+ SET(EXTRA_LINK_LIBRARIES ${ARGN})
+
+ STRING(REPLACE "." "/" _x ${MODULE_NAME})
+ GET_FILENAME_COMPONENT(_parent_module_path ${_x} PATH)
+ GET_FILENAME_COMPONENT(_child_module_name ${_x} NAME)
+
+ GET_FILENAME_COMPONENT(_module_path ${MODULE_SIP} PATH)
+ GET_FILENAME_COMPONENT(_abs_module_sip ${MODULE_SIP} ABSOLUTE)
+
+ # We give this target a long logical target name.
+ # (This is to avoid having the library name clash with any already
+ # install library names. If that happens then cmake dependancy
+ # tracking get confused.)
+ STRING(REPLACE "." "_" _logical_name ${MODULE_NAME})
+ SET(_logical_name "python_module_${_logical_name}")
+
+ FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_module_path}) # Output goes in this dir.
+
+ SET(_sip_includes)
+ FOREACH (_inc ${SIP_INCLUDES})
+ GET_FILENAME_COMPONENT(_abs_inc ${_inc} ABSOLUTE)
+ LIST(APPEND _sip_includes -I ${_abs_inc})
+ ENDFOREACH (_inc )
+
+ SET(_sip_tags)
+ FOREACH (_tag ${SIP_TAGS})
+ LIST(APPEND _sip_tags -t ${_tag})
+ ENDFOREACH (_tag)
+
+ SET(_sip_x)
+ FOREACH (_x ${SIP_DISABLE_FEATURES})
+ LIST(APPEND _sip_x -x ${_x})
+ ENDFOREACH (_x ${SIP_DISABLE_FEATURES})
+
+ SET(_message "-DMESSAGE=Generating CPP code for module ${MODULE_NAME}")
+ SET(_sip_output_files)
+ FOREACH(CONCAT_NUM RANGE 0 ${SIP_CONCAT_PARTS} )
+ IF( ${CONCAT_NUM} LESS ${SIP_CONCAT_PARTS} )
+ SET(_sip_output_files ${_sip_output_files} ${CMAKE_CURRENT_BINARY_DIR}/${_module_path}/sip${_child_module_name}part${CONCAT_NUM}.cpp )
+ ENDIF( ${CONCAT_NUM} LESS ${SIP_CONCAT_PARTS} )
+ ENDFOREACH(CONCAT_NUM RANGE 0 ${SIP_CONCAT_PARTS} )
+
+ IF(NOT WIN32)
+ SET(TOUCH_COMMAND touch)
+ ELSE(NOT WIN32)
+ SET(TOUCH_COMMAND echo)
+ # instead of a touch command, give out the name and append to the files
+ # this is basically what the touch command does.
+ FOREACH(filename ${_sip_output_files})
+ FILE(APPEND filename "")
+ ENDFOREACH(filename ${_sip_output_files})
+ ENDIF(NOT WIN32)
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${_sip_output_files}
+ COMMAND ${CMAKE_COMMAND} ${_message} -P ${_print_status_cmake}
+ COMMAND ${TOUCH_COMMAND} ${_sip_output_files}
+ COMMAND ${SIP_EXECUTABLE} ${_sip_tags} ${_sip_x} ${SIP_EXTRA_OPTIONS} -j ${SIP_CONCAT_PARTS} -c ${CMAKE_CURRENT_BINARY_DIR}/${_module_path} ${_sip_includes} ${_abs_module_sip}
+ DEPENDS ${_abs_module_sip}
+ )
+
+ ADD_LIBRARY(${_logical_name} SHARED ${_sip_output_files} )
+ TARGET_LINK_LIBRARIES(${_logical_name} ${PYTHON_LIBRARY})
+ TARGET_LINK_LIBRARIES(${_logical_name} ${EXTRA_LINK_LIBRARIES})
+ SET_TARGET_PROPERTIES(${_logical_name} PROPERTIES PREFIX "" OUTPUT_NAME ${_child_module_name})
+
+ INSTALL(TARGETS ${_logical_name} DESTINATION "${PYTHON_SITE_PACKAGES_DIR}/${_parent_module_path}")
+
+ENDMACRO(ADD_SIP_PYTHON_MODULE)