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