Avoid holding the device lock when it isn't needed
[dsound-openal.git] / CMakeLists.txt
blob352ed49e5ecc164295c3827561ed717910228fab
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 if(NOT WIN32)
11     find_path(WINE_DIR include/wine/library.h
12               PATHS /usr /usr/local)
13     if(NOT WINE_DIR)
14         message(FATAL_ERROR "Could not find Wine installation directory")
15     endif()
16     message(STATUS "Found Wine installation directory - ${WINE_DIR}")
17     include_directories("${WINE_DIR}/include/wine" "${WINE_DIR}/include/wine/windows")
18     set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}" "${WINE_DIR}/include/wine" "${WINE_DIR}/include/wine/windows")
19 endif()
21 set(LIBNAME dsound)
23 IF(NOT CMAKE_BUILD_TYPE)
24     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
25         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
26         FORCE)
27 ENDIF()
29 set(DSOAL_OBJS buffer.c
30                capture.c
31                dsound8.c
32                dsound_main.c
33                duplex.c
34                primary.c
35                propset.c)
37 find_package(OpenAL REQUIRED)
38 include_directories("${DSOAL_BINARY_DIR}" ${OPENAL_INCLUDE_DIR})
40 if(NOT MSVC)
41     add_definitions(-Winline -Wall)
42     check_c_compiler_flag(-Wextra HAVE_W_EXTRA)
43     if(HAVE_W_EXTRA)
44         add_definitions(-Wextra)
45     endif()
46 endif()
47 if(NOT WIN32)
48     check_c_compiler_flag(-fvisibility=hidden HAVE_FVISIBILITY_HIDDEN)
49     if(HAVE_FVISIBILITY_HIDDEN)
50         add_definitions(-fvisibility=hidden)
51     endif()
52 endif()
54 check_include_file(dsound.h HAVE_DSOUND_H)
55 if(NOT HAVE_DSOUND_H)
56     message(FATAL_ERROR "Could not find dsound.h")
57 endif()
59 if(WIN32)
60     if(NOT WINDRES)
61         if(HOST)
62             set(WINDRES "${HOST}-windres")
63         else()
64             set(WINDRES "windres")
65         endif()
66     endif()
68     add_definitions(-D_WIN32 -DDEBUG_INFO)
70     set(DSOAL_OBJS ${DSOAL_OBJS} debug.c)
72     add_library(${LIBNAME} SHARED ${DSOAL_OBJS})
73     add_custom_command(TARGET ${LIBNAME} PRE_BUILD
74                        COMMAND "${WINDRES}" -o version.o -i "${DSOAL_SOURCE_DIR}/version.rc"
75                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
76                        COMMENT "Generating version.o" VERBATIM)
77     target_link_libraries(${LIBNAME} ${OPENAL_LIBRARY} dxguid uuid winmm ole32 dxerr8)
78     set_target_properties(${LIBNAME} PROPERTIES PREFIX ""
79                                      LINK_FLAGS "version.o ${DSOAL_SOURCE_DIR}/dsound-mingw.def")
80 else()
81     add_definitions(-D__WINESRC__)
83     add_library(${LIBNAME} STATIC ${DSOAL_OBJS})
84     set_target_properties(${LIBNAME} PROPERTIES PREFIX "lib" SUFFIX ".a"
85                                      COMPILE_FLAGS -fPIC)
87     add_custom_command(TARGET ${LIBNAME} PRE_BUILD
88                        COMMAND wrc --nostdinc -D__WINESRC__ "-I${WINE_DIR}/include/wine" "-I${WINE_DIR}/include/wine/windows" -foversion.res "${DSOAL_SOURCE_DIR}/version.rc"
89                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
90                        COMMENT "Generating version.res" VERBATIM)
91     add_custom_command(TARGET ${LIBNAME} PRE_BUILD
92                        COMMAND widl -D__WINESRC__ "-I${WINE_DIR}/include/wine" "-I${WINE_DIR}/include/wine/windows" -r -o "${LIBNAME}_classes_r.res" "${DSOAL_SOURCE_DIR}/${LIBNAME}_classes.idl"
93                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
94                        COMMENT "Generating ${LIBNAME}_classes_r.res" VERBATIM)
95     add_custom_command(TARGET ${LIBNAME} PRE_LINK
96                        COMMAND winebuild -w --def -o "lib${LIBNAME}.def" --export "${DSOAL_SOURCE_DIR}/${LIBNAME}.spec"
97                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
98                        COMMENT "Generating lib${LIBNAME}.def" VERBATIM)
99     add_custom_command(TARGET ${LIBNAME} POST_BUILD
100                        COMMAND winegcc -shared "${DSOAL_SOURCE_DIR}/${LIBNAME}.spec" "${LIBNAME}_classes_r.res" version.res -o "${LIBNAME}.dll.so" "lib${LIBNAME}.a" ${OPENAL_LIBRARY} -ldxguid -luuid -lwinmm -lole32 -ldxerr8
101                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
102                        COMMENT "Linking Wine shared library ${LIBNAME}.dll.so" VERBATIM)
103     add_custom_command(TARGET ${LIBNAME} POST_BUILD
104                        COMMAND winegcc -shared "${DSOAL_SOURCE_DIR}/${LIBNAME}.spec" "${LIBNAME}_classes_r.res" version.res -o "${LIBNAME}.dll.fake" "lib${LIBNAME}.a" ${OPENAL_LIBRARY} -ldxguid -luuid -lwinmm -lole32 -ldxerr8
105                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
106                        COMMENT "Creating ${LIBNAME}.dll.fake" VERBATIM)
108     install(FILES "${DSOAL_BINARY_DIR}/${LIBNAME}.dll.so"
109             DESTINATION "${WINE_DIR}/lib${LIB_SUFFIX}/wine")
110     install(FILES "${DSOAL_BINARY_DIR}/lib${LIBNAME}.def"
111             DESTINATION "${WINE_DIR}/lib${LIB_SUFFIX}/wine")
112     install(FILES "${DSOAL_BINARY_DIR}/${LIBNAME}.dll.fake"
113             DESTINATION "${WINE_DIR}/lib${LIB_SUFFIX}/wine/fakedlls"
114             RENAME ${LIBNAME}.dll)
115 endif()