]> git.sesse.net Git - vlc/blob - bindings/phonon/CMakeLists.txt
python-ctypes: accomodate both old and new message exception getter
[vlc] / bindings / phonon / CMakeLists.txt
1 project(Phonon)
2
3 cmake_minimum_required(VERSION 2.6.2 FATAL_ERROR)
4
5 # CMP0002: we have multiple targets with the same name for the unit tests
6 cmake_policy(SET CMP0002 OLD)
7
8 # enable unit tests
9 option(PHONON_BUILD_TESTS "Build the tests")
10 option(PHONON_BUILD_EXAMPLES "Build the examples")
11
12 if (PHONON_BUILD_TESTS)
13     enable_testing()
14 endif (PHONON_BUILD_TESTS)
15
16 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
17
18 include(PhononMacros)
19
20 include(MacroLogFeature)
21 include(MacroOptionalFindPackage)
22
23 set(QT_MIN_VERSION 4.4.0)
24 find_package(Qt4 REQUIRED)
25 if (NOT QT_QTDBUS_FOUND)
26    message(STATUS "Warning: Phonon won't be compiled with DBus support.")
27 endif(NOT QT_QTDBUS_FOUND)
28
29 find_package(Automoc4 REQUIRED)
30 include (CheckCXXCompilerFlag)
31 include (MacroEnsureVersion)
32
33 if (NOT AUTOMOC4_VERSION)
34    set(AUTOMOC4_VERSION "0.9.83")
35 endif (NOT AUTOMOC4_VERSION)
36 macro_ensure_version("0.9.86" "${AUTOMOC4_VERSION}" _automoc4_version_ok)
37 if (NOT _automoc4_version_ok)
38    message(FATAL_ERROR "Your version of automoc4 is too old. You have ${AUTOMOC4_VERSION}, you need at least 0.9.86")
39 endif (NOT _automoc4_version_ok)
40
41 if (CMAKE_COMPILER_IS_GNUCXX)
42    set (KDE4_ENABLE_EXCEPTIONS -fexceptions)
43    # Select flags.
44    set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
45    set(CMAKE_CXX_FLAGS_RELEASE        "-O2 -DNDEBUG -DQT_NO_DEBUG")
46    set(CMAKE_CXX_FLAGS_DEBUG          "-g -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline")
47    set(CMAKE_CXX_FLAGS_DEBUGFULL      "-g3 -fno-inline")
48    set(CMAKE_CXX_FLAGS_PROFILE        "-g3 -fno-inline -ftest-coverage -fprofile-arcs")
49    set(CMAKE_C_FLAGS_RELWITHDEBINFO   "-O2 -g")
50    set(CMAKE_C_FLAGS_RELEASE          "-O2 -DNDEBUG -DQT_NO_DEBUG")
51    set(CMAKE_C_FLAGS_DEBUG            "-g -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline")
52    set(CMAKE_C_FLAGS_DEBUGFULL        "-g3 -fno-inline")
53    set(CMAKE_C_FLAGS_PROFILE          "-g3 -fno-inline -ftest-coverage -fprofile-arcs")
54
55    if (CMAKE_SYSTEM_NAME MATCHES Linux)
56      set ( CMAKE_C_FLAGS     "${CMAKE_C_FLAGS} -Wno-long-long -std=iso9899:1990 -Wundef -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-common")
57      set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-exceptions -fno-check-new -fno-common")
58      add_definitions (-D_BSD_SOURCE)
59    endif (CMAKE_SYSTEM_NAME MATCHES Linux)
60
61    # gcc under Windows
62    if (MINGW)
63       set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--export-all-symbols -Wl,--disable-auto-import")
64       set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--export-all-symbols -Wl,--disable-auto-import")
65
66       # we always link against the release version of QT with mingw
67       # (even for debug builds). So we need to define QT_NO_DEBUG
68       # or else QPluginLoader rejects plugins because it thinks
69       # they're built against the wrong QT.
70       add_definitions(-DQT_NO_DEBUG)
71    endif (MINGW)
72
73    check_cxx_compiler_flag(-fPIE HAVE_FPIE_SUPPORT)
74    if(KDE4_ENABLE_FPIE)
75        if(HAVE_FPIE_SUPPORT)
76         set (KDE4_CXX_FPIE_FLAGS "-fPIE")
77         set (KDE4_PIE_LDFLAGS "-pie")
78        else(HAVE_FPIE_SUPPORT)
79         message(STATUS "Your compiler doesn't support PIE flag")
80        endif(HAVE_FPIE_SUPPORT)
81    endif(KDE4_ENABLE_FPIE)
82
83    check_cxx_compiler_flag(-Woverloaded-virtual __KDE_HAVE_W_OVERLOADED_VIRTUAL)
84    if(__KDE_HAVE_W_OVERLOADED_VIRTUAL)
85        set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual")
86    endif(__KDE_HAVE_W_OVERLOADED_VIRTUAL)
87
88    # visibility support
89    check_cxx_compiler_flag(-fvisibility=hidden __KDE_HAVE_GCC_VISIBILITY)
90    set( __KDE_HAVE_GCC_VISIBILITY ${__KDE_HAVE_GCC_VISIBILITY} CACHE BOOL "GCC support for hidden visibility")
91
92    # get the gcc version
93    exec_program(${CMAKE_C_COMPILER} ARGS --version OUTPUT_VARIABLE _gcc_version_info)
94
95    string (REGEX MATCH "[345]\\.[0-9]\\.[0-9]" _gcc_version "${_gcc_version_info}")
96    # gcc on mac just reports: "gcc (GCC) 3.3 20030304 ..." without the patch level, handle this here:
97    if (NOT _gcc_version)
98       string (REGEX REPLACE ".*\\(GCC\\).* ([34]\\.[0-9]) .*" "\\1.0" _gcc_version "${_gcc_version_info}")
99    endif (NOT _gcc_version)
100
101    macro_ensure_version("4.1.0" "${_gcc_version}" GCC_IS_NEWER_THAN_4_1)
102    macro_ensure_version("4.2.0" "${_gcc_version}" GCC_IS_NEWER_THAN_4_2)
103    macro_ensure_version("4.3.0" "${_gcc_version}" GCC_IS_NEWER_THAN_4_3)
104
105    # save a little by making local statics not threadsafe
106    # ### do not enable it for older compilers, see
107    # ### http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31806
108    if (GCC_IS_NEWER_THAN_4_3)
109        set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-threadsafe-statics")
110    endif (GCC_IS_NEWER_THAN_4_3)
111
112    set(_GCC_COMPILED_WITH_BAD_ALLOCATOR FALSE)
113    if (GCC_IS_NEWER_THAN_4_1)
114       exec_program(${CMAKE_C_COMPILER} ARGS -v OUTPUT_VARIABLE _gcc_alloc_info)
115       string(REGEX MATCH "(--enable-libstdcxx-allocator=mt)" _GCC_COMPILED_WITH_BAD_ALLOCATOR "${_gcc_alloc_info}")
116    endif (GCC_IS_NEWER_THAN_4_1)
117
118    if (__KDE_HAVE_GCC_VISIBILITY AND GCC_IS_NEWER_THAN_4_1 AND NOT _GCC_COMPILED_WITH_BAD_ALLOCATOR)
119       set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
120       set (KDE4_C_FLAGS "-fvisibility=hidden")
121       # check that Qt defines Q_DECL_EXPORT as __attribute__ ((visibility("default")))
122       # if it doesn't and KDE compiles with hidden default visibiltiy plugins will break
123       set(_source "#include <QtCore/QtGlobal>\n int main()\n {\n #ifdef QT_VISIBILITY_AVAILABLE \n return 0;\n #else \n return 1; \n #endif \n }\n")
124       set(_source_file ${CMAKE_BINARY_DIR}/CMakeTmp/check_qt_visibility.cpp)
125       file(WRITE "${_source_file}" "${_source}")
126       set(_include_dirs "-DINCLUDE_DIRECTORIES:STRING=${QT_INCLUDES}")
127
128       try_run(_run_result _compile_result ${CMAKE_BINARY_DIR} ${_source_file} CMAKE_FLAGS "${_include_dirs}")
129
130       if(NOT _compile_result)
131          message(FATAL_ERROR "Could not compile simple test program:\n ${_source}")
132       endif(NOT _compile_result)
133       if(_run_result)
134          message(FATAL_ERROR "Qt compiled without support for -fvisibility=hidden. This will break plugins and linking of some applications. Please fix your Qt installation.")
135       endif(_run_result)
136
137       if (GCC_IS_NEWER_THAN_4_2)
138           set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden")
139       endif (GCC_IS_NEWER_THAN_4_2)
140    else (__KDE_HAVE_GCC_VISIBILITY AND GCC_IS_NEWER_THAN_4_1 AND NOT _GCC_COMPILED_WITH_BAD_ALLOCATOR)
141       set (__KDE_HAVE_GCC_VISIBILITY 0)
142    endif (__KDE_HAVE_GCC_VISIBILITY AND GCC_IS_NEWER_THAN_4_1 AND NOT _GCC_COMPILED_WITH_BAD_ALLOCATOR)
143
144 endif (CMAKE_COMPILER_IS_GNUCXX)
145
146 set(CMAKE_INCLUDE_CURRENT_DIR ON)
147 set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
148 set(CMAKE_COLOR_MAKEFILE ON)
149
150 set(PHONON_LIB_MAJOR_VERSION "4")
151 set(PHONON_LIB_MINOR_VERSION "3")
152 set(PHONON_LIB_PATCH_VERSION "50")
153 set(PHONON_LIB_VERSION "${PHONON_LIB_MAJOR_VERSION}.4.0")
154 set(PHONON_LIB_SOVERSION ${PHONON_LIB_MAJOR_VERSION})
155
156 add_definitions(${QT_DEFINITIONS})
157 remove_definitions(-DQT3_SUPPORT_WARNINGS -DQT3_SUPPORT)
158 if(MSVC)
159   add_definitions( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS )
160 endif(MSVC)
161
162 # for including config.h and for includes like <kparts/foo.h>
163 include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/includes ${CMAKE_CURRENT_SOURCE_DIR}/phonon ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/phonon)
164
165 macro(_SET_FANCY _var _value _comment)
166    if (KDESupport_SOURCE_DIR)
167       # when building inside kdesupport other subprojects write crap into our variables
168       set(${_var} "${_value}")
169    else (KDESupport_SOURCE_DIR)
170       if (NOT DEFINED ${_var})
171          set(${_var} "${_value}")
172       else (NOT DEFINED ${_var})
173          set(${_var} "${${_var}}" CACHE PATH "${_comment}")
174       endif (NOT DEFINED ${_var})
175    endif (KDESupport_SOURCE_DIR)
176 endmacro(_SET_FANCY)
177
178 set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" )
179
180 _set_fancy(EXEC_INSTALL_PREFIX         "${CMAKE_INSTALL_PREFIX}"                   "Base directory for executables and libraries")
181 _set_fancy(SHARE_INSTALL_PREFIX        "${CMAKE_INSTALL_PREFIX}/share"             "Base directory for files which go to share/")
182 _set_fancy(BIN_INSTALL_DIR             "${EXEC_INSTALL_PREFIX}/bin"                "The install dir for executables (default ${EXEC_INSTALL_PREFIX}/bin)")
183 _set_fancy(LIB_INSTALL_DIR             "${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX}"   "The subdirectory relative to the install prefix where libraries will be installed (default is ${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX})")
184 _set_fancy(INCLUDE_INSTALL_DIR         "${CMAKE_INSTALL_PREFIX}/include"           "The subdirectory to the header prefix")
185 _set_fancy(PLUGIN_INSTALL_DIR          "${LIB_INSTALL_DIR}/kde4"                   "The subdirectory relative to the install prefix where plugins will be installed (default is ${LIB_INSTALL_DIR}/kde4)")
186 _set_fancy(ICON_INSTALL_DIR            "${SHARE_INSTALL_PREFIX}/icons"             "The icon install dir (default ${SHARE_INSTALL_PREFIX}/share/icons/)")
187 _set_fancy(SERVICES_INSTALL_DIR        "${SHARE_INSTALL_PREFIX}/kde4/services"     "The install dir for service (desktop, protocol, ...) files")
188 _set_fancy(DBUS_INTERFACES_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/dbus-1/interfaces" "The dbus interfaces install dir (default: ${SHARE_INSTALL_PREFIX}/dbus-1/interfaces)")
189 _set_fancy(DBUS_SERVICES_INSTALL_DIR   "${SHARE_INSTALL_PREFIX}/dbus-1/services"   "The dbus services install dir (default: ${SHARE_INSTALL_PREFIX}/dbus-1/services)")
190
191 set(INSTALL_TARGETS_DEFAULT_ARGS  RUNTIME DESTINATION "${BIN_INSTALL_DIR}"
192                                   LIBRARY DESTINATION "${LIB_INSTALL_DIR}"
193                                   ARCHIVE DESTINATION "${LIB_INSTALL_DIR}" COMPONENT Devel )
194
195 # on the Mac support an extra install directory for application bundles
196 if(APPLE)
197    set(INSTALL_TARGETS_DEFAULT_ARGS  ${INSTALL_TARGETS_DEFAULT_ARGS}
198                                      BUNDLE DESTINATION "${BUNDLE_INSTALL_DIR}" )
199         set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS   "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS}   -flat_namespace -undefined dynamic_lookup")
200         set(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS "${CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS} -flat_namespace -undefined dynamic_lookup")
201 endif(APPLE)
202
203 if (CMAKE_SYSTEM_NAME MATCHES Linux)
204    if (CMAKE_COMPILER_IS_GNUCXX)
205       set ( CMAKE_SHARED_LINKER_FLAGS "-Wl,--fatal-warnings -Wl,--no-undefined -lc ${CMAKE_SHARED_LINKER_FLAGS}")
206       set ( CMAKE_MODULE_LINKER_FLAGS "-Wl,--fatal-warnings -Wl,--no-undefined -lc ${CMAKE_MODULE_LINKER_FLAGS}")
207
208       set ( CMAKE_SHARED_LINKER_FLAGS "-Wl,--enable-new-dtags ${CMAKE_SHARED_LINKER_FLAGS}")
209       set ( CMAKE_MODULE_LINKER_FLAGS "-Wl,--enable-new-dtags ${CMAKE_MODULE_LINKER_FLAGS}")
210       set ( CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags ${CMAKE_EXE_LINKER_FLAGS}")
211
212       # we profile...
213       if(CMAKE_BUILD_TYPE_TOLOWER MATCHES profile)
214         set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
215         set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
216       endif(CMAKE_BUILD_TYPE_TOLOWER MATCHES profile)
217    endif (CMAKE_COMPILER_IS_GNUCXX)
218    if (CMAKE_C_COMPILER MATCHES "icc")
219       set ( CMAKE_SHARED_LINKER_FLAGS "-Wl,--fatal-warnings -Wl,--no-undefined -lc ${CMAKE_SHARED_LINKER_FLAGS}")
220       set ( CMAKE_MODULE_LINKER_FLAGS "-Wl,--fatal-warnings -Wl,--no-undefined -lc ${CMAKE_MODULE_LINKER_FLAGS}")
221    endif (CMAKE_C_COMPILER MATCHES "icc")
222 endif (CMAKE_SYSTEM_NAME MATCHES Linux)
223
224 set(PHONON_LIBS phonon ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})
225 if(QT_QTDBUS_FOUND)
226     list(APPEND PHONON_LIBS phonon ${QT_QTDBUS_LIBRARY})
227 endif(QT_QTDBUS_FOUND)
228
229 set(EXECUTABLE_OUTPUT_PATH ${Phonon_BINARY_DIR}/bin)
230 if (WIN32)
231    set(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH})
232 else (WIN32)
233    set(LIBRARY_OUTPUT_PATH ${Phonon_BINARY_DIR}/lib)
234 endif (WIN32)
235
236 if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER MATCHES "icc")
237    set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-check-new -fno-common")
238 endif (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER MATCHES "icc")
239
240 # Set up RPATH handling, so the libs are found if they are installed to a non-standard location.
241 # By default cmake builds the targets with full RPATH to everything in the build directory,
242 # but then removes the RPATH when installing.
243 # These two options below make it set the RPATH of the installed targets to all
244 # RPATH directories outside the current CMAKE_BINARY_DIR and also the library
245 # install directory. Alex
246 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH  TRUE)
247 set(CMAKE_INSTALL_RPATH "${LIB_INSTALL_DIR}" )
248
249 if(APPLE)
250    set(CMAKE_INSTALL_NAME_DIR ${LIB_INSTALL_DIR})
251 endif(APPLE)
252
253 if (Q_WS_X11)
254    add_subdirectory(vlc)
255 endif (Q_WS_X11)
256
257 macro_display_feature_log()