Make sure dsound.h exists
[dsound-openal.git] / CMakeLists.txt
blobf9a2a6eef830bd5669969e69cb1373a96c2428d1
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
25                regsvr.c)
27 find_package(OpenAL REQUIRED)
28 include_directories("${DSOAL_BINARY_DIR}" ${OPENAL_INCLUDE_DIR})
30 if(NOT MSVC)
31     add_definitions(-Winline -Wall)
32     check_c_compiler_flag(-Wextra HAVE_W_EXTRA)
33     if(HAVE_W_EXTRA)
34         add_definitions(-Wextra)
35     endif()
36     if(WIN32)
37         check_c_compiler_flag(-Wformat=0 HAVE_W_FORMAT_ZERO)
38         if(HAVE_W_FORMAT_ZERO)
39             add_definitions(-Wformat=0)
40         endif()
41     endif()
42 endif()
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 if(WIN32)
50     add_definitions(-D_WIN32 -DDEBUG_INFO)
52     set(DSOAL_OBJS ${DSOAL_OBJS} debug.c)
54     add_library(${LIBNAME} SHARED ${DSOAL_OBJS})
55     target_link_libraries(${LIBNAME} ${OPENAL_LIBRARY} dxguid uuid winmm ole32 dxerr8)
56     set_target_properties(${LIBNAME} PROPERTIES PREFIX ""
57                                                 LINK_FLAGS "${DSOAL_SOURCE_DIR}/dsound-mingw.def")
58 else()
59     find_path(WINE_INCLUDE_DIR library.h
60               PATHS
61               /usr/include/wine
62               /usr/local/include/wine)
63     if(NOT WINE_INCLUDE_DIR)
64         message(FATAL_ERROR "Could not find Wine header files")
65     endif()
66     message(STATUS "Found Wine header files - ${WINE_INCLUDE_DIR}")
67     add_definitions(-D__WINESRC__ "-I${WINE_INCLUDE_DIR}" "-I${WINE_INCLUDE_DIR}/windows")
69     add_custom_command(OUTPUT version.res
70                        COMMAND wrc --nostdinc -D__WINESRC__ "-I${DSOAL_BINARY_DIR}" "-I${WINE_INCLUDE_DIR}" "-I${WINE_INCLUDE_DIR}/windows" -foversion.res ${DSOAL_SOURCE_DIR}/version.rc
71                        DEPENDS "${DSOAL_SOURCE_DIR}/version.rc"
72                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}/CMakeFiles/dsoal.dir"
73                        COMMENT "Generating version.res..." VERBATIM)
75     add_library(dsoal STATIC ${DSOAL_OBJS})
76     set_target_properties(dsoal PROPERTIES PREFIX "lib" SUFFIX ".a"
77                                 COMPILE_FLAGS -fPIC)
79     set(OBJECT_FILES)
80     foreach(SRC ${DSOAL_OBJS})
81         string(REGEX REPLACE ".c" ".o" OBJ "${SRC}")
82         set(OBJECT_FILES "${OBJECT_FILES}" "${OBJ}")
83     endforeach()
85     add_custom_command(OUTPUT "${DSOAL_BINARY_DIR}/dsound.dll.so"
86                        COMMAND winegcc -shared "${DSOAL_SOURCE_DIR}/dsound.spec" version.res -o "${DSOAL_BINARY_DIR}/dsound.dll.so" "${DSOAL_BINARY_DIR}/libdsoal.a" -lopenal -ldxguid -luuid -lwinmm -lole32 -ldxerr8
87                        DEPENDS version.res "${DSOAL_SOURCE_DIR}/dsound.spec" "${DSOAL_BINARY_DIR}/libdsoal.a"
88                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}/CMakeFiles/dsoal.dir"
89                        COMMENT "Linking C shared library dsound.dll.so" VERBATIM)
91     add_custom_target(dsound ALL DEPENDS "${DSOAL_BINARY_DIR}/dsound.dll.so")
92 endif()