CMakeLists.txt 7.47 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
#-----------------------------------------------------------------------------
Sylvain Thery's avatar
Sylvain Thery committed
2 3
# NOTE: The CMake files have been contributed to PythonQt and have not been tested with the current
# PythonQt version. They have not yet been updated to support Qt 5 and/or Python 3.
Pierre Kraemer's avatar
Pierre Kraemer committed
4
#
Sylvain Thery's avatar
Sylvain Thery committed
5 6
# If you are not a CMake expert, you should better use the provided qmake profiles.
#-----------------------------------------------------------------------------
Pierre Kraemer's avatar
Pierre Kraemer committed
7

Sylvain Thery's avatar
Sylvain Thery committed
8
cmake_minimum_required(VERSION 2.8.11)
Pierre Kraemer's avatar
Pierre Kraemer committed
9 10 11 12 13 14 15
#-----------------------------------------------------------------------------
project(PythonQt)
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Python libraries

16
find_package(PythonLibs 2.7 REQUIRED)
Pierre Kraemer's avatar
Pierre Kraemer committed
17
include_directories("${PYTHON_INCLUDE_DIR}")
Sylvain Thery's avatar
Sylvain Thery committed
18
add_definitions("-DPYTHONQT_USE_RELEASE_PYTHON_FALLBACK")
Sylvain Thery's avatar
Sylvain Thery committed
19

Pierre Kraemer's avatar
Pierre Kraemer committed
20 21 22
#-----------------------------------------------------------------------------
# Build options

Sylvain Thery's avatar
Sylvain Thery committed
23 24 25 26
option(PythonQt_Wrap_QtAll "Make all Qt components available in python" OFF)

set(qtlibs core gui network opengl sql svg uitools webkit xml xmlpatterns)
foreach(qtlib ${qtlibs})
Pierre Kraemer's avatar
Pierre Kraemer committed
27 28 29
  OPTION(PythonQt_Wrap_Qt${qtlib} "Make all of Qt${qtlib} available in python" OFF)
endforeach()

Sylvain Thery's avatar
Sylvain Thery committed
30 31 32 33 34 35 36 37 38 39 40
# Force option if it applies
if(PythonQt_Wrap_QtAll)
  list(REMOVE_ITEM qtlibs xmlpatterns) # xmlpatterns wrapper does *NOT* build at all :(  
  foreach(qtlib ${qtlibs})
    if(NOT ${PythonQt_Wrap_Qt${qtlib}})
      set(PythonQt_Wrap_Qt${qtlib} ON CACHE BOOL "Make all of Qt${qtlib} available in python" FORCE)
      message(STATUS "Enabling [PythonQt_Wrap_Qt${qtlib}] because of [PythonQt_Wrap_QtAll] evaluates to True")
    endif()
  endforeach()
endif()

Pierre Kraemer's avatar
Pierre Kraemer committed
41 42 43 44 45 46 47
option(PythonQt_DEBUG "Enable/Disable PythonQt debug output" OFF)
if(PythonQt_DEBUG)
  add_definitions(-DPYTHONQT_DEBUG)
else()
  remove_definitions(-DPYTHONQT_DEBUG)
endif()

48 49 50 51
if(WIN32)
	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
endif() 

Pierre Kraemer's avatar
Pierre Kraemer committed
52 53 54
#-----------------------------------------------------------------------------
# Setup Qt

Sylvain Thery's avatar
Sylvain Thery committed
55 56 57 58 59 60 61 62 63 64
if("${QT_VERSION_MAJOR}" STREQUAL "5")
    # NEW
    if ("${QT_VERSION_MINOR}" STREQUAL "4")
        set(generated_cpp_suffix "_54")
    else()
        if ("${QT_VERSION_MINOR}" STREQUAL "3")
            set(generated_cpp_suffix "_53")
        else()
            set(generated_cpp_suffix "_50")
        endif()
Pierre Kraemer's avatar
Pierre Kraemer committed
65 66
    endif()
else()
Sylvain Thery's avatar
Sylvain Thery committed
67 68 69 70 71
    # OLD
    set(generated_cpp_suffix "_${QT_VERSION_MAJOR}${QT_VERSION_MINOR}")
    if("${generated_cpp_suffix}" STREQUAL "_46")
            set(generated_cpp_suffix "_47") # Also use 4.7 wrappers for 4.6.x version
    endif()
Pierre Kraemer's avatar
Pierre Kraemer committed
72 73 74
endif()

set(sources
Sylvain Thery's avatar
Sylvain Thery committed
75
    src/PythonQtBoolResult.cpp
Pierre Kraemer's avatar
Pierre Kraemer committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    src/PythonQtClassInfo.cpp
    src/PythonQtClassWrapper.cpp
    src/PythonQtConversion.cpp
    src/PythonQt.cpp
    src/PythonQtImporter.cpp
    src/PythonQtInstanceWrapper.cpp
    src/PythonQtMethodInfo.cpp
    src/PythonQtMisc.cpp
    src/PythonQtObjectPtr.cpp
    src/PythonQtQFileImporter.cpp
    src/PythonQtSignalReceiver.cpp
    src/PythonQtSlot.cpp
    src/PythonQtSignal.cpp
    src/PythonQtStdDecorators.cpp
    src/PythonQtStdIn.cpp
    src/PythonQtStdOut.cpp
    src/gui/PythonQtScriptingConsole.cpp

Sylvain Thery's avatar
Sylvain Thery committed
94 95 96 97
    generated_cpp${generated_cpp_suffix}/com_trolltech_qt_core_builtin/com_trolltech_qt_core_builtin0.cpp
    generated_cpp${generated_cpp_suffix}/com_trolltech_qt_core_builtin/com_trolltech_qt_core_builtin_init.cpp
    generated_cpp${generated_cpp_suffix}/com_trolltech_qt_gui_builtin/com_trolltech_qt_gui_builtin0.cpp
    generated_cpp${generated_cpp_suffix}/com_trolltech_qt_gui_builtin/com_trolltech_qt_gui_builtin_init.cpp
Pierre Kraemer's avatar
Pierre Kraemer committed
98 99 100 101 102 103
)

#-----------------------------------------------------------------------------
# List headers.  This is list is used for the install command.

set(headers
Sylvain Thery's avatar
Sylvain Thery committed
104
    src/PythonQtBoolResult.h
Pierre Kraemer's avatar
Pierre Kraemer committed
105 106 107 108 109 110 111 112 113 114 115 116
    src/PythonQtClassInfo.h
    src/PythonQtClassWrapper.h
    src/PythonQtConversion.h
    src/PythonQtCppWrapperFactory.h
    src/PythonQtDoc.h
    src/PythonQt.h
    src/PythonQtImporter.h
    src/PythonQtImportFileInterface.h
    src/PythonQtInstanceWrapper.h
    src/PythonQtMethodInfo.h
    src/PythonQtMisc.h
    src/PythonQtObjectPtr.h
Sylvain Thery's avatar
Sylvain Thery committed
117
    src/PythonQtPythonInclude.h
Pierre Kraemer's avatar
Pierre Kraemer committed
118
    src/PythonQtQFileImporter.h
Sylvain Thery's avatar
Sylvain Thery committed
119
    src/PythonQtSignal.h
Pierre Kraemer's avatar
Pierre Kraemer committed
120 121 122 123 124 125
    src/PythonQtSignalReceiver.h
    src/PythonQtSlot.h
    src/PythonQtStdDecorators.h
    src/PythonQtStdIn.h
    src/PythonQtStdOut.h
    src/PythonQtSystem.h
Sylvain Thery's avatar
Sylvain Thery committed
126
    src/PythonQtUtils.h
Pierre Kraemer's avatar
Pierre Kraemer committed
127 128 129 130 131 132 133 134 135 136 137 138
    src/PythonQtVariants.h
)

#-----------------------------------------------------------------------------
# Headers that should run through moc

set(moc_sources
    src/PythonQt.h
    src/PythonQtSignalReceiver.h
    src/PythonQtStdDecorators.h
    src/gui/PythonQtScriptingConsole.h

Sylvain Thery's avatar
Sylvain Thery committed
139 140
    generated_cpp${generated_cpp_suffix}/com_trolltech_qt_core_builtin/com_trolltech_qt_core_builtin0.h
    generated_cpp${generated_cpp_suffix}/com_trolltech_qt_gui_builtin/com_trolltech_qt_gui_builtin0.h
Pierre Kraemer's avatar
Pierre Kraemer committed
141 142 143 144
)

#-----------------------------------------------------------------------------
# Add extra sources
Sylvain Thery's avatar
Sylvain Thery committed
145
#foreach(qtlib core gui network opengl sql svg uitools webkit xml xmlpatterns)
Pierre Kraemer's avatar
Pierre Kraemer committed
146
  
Sylvain Thery's avatar
Sylvain Thery committed
147
#  if (${PythonQt_Wrap_Qt${qtlib}})
Pierre Kraemer's avatar
Pierre Kraemer committed
148
    
Sylvain Thery's avatar
Sylvain Thery committed
149
#    ADD_DEFINITIONS(-DPYTHONQT_WRAP_Qt${qtlib})
Pierre Kraemer's avatar
Pierre Kraemer committed
150
    
Sylvain Thery's avatar
Sylvain Thery committed
151
#    set(file_prefix generated_cpp${generated_cpp_suffix}/com_trolltech_qt_${qtlib}/com_trolltech_qt_${qtlib})
Pierre Kraemer's avatar
Pierre Kraemer committed
152
    
Sylvain Thery's avatar
Sylvain Thery committed
153
#    foreach(index RANGE 0 11)
Pierre Kraemer's avatar
Pierre Kraemer committed
154
    
Sylvain Thery's avatar
Sylvain Thery committed
155 156 157 158
#      # Source files
#      if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file_prefix}${index}.cpp)
#        list(APPEND sources ${file_prefix}${index}.cpp)
#      endif()
Pierre Kraemer's avatar
Pierre Kraemer committed
159
      
Sylvain Thery's avatar
Sylvain Thery committed
160 161 162 163
#      # Headers that should run through moc
#      if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file_prefix}${index}.h)
#        list(APPEND moc_sources ${file_prefix}${index}.h)
#      endif()
Pierre Kraemer's avatar
Pierre Kraemer committed
164
      
Sylvain Thery's avatar
Sylvain Thery committed
165
#    endforeach()
Pierre Kraemer's avatar
Pierre Kraemer committed
166
    
Sylvain Thery's avatar
Sylvain Thery committed
167
#    list(APPEND sources ${file_prefix}_init.cpp)
Pierre Kraemer's avatar
Pierre Kraemer committed
168

Sylvain Thery's avatar
Sylvain Thery committed
169 170
#  endif()
#endforeach()
Pierre Kraemer's avatar
Pierre Kraemer committed
171 172 173 174 175 176 177 178 179 180 181

#-----------------------------------------------------------------------------
# UI files
set(ui_sources )

#-----------------------------------------------------------------------------
# Resources
set(qrc_sources )

#-----------------------------------------------------------------------------
# Do wrapping
Sylvain Thery's avatar
Sylvain Thery committed
182 183 184

#qt_wrap_ui(gen_ui_sources ${ui_sources})
#qt_add_resources(gen_qrc_sources ${qrc_sources})
Pierre Kraemer's avatar
Pierre Kraemer committed
185 186 187 188

#-----------------------------------------------------------------------------
# Build the library
include_directories(
Sylvain Thery's avatar
Sylvain Thery committed
189 190 191 192 193 194 195
    ${CMAKE_CURRENT_SOURCE_DIR}/src
    ${CMAKE_CURRENT_SOURCE_DIR}
)

qt_wrap_cpp(gen_moc_sources ${moc_sources})

add_library(${PROJECT_NAME} SHARED
Pierre Kraemer's avatar
Pierre Kraemer committed
196 197 198
            ${sources}
            ${gen_moc_sources}
  )
Sylvain Thery's avatar
Sylvain Thery committed
199 200 201 202 203 204 205 206 207

target_compile_definitions(${PROJECT_NAME} PRIVATE PYTHONQT_EXPORTS)

    qt_use_modules(${PROJECT_NAME} Core Gui)

target_link_libraries(${PROJECT_NAME}
              ${PYTHON_LIBRARIES}
  )
set_target_properties(${PROJECT_NAME} PROPERTIES DEFINE_SYMBOL PYTHONQT_EXPORTS)
Pierre Kraemer's avatar
Pierre Kraemer committed
208 209 210 211 212

#
# That should solve linkage error on Mac when the project is used in a superbuild setup
# See http://blog.onesadcookie.com/2008/01/installname-magic.html
#
Sylvain Thery's avatar
Sylvain Thery committed
213
set_target_properties(${PROJECT_NAME}  PROPERTIES
Pierre Kraemer's avatar
Pierre Kraemer committed
214 215 216
  INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
  )

Sylvain Thery's avatar
Sylvain Thery committed
217

Pierre Kraemer's avatar
Pierre Kraemer committed
218 219 220 221

#-----------------------------------------------------------------------------
# Install library (on windows, put the dll in 'bin' and the archive in 'lib')

Sylvain Thery's avatar
Sylvain Thery committed
222 223 224 225 226
install(TARGETS PythonQt
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib)
install(FILES ${headers} DESTINATION include/PythonQt)