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