3e8f30a2eebcf71f23b9ce8c3da58885c1efa294
[vlc.git] / extras / buildsystem / cmake / include / config.cmake
1 include( CheckIncludeFile )
2 include (CheckTypeSize)
3 include (CheckCSourceCompiles)
4 include (CheckSymbolExists)
5 include (CheckLibraryExists)
6 include (FindThreads)
7
8 include( ${CMAKE_SOURCE_DIR}/cmake/vlc_check_include_files.cmake )
9 include( ${CMAKE_SOURCE_DIR}/cmake/vlc_check_functions_exist.cmake )
10 include( ${CMAKE_SOURCE_DIR}/cmake/vlc_add_compile_flag.cmake )
11 include( ${CMAKE_SOURCE_DIR}/cmake/vlc_check_type.cmake )
12 include( ${CMAKE_SOURCE_DIR}/cmake/pkg_check_modules.cmake )
13
14 ###########################################################
15 # VERSION
16 ###########################################################
17
18 set(VLC_VERSION_MAJOR 0)
19 set(VLC_VERSION_MINOR 9)
20 set(VLC_VERSION_PATCH 0)
21 set(VLC_VERSION_EXTRA "-svn")
22
23 set(PACKAGE "vlc")
24 set(PACKAGE_STRING "vlc")
25 set(VERSION_MESSAGE "vlc-${VLC_VERSION_MAJOR}.${VLC_VERSION_MINOR}.${VLC_VERSION_PATCH}${VLC_VERSION_EXTRA}")
26 set(COPYRIGHT_MESSAGE "Copyright © the VideoLAN team")
27 set(COPYRIGHT_YEARS "2001-2008")
28
29 ###########################################################
30 # Options
31 ###########################################################
32
33 OPTION( ENABLE_HTTPD           "Enable httpd server" ON )
34 OPTION( ENABLE_VLM             "Enable vlm" ON )
35 OPTION( ENABLE_DYNAMIC_PLUGINS "Enable dynamic plugin" ON )
36 OPTION( ENABLE_NO_SYMBOL_CHECK "Don't check symbols of modules against libvlc. (Enabling this option speeds up compilation)" ON )
37
38 IF (NOT CMAKE_BUILD_TYPE)
39     SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING  "build type determining compiler flags" FORCE )
40 endif(NOT CMAKE_BUILD_TYPE )
41
42 set( HAVE_DYNAMIC_PLUGINS ${ENABLE_DYNAMIC_PLUGINS})
43 set( LIBEXT ${CMAKE_SHARED_MODULE_SUFFIX})
44
45 ###########################################################
46 # Headers checks
47 ###########################################################
48
49 vlc_check_include_files (malloc.h stdbool.h locale.h)
50 vlc_check_include_files (stddef.h stdlib.h sys/stat.h)
51 vlc_check_include_files (stdio.h stdint.h inttypes.h)
52 vlc_check_include_files (signal.h unistd.h dirent.h)
53 vlc_check_include_files (netinet/in.h netinet/udplite.h)
54 vlc_check_include_files (arpa/inet.h net/if.h)
55 vlc_check_include_files (netdb.h fcntl.h sys/time.h poll.h)
56 vlc_check_include_files (errno.h time.h)
57
58 vlc_check_include_files (dlfcn.h dl.h)
59
60 vlc_check_include_files (kernel/OS.h)
61 vlc_check_include_files (mach-o/dyld.h)
62
63
64 ###########################################################
65 # Functions/structures checks
66 ###########################################################
67
68 set(CMAKE_EXTRA_INCLUDE_FILES string.h)
69 vlc_check_functions_exist(strcpy strcasecmp)
70 vlc_check_functions_exist(strcasestr strdup)
71 vlc_check_functions_exist(strndup stricmp strnicmp)
72 vlc_check_functions_exist(atof strtoll atoll lldiv)
73 vlc_check_functions_exist(strlcpy)
74 set(CMAKE_EXTRA_INCLUDE_FILES)
75
76 set(CMAKE_EXTRA_INCLUDE_FILES stdio.h)
77 vlc_check_functions_exist(vasprintf)
78 set(CMAKE_EXTRA_INCLUDE_FILES)
79
80 set(CMAKE_EXTRA_INCLUDE_FILES libc.h)
81 vlc_check_functions_exist(fork)
82 set(CMAKE_EXTRA_INCLUDE_FILES)
83
84 check_c_source_compiles(
85 "#include <langinfo.h>
86 int main() { char* cs = nl_langinfo(CODESET); }"
87 HAVE_LANGINFO_CODESET)
88
89 vlc_check_type("struct addrinfo" "sys/socket.h;netdb.h")
90 if(HAVE_STRUCT_ADDRINFO)
91   set(HAVE_ADDRINFO ON)
92 endif(HAVE_STRUCT_ADDRINFO)
93 vlc_check_type("struct timespec" "time.h")
94
95 check_c_source_compiles (
96 "#include <stdint.h> \n #ifdef UINTMAX \n #error no uintmax
97  #endif
98  int main() { return 0;}" HAVE_STDINT_H_WITH_UINTMAX)
99
100 check_symbol_exists(ntohl "sys/param.h" NTOHL_IN_SYS_PARAM_H)
101 check_symbol_exists(scandir "dirent.h" HAVE_SCANDIR)
102 check_symbol_exists(scandir "dirent.h" HAVE_SCANDIR)
103 check_symbol_exists(localtime_r "time.h" HAVE_LOCALTIME_R)
104
105 check_symbol_exists(getnameinfo "sys/types.h;sys/socket.h;netdb.h" HAVE_GETNAMEINFO)
106 check_symbol_exists(getaddrinfo "sys/types.h;sys/socket.h;netdb.h" HAVE_GETADDRINFO)
107 if(NOT HAVE_GETADDRINFO)
108     check_library_exists(getaddrinfo nsl "" HAVE_GETADDRINFO)
109 endif(NOT HAVE_GETADDRINFO)
110
111 vlc_check_functions_exist(iconv)
112 if(NOT HAVE_ICONV)
113     set(LIBICONV "iconv")
114     check_library_exists(iconv iconv "" HAVE_ICONV)
115 endif(NOT HAVE_ICONV)
116 set(CMAKE_REQUIRED_LIBRARIES ${LIBICONV})
117 CHECK_C_SOURCE_COMPILES(" #include <iconv.h>
118  int main() { return iconv(0, (char **)0, 0, (char**)0, 0); }" ICONV_NO_CONST)
119 if( ICONV_NO_CONST )
120   set( ICONV_CONST "const" )
121 else( ICONV_NO_CONST )
122   set( ICONV_CONST " ")
123 endif( ICONV_NO_CONST )
124 set(CMAKE_REQUIRED_LIBRARIES)
125
126 check_library_exists(rt clock_nanosleep "" HAVE_CLOCK_NANOSLEEP)
127 if (HAVE_CLOCK_NANOSLEEP)
128     set(LIBRT "rt")
129 endif (HAVE_CLOCK_NANOSLEEP)
130
131 check_library_exists(m pow "" HAVE_LIBM)
132 if (HAVE_LIBM)
133     set (LIBM "m")
134 endif (HAVE_LIBM)
135
136 ###########################################################
137 # Other check
138 ###########################################################
139 include( ${CMAKE_SOURCE_DIR}/cmake/vlc_test_inline.cmake )
140
141 ###########################################################
142 # Platform check
143 ###########################################################
144 if(APPLE)
145     include( ${CMAKE_SOURCE_DIR}/cmake/vlc_find_frameworks.cmake )
146
147     if(ENABLE_NO_SYMBOL_CHECK)
148         set(DYNAMIC_LOOKUP "-undefined dynamic_lookup" CACHE INTERNAL STRING)
149     endif(ENABLE_NO_SYMBOL_CHECK)
150     set(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS
151      "${CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS} ${DYNAMIC_LOOKUP}")
152     set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
153      "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} ${DYNAMIC_LOOKUP}")
154
155     set(SYS_DARWIN 1)
156     add_definitions(-std=gnu99) # Hack for obj-c files to be compiled with gnu99
157     vlc_enable_modules(macosx minimal_macosx access_eyetv quartztext)
158
159     vlc_find_frameworks(Cocoa Carbon OpenGL AGL IOKit Quicktime
160                         WebKit QuartzCore Foundation ApplicationServices)
161     vlc_module_add_link_libraries(macosx
162         ${Cocoa_FRAMEWORKS}
163         ${IOKit_FRAMEWORKS}
164         ${OpenGL_FRAMEWORKS}
165         ${AGL_FRAMEWORKS}
166         ${Quicktime_FRAMEWORKS}
167         ${WebKit_FRAMEWORKS})
168     vlc_module_add_link_libraries(minimal_macosx
169         ${Cocoa_FRAMEWORKS}
170         ${Carbon_FRAMEWORKS}
171         ${OpenGL_FRAMEWORKS}
172         ${AGL_FRAMEWORKS})
173     vlc_module_add_link_libraries(access_eyetv
174         ${Foundation_FRAMEWORKS})
175     vlc_module_add_link_libraries(opengllayer
176          ${Cocoa_FRAMEWORKS}
177          ${QuartzCore_FRAMEWORKS}
178          ${OpenGL_FRAMEWORKS} )
179     vlc_module_add_link_libraries(quartztext
180          ${Carbon_FRAMEWORKS}
181          ${ApplicationServices_FRAMEWORKS} )
182     vlc_module_add_link_libraries(mp4
183          ${IOKit_FRAMEWORKS} )
184
185     add_executable(VLC MACOSX_BUNDLE src/vlc.c)
186     target_link_libraries(VLC libvlc)
187     set( MacOS ${CMAKE_CURRENT_BINARY_DIR}/VLC.app/Contents/MacOS )
188     add_custom_command(
189         TARGET VLC
190         POST_BUILD
191         COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/tmp
192         COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/tmp/modules/gui/macosx
193         COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/tmp/extras/package/macosx
194         COMMAND for i in vlc.xcodeproj Resources README.MacOSX.rtf\; do cp -R ${CMAKE_CURRENT_SOURCE_DIR}/extras/package/macosx/$$i ${CMAKE_CURRENT_BINARY_DIR}/tmp/extras/package/macosx\; done
195         COMMAND for i in AUTHORS COPYING THANKS\;do cp ${CMAKE_CURRENT_SOURCE_DIR}/$$i ${CMAKE_CURRENT_BINARY_DIR}/tmp\; done
196         COMMAND for i in AppleRemote.h AppleRemote.m about.h about.m applescript.h applescript.m controls.h controls.m equalizer.h equalizer.m intf.h intf.m macosx.m misc.h misc.m open.h open.m output.h output.m playlist.h playlist.m playlistinfo.h playlistinfo.m prefs_widgets.h prefs_widgets.m prefs.h prefs.m vout.h voutqt.m voutgl.m wizard.h wizard.m extended.h extended.m bookmarks.h bookmarks.m sfilters.h sfilters.m update.h update.m interaction.h interaction.m embeddedwindow.h embeddedwindow.m fspanel.h fspanel.m vout.m\; do cp ${CMAKE_CURRENT_SOURCE_DIR}/modules/gui/macosx/$$i ${CMAKE_CURRENT_BINARY_DIR}/tmp/modules/gui/macosx\; done
197         COMMAND cd ${CMAKE_CURRENT_BINARY_DIR}/tmp/extras/package/macosx && xcodebuild -target vlc | grep -vE '^\([ \\t]|$$\)' && cd ../../../../ && cp ${CMAKE_CURRENT_BINARY_DIR}/tmp/extras/package/macosx/build/Default/VLC.bundle/Contents/Info.plist ${CMAKE_CURRENT_BINARY_DIR}/VLC.app/Contents && cp -R ${CMAKE_CURRENT_BINARY_DIR}/tmp/extras/package/macosx/build/Default/VLC.bundle/Contents/Resources/English.lproj ${CMAKE_CURRENT_BINARY_DIR}/VLC.app/Contents/Resources
198         COMMAND cp -r ${CMAKE_CURRENT_SOURCE_DIR}/extras/package/macosx/Resources ${CMAKE_CURRENT_BINARY_DIR}/VLC.app/Contents
199         COMMAND find -d ${CMAKE_CURRENT_BINARY_DIR}/VLC.app/Contents/Resources -type d -name \\.svn -exec rm -rf {} "\;"
200         COMMAND rm -rf ${MacOS}/modules ${MacOS}/locale ${MacOS}/share
201         COMMAND ln -s ${CMAKE_CURRENT_SOURCE_DIR}/share ${MacOS}/share
202         COMMAND ln -s ${CMAKE_CURRENT_BINARY_DIR}/modules ${MacOS}/modules
203         COMMAND find ${CMAKE_BINARY_DIR}/po -name *.gmo -exec sh -c \"mkdir -p ${MacOS}/locale/\\`basename {}|sed s/\\.gmo//\\`/LC_MESSAGES\; ln -s {} ${MacOS}/locale/\\`basename {}|sed s/\\.gmo//\\`/LC_MESSAGES/vlc.mo\" "\;"
204         COMMAND ln -sf VLC ${MacOS}/clivlc #useless?
205         COMMAND printf "APPLVLC#" > ${CMAKE_CURRENT_BINARY_DIR}/VLC.app/Contents/PkgInfo
206     )
207     set( MacOS )
208
209 endif(APPLE)
210
211 ###########################################################
212 # info
213 ###########################################################
214
215 macro(command_to_configvar command var)
216  execute_process(
217   COMMAND sh -c "${command}"
218   OUTPUT_VARIABLE ${var}
219   OUTPUT_STRIP_TRAILING_WHITESPACE)
220  string( REPLACE "\n" "\\n" ${var} ${${var}})
221 endmacro(command_to_configvar)
222
223 command_to_configvar( "whoami" VLC_COMPILE_BY )
224 command_to_configvar( "hostname" VLC_COMPILE_HOST )
225 command_to_configvar( "hostname" VLC_COMPILE_DOMAIN )
226 command_to_configvar( "${CMAKE_C_COMPILER} --version" VLC_COMPILER )
227 # FIXME: WTF? this is not the configure line!
228 command_to_configvar( "${CMAKE_C_COMPILER} --version" CONFIGURE_LINE )
229 set( VLC_COMPILER "${CMAKE_C_COMPILER}" )
230
231
232 ###########################################################
233 # Modules: Following are all listed in options
234 ###########################################################
235
236 # This module will be enabled but user could disabled it
237 vlc_enable_modules(dummy logger memcpy)
238 vlc_enable_modules(mpgv mpga m4v m4a h264 vc1 demux_cdg cdg ps pva avi mp4 rawdv rawvid nsv real aiff mjpeg demuxdump flacsys tta)
239 vlc_enable_modules(cvdsub svcdsub spudec subsdec subsusf t140 dvbsub cc mpeg_audio lpcm a52 dts cinepak flac)
240 vlc_enable_modules(deinterlace invert adjust transform wave ripple psychedelic gradient motionblur rv32 rotate noise grain extract sharpen seamcarving)
241 vlc_enable_modules(converter_fixed mono)
242 vlc_enable_modules(trivial_resampler ugly_resampler)
243 vlc_enable_modules(trivial_channel_mixer trivial_mixer)
244 vlc_enable_modules(playlist export nsc xtag)
245 vlc_enable_modules(i420_rgb grey_yuv rawvideo blend scale image logo magnify puzzle colorthres)
246 vlc_enable_modules(wav araw subtitle vobsub adpcm a52sys dtssys au ty voc xa nuv smf)
247 vlc_enable_modules(access_directory access_file access_udp access_tcp)
248 vlc_enable_modules(access_http access_mms access_ftp)
249 vlc_enable_modules(access_filter_bandwidth)
250 vlc_enable_modules(packetizer_mpegvideo packetizer_h264)
251 vlc_enable_modules(packetizer_mpeg4video packetizer_mpeg4audio)
252 vlc_enable_modules(packetizer_vc1)
253 vlc_enable_modules(spatializer)
254
255 if(NOT mingwce)
256    set(enabled ON)
257 endif(NOT mingwce)
258 vlc_register_modules(${enabled} access_fake access_filter_timeshift access_filter_record access_filter_dump)
259 vlc_register_modules(${enabled} gestures rc telnet hotkeys showintf marq podcast shout sap fake folder)
260 vlc_register_modules(${enabled} rss mosaic wall motiondetect clone crop erase bluescreen alphamask gaussianblur)
261 vlc_register_modules(${enabled} i420_yuy2 i422_yuy2 i420_ymga i422_i420 yuy2_i422 yuy2_i420 chroma_chain)
262 vlc_register_modules(${enabled} aout_file linear_resampler bandlimited_resampler)
263 vlc_register_modules(${enabled} float32_mixer spdif_mixer simple_channel_mixer)
264 vlc_register_modules(${enabled} dolby_surround_decoder headphone_channel_mixer normvol equalizer param_eq)
265 vlc_register_modules(${enabled} converter_float a52tospdif dtstospdif audio_format)
266 set(enabled)
267
268 if(NOT WIN32)
269    vlc_enable_modules(screensaver)
270 endif(NOT WIN32)
271
272 # Following modules will be disabled but listed in options
273
274 vlc_disable_modules(asf)
275
276 # This module is disabled because the CMakeList.txt which
277 # is generated isn't correct. We'll put that back
278 # when cmake will be accepted as default build system
279 vlc_disable_modules(motion)
280
281 ###########################################################
282 # libraries
283 ###########################################################
284 OPTION( ENABLE_CONTRIB "Attempt to use VLC contrib system to get the third-party libraries" ON )
285 if(ENABLE_CONTRIB)
286   set( CONTRIB_INCLUDE ${CMAKE_SOURCE_DIR}/extras/contrib/include)
287   set( CONTRIB_LIB ${CMAKE_SOURCE_DIR}/extras/contrib/lib)
288   set( CONTRIB_PROGRAM ${CMAKE_SOURCE_DIR}/extras/contrib/bin)
289   set( CMAKE_LIBRARY_PATH ${CONTRIB_LIB} ${CMAKE_LIBRARY_PATH} )
290   set( CMAKE_PROGRAM_PATH ${CONTRIB_PROGRAM} ${CMAKE_PROGRAM_PATH} )
291   set( CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -L${CONTRIB_LIB}" )
292   set( CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -L${CONTRIB_LIB}" )
293   set( CMAKE_SHARED_MODULE_CREATE_C_FLAGS "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -L${CONTRIB_LIB}" )
294   set( CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS "${CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS} -L${CONTRIB_LIB}" )
295   set( CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS} -L${CONTRIB_LIB}" )
296   set( CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS} -L${CONTRIB_LIB}" )
297   add_definitions(-I${CONTRIB_INCLUDE})
298 endif(ENABLE_CONTRIB)
299
300 set(CMAKE_REQUIRED_INCLUDES ${CONTRIB_INCLUDE})
301
302 #fixme: use find_package(cddb 0.9.5)
303 pkg_check_modules(LIBCDDB libcddb>=0.9.5)
304 if(${LIBCDDB_FOUND})
305   vlc_module_add_link_libraries(cdda ${LIBCDDB_LIBRARIES})
306   vlc_add_module_compile_flag(cdda ${LIBCDDB_CFLAGS} )
307 endif(${LIBCDDB_FOUND})
308
309 find_package(Dlopen)
310 set(HAVE_DL_DLOPEN ${Dlopen_FOUND})
311
312 find_package(FFmpeg)
313 if(FFmpeg_FOUND)
314   set(CMAKE_EXTRA_INCLUDE_FILES stdint.h)
315   vlc_check_include_files (ffmpeg/avcodec.h)
316   vlc_check_include_files (postproc/postprocess.h)
317   set(CMAKE_EXTRA_INCLUDE_FILES)
318   vlc_enable_modules(ffmpeg)
319   vlc_add_module_compile_flag(ffmpeg ${FFmpeg_CFLAGS} )
320   vlc_module_add_link_libraries(ffmpeg ${FFmpeg_LIBRARIES})
321 endif(FFmpeg_FOUND)
322
323 find_package(Lua)
324 if(Lua_FOUND)
325   set(HAVE_LUA TRUE)
326   vlc_enable_modules(lua)
327   vlc_add_module_compile_flag(lua ${Lua_CFLAGS} )
328   vlc_module_add_link_libraries(lua ${Lua_LIBRARIES})
329 endif(Lua_FOUND)
330
331 set(CMAKE_REQUIRED_INCLUDES)
332
333 ###########################################################
334 # Final configuration
335 ###########################################################
336 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/include/config.h)
337