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