Remove some unnecessary locks
[dsound-openal.git] / CMakeLists.txt
blobb3ee9a3c56d7b8308190ce5a3ea4641b85624563
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()
48 check_include_file(dsound.h HAVE_DSOUND_H)
49 if(NOT HAVE_DSOUND_H)
50     message(FATAL_ERROR "Could not find dsound.h")
51 endif()
53 if(WIN32)
54     if(NOT WINDRES)
55         if(HOST)
56             set(WINDRES "${HOST}-windres")
57         else()
58             set(WINDRES "windres")
59         endif()
60     endif()
62     add_definitions(-D_WIN32 -DDEBUG_INFO)
64     set(DSOAL_OBJS ${DSOAL_OBJS} debug.c)
66     add_library(${LIBNAME} SHARED ${DSOAL_OBJS})
67     add_custom_command(TARGET ${LIBNAME} PRE_BUILD
68                        COMMAND "${WINDRES}" -o version.o -i "${DSOAL_SOURCE_DIR}/version.rc"
69                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
70                        COMMENT "Generating version.o" VERBATIM)
71     target_link_libraries(${LIBNAME} ${OPENAL_LIBRARY} dxguid uuid winmm ole32 dxerr8)
72     set_target_properties(${LIBNAME} PROPERTIES PREFIX ""
73                                      LINK_FLAGS "version.o ${DSOAL_SOURCE_DIR}/dsound-mingw.def")
74 else()
75     add_definitions(-D__WINESRC__)
77     add_library(${LIBNAME} STATIC ${DSOAL_OBJS})
78     set_target_properties(${LIBNAME} PROPERTIES PREFIX "lib" SUFFIX ".a"
79                                      COMPILE_FLAGS -fPIC)
81     add_custom_command(TARGET ${LIBNAME} PRE_BUILD
82                        COMMAND wrc --nostdinc -D__WINESRC__ "-I${WINE_DIR}/include/wine" "-I${WINE_DIR}/include/wine/windows" -foversion.res "${DSOAL_SOURCE_DIR}/version.rc"
83                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
84                        COMMENT "Generating version.res" VERBATIM)
85     add_custom_command(TARGET ${LIBNAME} PRE_BUILD
86                        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"
87                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
88                        COMMENT "Generating ${LIBNAME}_classes_r.res" VERBATIM)
89     add_custom_command(TARGET ${LIBNAME} PRE_LINK
90                        COMMAND winebuild -w --def -o "lib${LIBNAME}.def" --export "${DSOAL_SOURCE_DIR}/${LIBNAME}.spec"
91                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
92                        COMMENT "Generating lib${LIBNAME}.def" VERBATIM)
93     add_custom_command(TARGET ${LIBNAME} POST_BUILD
94                        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
95                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
96                        COMMENT "Linking Wine shared library ${LIBNAME}.dll.so" VERBATIM)
97     add_custom_command(TARGET ${LIBNAME} POST_BUILD
98                        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
99                        WORKING_DIRECTORY "${DSOAL_BINARY_DIR}"
100                        COMMENT "Creating ${LIBNAME}.dll.fake" VERBATIM)
102     install(FILES "${DSOAL_BINARY_DIR}/${LIBNAME}.dll.so"
103             DESTINATION "${WINE_DIR}/lib${LIB_SUFFIX}/wine")
104     install(FILES "${DSOAL_BINARY_DIR}/lib${LIBNAME}.def"
105             DESTINATION "${WINE_DIR}/lib${LIB_SUFFIX}/wine")
106     install(FILES "${DSOAL_BINARY_DIR}/${LIBNAME}.dll.fake"
107             DESTINATION "${WINE_DIR}/lib${LIB_SUFFIX}/wine/fakedlls"
108             RENAME ${LIBNAME}.dll)
109 endif()