-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
219 lines (181 loc) · 7.25 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# cmake project file by Prakash Punnoor
CMAKE_MINIMUM_REQUIRED(VERSION 2.0)
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/admin/CMakeModules")
PROJECT(Alut C)
SET(PACKAGE "freealut")
SET(PACKAGE_TARNAME "freealut")
SET(PACKAGE_NAME "freealut library")
SET(PACKAGE_MAJOR_VERSION "1")
SET(PACKAGE_MINOR_VERSION "0")
SET(PACKAGE_BUILD_VERSION "1")
SET(PACKAGE_VERSION "${PACKAGE_MAJOR_VERSION}.${PACKAGE_MINOR_VERSION}.${PACKAGE_BUILD_VERSION}")
SET(MAJOR_VERSION "0")
SET(MINOR_VERSION "0")
SET(BUILD_VERSION "0")
SET(VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${BUILD_VERSION}")
SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
SET(PACKAGE_BUGREPORT "[email protected]")
SET(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
INCLUDE(${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/CheckIncludeFiles.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/CheckCSourceCompiles.cmake)
FIND_PACKAGE(ConfigHelper)
SET(ALUT_SOURCES src/alutBufferData.c
src/alutCodec.c
src/alutError.c
src/alutInit.c
src/alutInputStream.c
src/alutInternal.h
src/alutLoader.c
src/alutOutputStream.c
src/alutUtil.c
src/alutVersion.c
src/alutWaveform.c)
INCLUDE_DIRECTORIES(${Alut_SOURCE_DIR}/include)
SET(ADD_WFLAGS "")
SET(ADD_CFLAGS "")
SET(ADD_LDFLAGS "")
SET(ADD_LIBS "")
OPTION(BUILD_STATIC "build static library too" OFF)
OPTION(PROFILE "enable profile" OFF)
OPTION(OPTIMIZATION "enable optimization" ON)
OPTION(WARNINGS "enable warnings" OFF)
IF(WARNINGS)
OPTION(MORE_WARNINGS "enable more warnings" OFF)
OPTION(USE_WERROR "enable fail on all warning" OFF)
ENDIF(WARNINGS)
#want test-suit?
OPTION(BUILD_TESTS "build the test-suite" OFF)
ADD_DEFINE(ALUT_BUILD_LIBRARY)
# We could possibly need struct timespec and random(), which are not ANSI.
# Define to 500 if Single Unix conformance is wanted, 600 for sixth revision.
ADD_DEFINE("_XOPEN_SOURCE 600")
# We might need nanosleep, which is a POSIX IEEE Std 1003.1b-1993 feature.
# Define to the POSIX version that should be used.
ADD_DEFINE("_POSIX_C_SOURCE 200112L")
# Without __NO_CTYPE tolower and friends are macros which introduce a GLIBC 2.3
# dependency. By defining this identifier we are currently backwards compatible
# to GLIBC 2.1.3, which is a good thing. In addition, the macros lead to code
# which triggers warnings with -Wunreachable-code.
ADD_DEFINE("__NO_CTYPE 1")
ADD_DEFINITIONS(-DHAVE_CONFIG_H)
ADD_DEFINITIONS(-DNDEBUG)
FIND_LIBRARY(OPENAL_LIB NAMES openal openal32 PATHS /usr/lib /usr/local/lib ${OPENAL_LIB_DIR})
IF(OPENAL_LIB MATCHES "NOTFOUND")
MESSAGE(FATAL_ERROR "OpenAL not installed, cannot build alut - aborting.")
ENDIF(OPENAL_LIB MATCHES "NOTFOUND")
IF(UNIX)
SET(ADD_LIBS ${ADD_LIBS} m)
ENDIF(UNIX)
SET(CMAKE_REQUIRED_INCLUDES ${OPENAL_INCLUDE_DIR})
CHECK_INCLUDE_FILES("AL/alc.h;AL/al.h" AL_HEADERS)
IF(NOT AL_HEADERS)
MESSAGE(FATAL_ERROR "OpenAL header files not found - aborting.")
ENDIF(NOT AL_HEADERS)
IF(DEFINED OPENAL_INCLUDE_DIR)
INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR})
ENDIF(DEFINED OPENAL_INCLUDE_DIR)
# checks for unistd.h and time.h, as well
FIND_PACKAGE(SleepFunction)
CHECK_INCLUDE_FILE_DEFINE(stdint.h HAVE_STDINT_H)
IF(WIN32)
# check for __int8 type
SET(SOURCE
"int main(){__int8 foo;return 0;}
")
FILE(WRITE "${CMAKE_BINARY_DIR}/CMakeTmp/src.c" "${SOURCE}")
TRY_COMPILE(HAVE___INT8
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}/CMakeTmp/src.c
CMAKE_FLAGS
OUTPUT_VARIABLE OUTPUT)
IF(HAVE___INT8)
ADD_DEFINE("HAVE___INT8 1")
ENDIF(HAVE___INT8)
ENDIF(WIN32)
IF(HAVE_UNISTD_H)
CHECK_FUNCTION_DEFINE("
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
" stat "(\"\", (struct stat*)0)" HAVE_STAT)
ENDIF(HAVE_UNISTD_H)
IF(NOT HAVE_STAT)
CHECK_FUNCTION_DEFINE("
#include <sys/types.h>
#include <sys/stat.h>
" _stat "(\"\", (struct _stat*)0)" HAVE__STAT)
ENDIF(NOT HAVE_STAT)
# compiler specific settings
FIND_PACKAGE(CompilerAttribute)
FIND_PACKAGE(CompilerVisibility)
FIND_PACKAGE(CompilerFlagsSet)
GENERATE_CONFIG_H()
SET(CMAKE_C_FLAGS "${ADD_WFLAGS} ${ADD_CFLAGS} ${CMAKE_C_FLAGS}")
SET(CMAKE_CXX_FLAGS "${ADD_CFLAGS} ${CMAKE_CXX_FLAGS}")
SET(CMAKE_SHARED_LINKER_FLAGS "${ADD_LDFLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
SET(CMAKE_MODULE_LINKER_FLAGS "${ADD_LDFLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")
IF(BUILD_STATIC)
# we can't create a static library with the same name
# as the shared one, so we copy it over after creation
ADD_LIBRARY(alut_static STATIC ${ALUT_SOURCES})
TARGET_LINK_LIBRARIES(alut_static ${OPENAL_LIB} ${ADD_LIBS})
IF(NOT WIN32)
ADD_CUSTOM_COMMAND(
TARGET alut_static
POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E copy
${CMAKE_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}alut_static${CMAKE_STATIC_LIBRARY_SUFFIX}
${CMAKE_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}alut${CMAKE_STATIC_LIBRARY_SUFFIX})
INSTALL_FILES(/lib FILES ${CMAKE_STATIC_LIBRARY_PREFIX}alut${CMAKE_STATIC_LIBRARY_SUFFIX})
ENDIF(NOT WIN32)
ENDIF(BUILD_STATIC)
ADD_LIBRARY(alut SHARED ${ALUT_SOURCES})
SET_TARGET_PROPERTIES(alut PROPERTIES VERSION ${VERSION} SOVERSION ${MAJOR_VERSION})
TARGET_LINK_LIBRARIES(alut ${OPENAL_LIB} ${ADD_LIBS})
INSTALL_TARGETS(/lib alut)
INSTALL_FILES(/include/AL FILES include/AL/alut.h)
# needed for openal.pc.in and openal-config.in
SET(prefix ${CMAKE_INSTALL_PREFIX})
SET(exec_prefix "\${prefix}")
SET(libdir "\${exec_prefix}/lib")
SET(bindir "\${exec_prefix}/bin")
SET(includedir "\${prefix}/include")
SET(requirements "")
# static linking dependecies are broken, so pthread isn't needed currently
SET(PTHREAD_LIBS ${CMAKE_THREAD_LIBS_INIT})
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/admin/pkgconfig/freealut.pc.in
${CMAKE_BINARY_DIR}/admin/pkgconfig/freealut.pc @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/admin/pkgconfig/freealut-config.in
${CMAKE_BINARY_DIR}/admin/pkgconfig/freealut-config @ONLY)
INSTALL_PROGRAMS(/bin FILES admin/pkgconfig/freealut-config)
INSTALL_FILES(/lib/pkgconfig FILES admin/pkgconfig/freealut.pc)
# test-suite
IF(BUILD_TESTS)
# examples
ADD_EXECUTABLE(hello_world examples/hello_world.c)
TARGET_LINK_LIBRARIES(hello_world ${OPENAL_LIB} ${ADD_LIBS} alut)
ADD_EXECUTABLE(playfile examples/playfile.c)
TARGET_LINK_LIBRARIES(playfile ${OPENAL_LIB} ${ADD_LIBS} alut)
SET(TESTS errorstuff
fileloader
memoryloader
version
waveforms)
FOREACH(TEST ${TESTS})
SET(TEST_SRC test_suite/test_${TEST}.c)
IF(CMAKE_COMPILER_IS_GNUCC)
SET_SOURCE_FILES_PROPERTIES(${TEST_SRC} PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations")
ENDIF(CMAKE_COMPILER_IS_GNUCC)
ADD_EXECUTABLE(test_${TEST} ${TEST_SRC})
TARGET_LINK_LIBRARIES(test_${TEST} ${OPENAL_LIB} ${ADD_LIBS} alut)
ENDFOREACH(TEST)
#copy over testdata, so test-suite can be used in binary dir
SET(TESTDATA file1.wav
file2.au
file3.raw)
FOREACH(TESTDATUM ${TESTDATA})
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/test_suite/${TESTDATUM} ${CMAKE_BINARY_DIR}/${TESTDATUM} COPYONLY)
ENDFOREACH(TESTDATUM)
ENDIF(BUILD_TESTS)