Build and install the .def file
[wine/multimedia.git] / CMakeLists.txt
blobfd4d723a06d26e3bd166589af70c15b68224e451
1 cmake_minimum_required(VERSION 2.6)
3 SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
5 include(CheckCCompilerFlag)
6 include(CheckIncludeFile)
8 project(DSOAL C)
10 set(LIBNAME dsound)
12 IF(NOT CMAKE_BUILD_TYPE)
13     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
14         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
15         FORCE)
16 ENDIF()
18 set(DSOAL_OBJS buffer.c
19                capture.c
20                dsound8.c
21                dsound_main.c
22                duplex.c
23                primary.c
24                propset.c)
26 find_package(OpenAL REQUIRED)
27 include_directories("${DSOAL_BINARY_DIR}" ${OPENAL_INCLUDE_DIR})
29 if(NOT MSVC)
30     add_definitions(-Winline -Wall)
31     check_c_compiler_flag(-Wextra HAVE_W_EXTRA)
32     if(HAVE_W_EXTRA)
33         add_definitions(-Wextra)
34     endif()
35     if(WIN32)
36         check_c_compiler_flag(-Wformat=0 HAVE_W_FORMAT_ZERO)
37         if(HAVE_W_FORMAT_ZERO)
38             add_definitions(-Wformat=0)
39         endif()
40     endif()
41 endif()
43 if(WIN32)
44     check_include_file(dsound.h HAVE_DSOUND_H)
45     if(NOT HAVE_DSOUND_H)
46         message(FATAL_ERROR "Could not find dsound.h")
47     endif()
49     add_definitions(-D_WIN32 -DDEBUG_INFO)
51     set(DSOAL_OBJS ${DSOAL_OBJS} debug.c)
53     add_library(${LIBNAME} SHARED ${DSOAL_OBJS})
54     target_link_libraries(${LIBNAME} ${OPENAL_LIBRARY} dxguid uuid winmm ole32 dxerr8)
55     set_target_properties(${LIBNAME} PROPERTIES PREFIX ""
56                                                 LINK_FLAGS "${DSOAL_SOURCE_DIR}/dsound-mingw.def")
57 else()
58     find_path(WINE_DIR include/wine/library.h
59               PATHS /usr /usr/local)
60     if(NOT WINE_DIR)
61         message(FATAL_ERROR "Could not find Wine installation directory")
62     endif()
63     message(STATUS "Found Wine installation directory - ${WINE_DIR}")
64     add_definitions(-D__WINESRC__ "-I${WINE_DIR}/include/wine" "-I${WINE_DIR}/include/wine/windows")
65     set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}" "${WINE_DIR}/include/wine" "${WINE_DIR}/include/wine/windows")
67     check_include_file(dsound.h HAVE_DSOUND_H)
68     if(NOT HAVE_DSOUND_H)
69         message(FATAL_ERROR "Could not find dsound.h")
70     endif()
72     add_library(${LIBNAME} STATIC ${DSOAL_OBJS})
73     set_target_properties(${LIBNAME} PROPERTIES PREFIX "lib" SUFFIX ".a"
74                                      COMPILE_FLAGS -fPIC)
76     add_custom_command(TARGET ${LIBNAME} POST_BUILD
77                        COMMAND wrc --nostdinc -D__WINESRC__ "-I${DSOAL_BINARY_DIR}" "-I${WINE_DIR}/include/wine" "-I${WINE_DIR}/include/wine/windows" -foversion.res ${DSOAL_SOURCE_DIR}/version.rc
78                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
79                        COMMENT "Generating version.res" VERBATIM)
80     add_custom_command(TARGET ${LIBNAME} POST_BUILD
81                        COMMAND winebuild -w --def -o lib${LIBNAME}.def --export ${DSOAL_SOURCE_DIR}/${LIBNAME}.spec
82                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
83                        COMMENT "Generating lib${LIBNAME}.def" VERBATIM)
84     add_custom_command(TARGET ${LIBNAME} POST_BUILD
85                        COMMAND winegcc -shared "${DSOAL_SOURCE_DIR}/${LIBNAME}.spec" version.res -o "${DSOAL_BINARY_DIR}/${LIBNAME}.dll.so" "lib${LIBNAME}.a" -lopenal -ldxguid -luuid -lwinmm -lole32 -ldxerr8
86                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
87                        COMMENT "Linking Wine shared library ${LIBNAME}.dll.so" VERBATIM)
88     add_custom_command(TARGET ${LIBNAME} POST_BUILD
89                        COMMAND winegcc -shared "${DSOAL_SOURCE_DIR}/${LIBNAME}.spec" version.res -o "${DSOAL_BINARY_DIR}/${LIBNAME}.dll.fake" "lib${LIBNAME}.a" -lopenal -ldxguid -luuid -lwinmm -lole32 -ldxerr8
90                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
91                        COMMENT "Creating ${LIBNAME}.dll.fake" VERBATIM)
93     install(FILES "${DSOAL_BINARY_DIR}/${LIBNAME}.dll.so"
94             DESTINATION "${WINE_DIR}/lib${LIB_SUFFIX}/wine")
95     install(FILES "${DSOAL_BINARY_DIR}/lib${LIBNAME}.def"
96             DESTINATION "${WINE_DIR}/lib${LIB_SUFFIX}/wine")
97     install(FILES "${DSOAL_BINARY_DIR}/${LIBNAME}.dll.fake"
98             DESTINATION "${WINE_DIR}/lib${LIB_SUFFIX}/wine/fakedlls"
99             RENAME ${LIBNAME}.dll)
100 endif()