~townsend/compiz/fix-auto-vp-switch-0.9.10

« back to all changes in this revision

Viewing changes to compizconfig/compizconfig-python/CMakeLists.txt

  • Committer: Sam Spilsbury
  • Date: 2012-10-16 13:53:20 UTC
  • mto: This revision was merged to the branch mainline in revision 3434.
  • Revision ID: sam.spilsbury@canonical.com-20121016135320-3zb8wy8u16eayb7m
Clean up the CMake code around the python modules and uninstalling
 - It isn't possible to build python extensions using distutils that
   link to things that we are building, because CMake provides no
   means for a custom command to depend on a library. Build them
   using CMake directly instead
 - Clean up the tests: the tests depended on having a working opengl
   and core plugin xml file and were also sensitive to xml data. Make
   a mock.xml and use that instead
 - Require ini for the compizconfig-python tests. They won't run without it
 - Fix the uninstall scripts. We were clobbering the uninstall target
   with the python uninstall targets, that is just plain wrong. Created
   a new cmake function to append custom uninstall scripts to the global
   uninstall script

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
find_package (CompizConfig REQUIRED)
2
 
include (LibCompizConfigCommon)
3
 
 
4
1
# Hack
5
2
set (CMAKE_PROJECT_NAME compizconfig-python)
6
3
 
7
 
add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/compizconfig_wrapper.c
8
 
                    COMMAND echo \"int main (void) { return 0\; }\" >> ${CMAKE_CURRENT_BINARY_DIR}/compizconfig_wrapper.c
9
 
                    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
10
 
 
11
4
# Get arch
12
5
execute_process (COMMAND uname -p OUTPUT_VARIABLE PROC_ARCH)
13
6
 
15
8
execute_process (COMMAND python -c "import sys; print str (sys.version_info[0]) + '.' + str (sys.version_info[1])"
16
9
                 OUTPUT_VARIABLE PY_VERSION)
17
10
 
 
11
find_package (PythonLibs)
 
12
 
 
13
# This is a workaround for a broken FindPythonLibs always finding the
 
14
# wrong library version because PYTHON_LIBRARY is in the cache and
 
15
# can't be overwritten
 
16
string (REGEX REPLACE "^([0-9]+\\.[0-9]+).*" "\\1" PYTHON_CURRENT_VERSION ${PY_VERSION})
 
17
string (REPLACE "." "" PYTHON_CURRENT_VERSION_NO_DOTS ${PYTHON_CURRENT_VERSION})
 
18
find_library (PYTHON_LIBRARY_LOCAL
 
19
              NAMES python${PYTHON_CURRENT_VERSION_NO_DOTS} python${PYTHON_CURRENT_VERSION}
 
20
              PATH_SUFFIXES python${PYTHON_CURRENT_VERSION}/config)
 
21
 
 
22
set (COMPIZCONFIG_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/compizconfig/libcompizconfig/include)
 
23
 
18
24
string (REPLACE "\n" "" PROC_ARCH ${PROC_ARCH})
19
25
string (REPLACE "\n" "" PY_VERSION ${PY_VERSION})
20
26
 
21
27
set (PY_BUILD_DIR lib.linux-${PROC_ARCH}-${PY_VERSION})
22
28
set (PY_SCRIPTS_DIR scripts-${PY_VERSION})
23
 
 
24
29
set (PY_COMPIZCONFIG_SRC ${CMAKE_CURRENT_BINARY_DIR}/compizconfig.c)
 
30
set (PY_COMPIZCONFIG_PYREX ${PY_COMPIZCONFIG_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/src/compizconfig.pyx)
25
31
 
26
32
add_custom_command (OUTPUT ${PY_COMPIZCONFIG_SRC}
27
 
                    COMMAND pyrexc -o ${PY_COMPIZCONFIG_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/src/compizconfig.pyx
28
 
                    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
29
 
 
30
 
set (PY_COMPIZCONFIG_LIB  ${CMAKE_CURRENT_BINARY_DIR}/build/${PY_BUILD_DIR}/compizconfig.so)
 
33
                    COMMAND pyrexc -o ${PY_COMPIZCONFIG_PYREX}
 
34
                    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
 
35
                    DEPENDS ${PY_COMPIZCONFIG_PYREX})
31
36
 
32
37
file (READ ${CMAKE_SOURCE_DIR}/VERSION COMPIZ_RELEASE_VERSION LIMIT 12 OFFSET 0)
33
38
string (STRIP ${COMPIZ_RELEASE_VERSION} COMPIZ_RELEASE_VERSION)
36
41
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/compizconfig-python.pc.in
37
42
                ${CMAKE_CURRENT_BINARY_DIR}/compizconfig-python.pc)
38
43
 
39
 
add_custom_command (OUTPUT ${PY_COMPIZCONFIG_LIB}
40
 
                    COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/setup.py build --build-base=${CMAKE_CURRENT_BINARY_DIR}/build --version=${VERSION}
41
 
                    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
42
 
                    DEPENDS ${PY_COMPIZCONFIG_SRC} ${PY_COMPIZCONFIG_VERSION} compizconfig
43
 
                    COMMENT "Generating Python Bytecode")
44
 
 
45
 
add_custom_target (compizconfig_python_module ALL DEPENDS
46
 
                   ${PY_COMPIZCONFIG_LIB})
47
 
 
48
 
add_custom_target (uninstall
49
 
                   COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/setup.py uninstall --prefix=${CMAKE_INSTALL_PREFIX}
50
 
                   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
51
 
                   COMMENT "Uninstalling Python Files")
 
44
include_directories (${PYTHON_INCLUDE_DIRS}
 
45
                     ${COMPIZCONFIG_INCLUDE_DIRS})
 
46
 
 
47
# pyrex generates code that does type-punning, this trips
 
48
# up -Werror
 
49
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-strict-aliasing")
 
50
 
 
51
# We need to remove the "lib"
 
52
set (CMAKE_SHARED_LIBRARY_PREFIX "")
 
53
 
 
54
# We must build the python module using CMake instead of distutils.
 
55
#
 
56
# The only way in which the python module can be built using distutils
 
57
# is by using add_custom_command to "generate" it into existence.
 
58
# Unfortunately this has drawbacks. Namely, it is not possible for
 
59
# add_custom_command to depend on library targets. Because of that, there's
 
60
# no way that we can guaruntee that libcompizconfig.so will be linked
 
61
# before compizconfig.so (which is required). The best that we can do
 
62
# there is to use add_custom_target, and make that target depend on the
 
63
# file, 
 
64
add_library (compizconfig_python_module SHARED
 
65
             ${PY_COMPIZCONFIG_SRC})
 
66
 
 
67
set_target_properties (compizconfig_python_module
 
68
                       PROPERTIES
 
69
                       OUTPUT_NAME
 
70
                       compizconfig)
 
71
 
 
72
target_link_libraries (compizconfig_python_module
 
73
                       ${PYTHON_LIBRARY_LOCAL}
 
74
                       compizconfig)
 
75
 
 
76
set (UNINSTALL_COMMAND "python ${CMAKE_CURRENT_SOURCE_DIR}/setup.py uninstall --prefix=${CMAKE_INSTALL_PREFIX} --version=${VERSION}")
 
77
 
 
78
compiz_add_code_to_uninstall_target (${UNINSTALL_COMMAND} ${CMAKE_CURRENT_BINARY_DIR})
52
79
 
53
80
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/compizconfig-python.pc
54
81
         DESTINATION ${libdir}/pkgconfig)
55
82
 
 
83
# This is probably not very portable, but we can't install using distutils
 
84
# as we cannot build with it safely
 
85
set (PYTHON_MODULE_DIR ${libdir}/python${PY_VERSION}/site-packages)
 
86
 
 
87
install (TARGETS compizconfig_python_module
 
88
         DESTINATION ${PYTHON_MODULE_DIR})
 
89
 
56
90
install (CODE
57
91
         "message (\"Installing python files\")
58
92
          execute_process (COMMAND cmake -DSETUP=${CMAKE_CURRENT_SOURCE_DIR}/setup.py -DPREFIX=${CMAKE_INSTALL_PREFIX} -DWDIR=${CMAKE_CURRENT_BINARY_DIR} -DVERSION=${VERSION} -P ${compiz_SOURCE_DIR}/compizconfig/cmake/exec_setup_py_with_destdir.cmake)")
67
101
 
68
102
        if (PYTHON_EXECUTABLE AND
69
103
            BASH_EXECUTABLE)
 
104
                set (MOCK_XML_SRC ${CMAKE_CURRENT_SOURCE_DIR}/tests/mock.xml)
 
105
                set (MOCK_XML_FILE ${CMAKE_CURRENT_BINARY_DIR}/mock.xml)
 
106
 
 
107
                add_custom_command (OUTPUT ${MOCK_XML_FILE}
 
108
                                    COMMAND cp ${MOCK_XML_SRC}
 
109
                                            ${MOCK_XML_FILE}
 
110
                                    COMMENT "Copying mock.xml file into testing directory"
 
111
                                    DEPENDS ${MOCK_XML_SRC})
 
112
 
 
113
                add_custom_target (compizconfig_python_test_mock_xml_file ALL DEPENDS
 
114
                                   ${MOCK_XML_FILE})
 
115
 
 
116
                # For testing purposes we need the ini backend
 
117
                add_dependencies (compizconfig_python_module ini compizconfig_python_test_mock_xml_file)
 
118
 
70
119
                foreach (PYTHON_TEST_FILE ${PYTHON_TESTS})
71
120
                        get_filename_component (PYTHON_TEST ${PYTHON_TEST_FILE} NAME_WE)
72
121
                        message (STATUS "Adding test " ${PYTHON_TEST})