Make sure enough space is allocated for wchar-to-ansi conversion
[dsound-openal.git] / CMakeLists.txt
blob93e51b8b88c7331205880fade8b605ee7f40eb88
1 cmake_minimum_required(VERSION 3.0.2)
3 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
5 include(CheckCCompilerFlag)
6 include(CheckCSourceCompiles)
7 include(CheckTypeSize)
8 include(CheckIncludeFile)
10 project(DSOAL C)
13 IF(NOT CMAKE_BUILD_TYPE)
14     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
15         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
16         FORCE)
17 ENDIF()
19 set(DSOAL_DEFS "")
20 set(DSOAL_INC "")
21 set(DSOAL_FLAGS "")
22 set(DSOAL_LIBS "")
24 set(DSOAL_OBJS buffer.c
25                capture.c
26                dsound8.c
27                dsound_main.c
28                dsound_private.h
29                duplex.c
30                eax.h
31                primary.c
32                propset.c)
34 set(DSOAL_INC ${DSOAL_INC} ${DSOAL_BINARY_DIR} ${DSOAL_SOURCE_DIR}/include/AL)
37 check_type_size("long" SIZEOF_LONG)
38 set(DSOAL_DEFS ${DSOAL_DEFS} "SIZEOF_LONG=${SIZEOF_LONG}")
40 check_c_source_compiles("#include <intrin.h>
41 int main()
43     unsigned long idx = 0;
44     _BitScanForward64(&idx, 1);
45     return idx;
46 }" HAVE_BITSCANFORWARD64_INTRINSIC)
47 if(HAVE_BITSCANFORWARD64_INTRINSIC)
48     set(DSOAL_DEFS ${DSOAL_DEFS} HAVE_BITSCANFORWARD64_INTRINSIC)
49 else()
50     check_c_source_compiles("#include <intrin.h>
51     int main()
52     {
53         unsigned long idx = 0;
54         _BitScanForward(&idx, 1);
55         return idx;
56     }" HAVE_BITSCANFORWARD_INTRINSIC)
57     if(HAVE_BITSCANFORWARD_INTRINSIC)
58         set(DSOAL_DEFS ${DSOAL_DEFS} HAVE_BITSCANFORWARD_INTRINSIC)
59     endif()
60 endif()
63 if(NOT MSVC)
64     set(DSOAL_FLAGS ${DSOAL_FLAGS} -Winline -Wall)
65     check_c_compiler_flag(-Wextra HAVE_W_EXTRA)
66     if(HAVE_W_EXTRA)
67         set(DSOAL_FLAGS ${DSOAL_FLAGS} -Wextra)
68     endif()
69     set(DSOAL_LIBS ${DSOAL_LIBS} -static-libgcc)
70 endif()
71 if(NOT WIN32)
72     check_c_compiler_flag(-fvisibility=hidden HAVE_FVISIBILITY_HIDDEN)
73     if(HAVE_FVISIBILITY_HIDDEN)
74         set(DSOAL_FLAGS ${DSOAL_FLAGS} -fvisibility=hidden)
75     endif()
76 else()
77     if(MINGW)
78         set(CMAKE_RC_COMPILER_INIT windres)
79         set(CMAKE_RC_COMPILE_OBJECT
80             "<CMAKE_RC_COMPILER> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
81     endif(MINGW)
82     enable_language(RC)
84     set(DSOAL_OBJS ${DSOAL_OBJS} debug.c version.rc)
86     set(DSOAL_DEFS ${DSOAL_DEFS} _WIN32 WINVER=0x0600 DEBUG_INFO)
88     set(DSOAL_LIBS ${DSOAL_LIBS} winmm ole32)
89 endif()
90 set(DSOAL_DEFS ${DSOAL_DEFS} COBJMACROS)
92 add_library(dsound SHARED ${DSOAL_OBJS} dsound.def)
93 if(WIN32)
94     set_target_properties(dsound PROPERTIES PREFIX "")
95 endif()
96 target_compile_definitions(dsound PRIVATE ${DSOAL_DEFS})
97 target_include_directories(dsound PRIVATE ${DSOAL_INC})
98 target_compile_options(dsound PRIVATE ${DSOAL_FLAGS})
99 target_link_libraries(dsound PRIVATE ${DSOAL_LIBS})