comparison CMakeLists.txt @ 3:a929285e1db0

Added CMake build system. There are problems with the SDL_sound module due to changes in CMake. Right now they just seem to be warnings, but I am unable to suppress them. Added license. Added README.
author Eric Wing <ewing . public |-at-| gmail . com>
date Wed, 27 Oct 2010 20:43:14 -0700
parents
children 26aec5629f68
comparison
equal deleted inserted replaced
2:279d0427ef26 3:a929285e1db0
1 CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
2 # These are all useless <sigh>
3 cmake_policy(SET CMP0000 OLD)
4 cmake_policy(SET CMP0004 OLD)
5
6 PROJECT(ALmixer)
7
8 INCLUDE(CMakeDependentOption)
9 SET(CPACK_SET_DESTDIR TRUE)
10 INCLUDE(CPack)
11 FIND_PACKAGE(OpenAL)
12 FIND_PACKAGE(SDL)
13 # Note: SDL_sound needs to be updated for 2.6+. You'll get annoying warnings.
14 FIND_PACKAGE(SDL_sound)
15
16
17
18 SET(ALMIXER_MAJOR_VERSION 0)
19 SET(ALMIXER_MINOR_VERSION 1)
20 SET(ALMIXER_PATCH_VERSION 0)
21
22 SET(ALMIXER_VERSION ${ALMIXER_MAJOR_VERSION}.${ALMIXER_MINOR_VERSION}.${ALMIXER_PATCH_VERSION})
23 SET(ALMIXER_COMPATIBILITY_VERSION ${ALMIXER_MAJOR_VERSION}.${ALMIXER_MINOR_VERSION}.0)
24 # ??? Don't know
25 SET(ALMIXER_SOVERSION ${ALMIXER_MAJOR_VERSION}.${ALMIXER_MINOR_VERSION}.0)
26
27
28 OPTION(WANTS_BUILD_SHARED_LIBRARY "Set to ON to build dynamic library." ON)
29 #OPTION(ALMIXER_COMPILE_WITHOUT_SDL "Not supported. Don't use" OFF)
30 OPTION(ENABLE_ALMIXER_THREADS "Use background thread for ALmixer_Update()" OFF)
31
32 IF(APPLE)
33 CMAKE_DEPENDENT_OPTION(WANTS_BUILD_FRAMEWORK "Set to ON to build framework instead of dylib. Only valid if BUILD_SHARED_LIBRARY is ON an is OS X." ON "WANTS_BUILD_SHARED_LIBRARY" ON)
34 ENDIF(APPLE)
35
36 SET(ALMIXER_LIBRARY_NAME ALmixer)
37 IF(APPLE)
38 SET(CMAKE_FRAMEWORK_INSTALL_DIR "/Library/Frameworks" CACHE STRING "Directory to install frameworks to.")
39 SET(CMAKE_FRAMEWORK_INSTALL_NAME_DIR "@executable_path/../Frameworks" CACHE STRING "install_name path for framework.")
40 #SET(CMAKE_DYLIB_INSTALL_NAME_DIR "" CACHE STRING "install_name path for dylib.")
41 SET(CMAKE_DYLIB_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "install_name path for dylib.")
42 SET(ALMIXER_FRAMEWORK_NAME "${ALMIXER_LIBRARY_NAME}.framework")
43 SET(ALMIXER_FRAMEWORK_VERSION_NUMBER "A")
44 SET(ALMIXER_FRAMEWORK_VERSIONED_EXECUTABLE_DIR "Versions/${ALMIXER_FRAMEWORK_VERSION_NUMBER}/MacOS")
45 SET(ALMIXER_FRAMEWORK_VERSIONED_LIB_DIR "Versions/${ALMIXER_FRAMEWORK_VERSION_NUMBER}/lib")
46 SET(ALMIXER_FRAMEWORK_CURRENT_EXECUTABLE_DIR "Versions/Current/MacOS")
47
48 # For Apple install_name, is it better to detect if Xcode vs Makefile?
49 # Xcode default=1, Makefile=0? Or detect if Framework vs. dylib,
50 # Framework=1, dylib=0?
51 OPTION(CMAKE_BUILD_WITH_INSTALL_RPATH "Set to YES to set the rpath or install_name on build instead of install." ON)
52
53 ELSEIF(UNIX)
54 SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "rpaths separated by semicolons.")
55 OPTION(CMAKE_BUILD_WITH_INSTALL_RPATH "Set to YES to set the rpath or install_name on build instead of install." OFF)
56
57 ENDIF(APPLE)
58
59
60
61 SET(ALMIXER_SOURCE
62 ${ALmixer_SOURCE_DIR}/ALmixer.c
63 ${ALmixer_SOURCE_DIR}/CircularQueue.c
64 ${ALmixer_SOURCE_DIR}/CircularQueue.h
65 )
66
67 SET(PUBLIC_HEADERS
68 ${ALmixer_SOURCE_DIR}/ALmixer.h
69 )
70
71 #SET(RESOURCE_FILES
72 #)
73
74 ADD_DEFINITIONS(-DALMIXER_BUILD_LIBRARY)
75 IF(ENABLE_ALMIXER_THREADS)
76 ADD_DEFINITIONS(-DENABLE_ALMIXER_THREADS)
77 ELSE(ENABLE_ALMIXER_THREADS)
78 REMOVE_DEFINITIONS(-DENABLE_ALMIXER_THREADS)
79 ENDIF(ENABLE_ALMIXER_THREADS)
80
81
82
83 IF(WANTS_BUILD_SHARED_LIBRARY)
84 ADD_LIBRARY(ALMIXER_LIBRARY SHARED ${PUBLIC_HEADERS} ${ALMIXER_SOURCE} ${RESOURCE_FILES})
85 SET_TARGET_PROPERTIES(ALMIXER_LIBRARY PROPERTIES OUTPUT_NAME "ALmixer")
86 ENDIF(WANTS_BUILD_SHARED_LIBRARY)
87
88 # Set Dynamic Library and Framework properties
89 IF(WANTS_BUILD_SHARED_LIBRARY AND WANTS_BUILD_FRAMEWORK)
90
91 SET_TARGET_PROPERTIES(ALMIXER_LIBRARY PROPERTIES
92 FRAMEWORK TRUE
93 FRAMEWORK_VERSION "${ALMIXER_FRAMEWORK_VERSION_NUMBER}"
94 # PRIVATE_HEADER "fooPrivate.h;fooBoth.h"
95 PUBLIC_HEADER "${PUBLIC_HEADERS}"
96 RESOURCE "${RESOURCE_FILES}"
97 # INSTALL_NAME_DIR ${CMAKE_FRAMEWORK_INSTALL_NAME_DIR}
98 # BUILD_WITH_INSTALL_RPATH ${CMAKE_BUILD_WITH_INSTALL_RPATH}
99 VERSION ${ALMIXER_VERSION}
100 SOVERSION ${ALMIXER_COMPATIBILITY_VERSION}
101 # COMPILE_FLAGS "${ALMIXER_C_FLAGS}"
102 )
103
104 # I moved the INSTALL_NAME_DIR to use SET_PROPERTY instead because
105 # SET_TARGET_PROPERTIES will fail if the variable is empty.
106 SET_PROPERTY(TARGET ALMIXER_LIBRARY PROPERTY INSTALL_NAME_DIR ${CMAKE_FRAMEWORK_INSTALL_NAME_DIR})
107 SET_PROPERTY(TARGET ALMIXER_LIBRARY PROPERTY BUILD_WITH_INSTALL_RPATH NO)
108 # If the user deletes the install_name path, use the gcc default
109 # and disable the option completely. But CMake by default places
110 # the name of the library in the install_name if
111 # BUILD_WITH_INSTALL_RPATH is ON. So to avoid this, I need to
112 # disable the switch.
113 IF(CMAKE_FRAMEWORK_INSTALL_NAME_DIR)
114 # MESSAGE("got dir ${CMAKE_FRAMEWORK_INSTALL_NAME_DIR}")
115 SET_PROPERTY(TARGET ALMIXER_LIBRARY PROPERTY BUILD_WITH_INSTALL_RPATH ${CMAKE_BUILD_WITH_INSTALL_RPATH})
116
117 ELSE(CMAKE_FRAMEWORK_INSTALL_NAME_DIR)
118 # MESSAGE("no dir ${CMAKE_FRAMEWORK_INSTALL_NAME_DIR}")
119 SET_PROPERTY(TARGET ALMIXER_LIBRARY PROPERTY BUILD_WITH_INSTALL_RPATH NO)
120
121 ENDIF(CMAKE_FRAMEWORK_INSTALL_NAME_DIR)
122
123
124
125 # Short Version is the "marketing version". It is the version
126 # the user sees in an information panel.
127 SET(MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${ALMIXER_MAJOR_VERSION}.${ALMIXER_MINOR_VERSION}.${ALMIXER_PATCH_VERSION}")
128 # Bundle version is the version the OS looks at.
129 SET(MACOSX_FRAMEWORK_BUNDLE_VERSION "${ALMIXER_MAJOR_VERSION}.${ALMIXER_MINOR_VERSION}.${ALMIXER_PATCH_VERSION}")
130 SET(MACOSX_FRAMEWORK_IDENTIFIER "net.playcontrol.almixer")
131
132 ELSEIF(WANTS_BUILD_SHARED_LIBRARY)
133 IF(APPLE)
134 SET_TARGET_PROPERTIES(ALMIXER_LIBRARY PROPERTIES
135 FRAMEWORK FALSE
136 # INSTALL_NAME_DIR ${CMAKE_DYLIB_INSTALL_NAME_DIR}
137 # BUILD_WITH_INSTALL_RPATH ${CMAKE_BUILD_WITH_INSTALL_RPATH}
138 VERSION ${ALMIXER_VERSION}
139 SOVERSION ${ALMIXER_COMPATIBILITY_VERSION}
140 # COMPILE_FLAGS "${ALMIXER_C_FLAGS}"
141 )
142 # I moved the INSTALL_NAME_DIR to use SET_PROPERTY instead because
143 # SET_TARGET_PROPERTIES will fail if the variable is empty.
144 SET_PROPERTY(TARGET ALMIXER_LIBRARY PROPERTY INSTALL_NAME_DIR ${CMAKE_DYLIB_INSTALL_NAME_DIR})
145 SET_PROPERTY(TARGET ALMIXER_LIBRARY PROPERTY BUILD_WITH_INSTALL_RPATH NO)
146 # If the user deletes the install_name path, use the gcc default
147 # and disable the option completely. But CMake by default places
148 # the name of the library in the install_name if
149 # BUILD_WITH_INSTALL_RPATH is ON. So to avoid this, I need to
150 # disable the switch.
151 IF(CMAKE_DYLIB_INSTALL_NAME_DIR)
152 SET_PROPERTY(TARGET ALMIXER_LIBRARY PROPERTY BUILD_WITH_INSTALL_RPATH ${CMAKE_BUILD_WITH_INSTALL_RPATH})
153 ELSE(CMAKE_DYLIB_INSTALL_NAME_DIR)
154 SET_PROPERTY(TARGET ALMIXER_LIBRARY PROPERTY BUILD_WITH_INSTALL_RPATH OFF)
155 ENDIF(CMAKE_DYLIB_INSTALL_NAME_DIR)
156
157
158
159 ELSEIF(UNIX)
160 SET_TARGET_PROPERTIES(ALMIXER_LIBRARY PROPERTIES
161 INSTALL_RPATH ${CMAKE_INSTALL_RPATH}
162 BUILD_WITH_INSTALL_RPATH ${CMAKE_BUILD_WITH_INSTALL_RPATH}
163 VERSION ${ALMIXER_VERSION}
164 SOVERSION ${ALMIXER_SOVERSION}
165 # COMPILE_FLAGS "${ALMIXER_C_FLAGS}"
166 )
167
168 ELSEIF(WIN32)
169 SET_TARGET_PROPERTIES(ALMIXER_LIBRARY PROPERTIES
170 VERSION ${ALMIXER_VERSION}
171 SOVERSION ${ALMIXER_COMPATIBILITY_VERSION}
172 # COMPILE_FLAGS "${ALMIXER_C_FLAGS} -DALMIXER_BUILD_AS_DLL"
173 )
174
175 ELSE(APPLE)
176 SET_TARGET_PROPERTIES(ALMIXER_LIBRARY PROPERTIES
177 VERSION ${ALMIXER_VERSION}
178 SOVERSION ${ALMIXER_COMPATIBILITY_VERSION}
179 # COMPILE_FLAGS "${ALMIXER_C_FLAGS}"
180 )
181
182 ENDIF(APPLE)
183
184
185 ENDIF(WANTS_BUILD_SHARED_LIBRARY AND WANTS_BUILD_FRAMEWORK)
186
187 INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR} ${SDL_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
188 #TARGET_LINK_LIBRARIES(ALMIXER_LIBRARY "${OPENAL_LIBRARY} ${SDL_LIBRARIES} ${SDL_SOUND_LIBRARIES}")
189 MESSAGE("SDL_libraries: ${SDL_LIBRARY}, ${SDL_SOUND_LIBRARIES}.")
190 TARGET_LINK_LIBRARIES(ALMIXER_LIBRARY ${OPENAL_LIBRARY} "${SDL_SOUND_LIBRARIES}" ${SDL_LIBRARY})
191
192
193
194 # Install commands below
195 IF(APPLE AND WANTS_BUILD_SHARED_LIBRARY AND WANTS_BUILD_FRAMEWORK)
196 # Will install framework to /Library/Frameworks directory or user specified
197 INSTALL(TARGETS
198 ALMIXER_LIBRARY
199 FRAMEWORK DESTINATION ${CMAKE_FRAMEWORK_INSTALL_DIR}
200 )
201 ELSE(APPLE AND WANTS_BUILD_SHARED_LIBRARY AND WANTS_BUILD_FRAMEWORK)
202 INSTALL(TARGETS
203 ALMIXER_LIBRARY
204 LIBRARY DESTINATION lib
205 ARCHIVE DESTINATION lib
206 PUBLIC_HEADER DESTINATION include
207 )
208 ENDIF(APPLE AND WANTS_BUILD_SHARED_LIBRARY AND WANTS_BUILD_FRAMEWORK)
209
210
211
212
213
214 # For uninstall (needs cmake_uninstall.cmake.in in the top-level directory)
215 CONFIGURE_FILE(
216 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
217 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
218 IMMEDIATE @ONLY)
219 ADD_CUSTOM_TARGET(uninstall
220 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
221
222
223
224 # Set defaults for Universal Binaries. We want 32-bit Intel/PPC on 10.4
225 # and 32/64-bit Intel/PPC on >= 10.5. Anything <= 10.3 doesn't support.
226 IF(APPLE)
227 # These are just defaults/recommendations, but how we want to build
228 # out of the box. But the user needs to be able to change these options.
229 # So we must only set the values the first time CMake is run, or we
230 # will overwrite any changes the user sets.
231 # FORCE is used because the options are not reflected in the UI otherwise.
232 # Seems like a good place to add version specific compiler flags too.
233 IF(NOT ALMIXER_CONFIG_HAS_BEEN_RUN_BEFORE)
234 # This is really fragile, but CMake doesn't provide the OS system
235 # version information we need. (Darwin versions can be changed
236 # independently of OS X versions.)
237 # It does look like CMake handles the CMAKE_OSX_SYSROOT automatically.
238 IF(EXISTS /Developer/SDKs/MacOSX10.5.sdk)
239 SET(CMAKE_OSX_ARCHITECTURES "ppc;i386;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
240 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.5" CACHE STRING "Flags used by the compiler during all build types." FORCE)
241 ELSE(EXISTS /Developer/SDKs/MacOSX10.5.sdk)
242 IF(EXISTS /Developer/SDKs/MacOSX10.4u.sdk)
243 SET(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build architectures for OSX" FORCE)
244 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.4" CACHE STRING "Flags used by the compiler during all build types." FORCE)
245 ELSE(EXISTS /Developer/SDKs/MacOSX10.4u.sdk)
246 # No Universal Binary support
247 # Should break down further to set the -mmacosx-version-min,
248 # but the SDK detection is too unreliable here.
249 ENDIF(EXISTS /Developer/SDKs/MacOSX10.4u.sdk)
250 ENDIF(EXISTS /Developer/SDKs/MacOSX10.5.sdk)
251 ENDIF(NOT ALMIXER_CONFIG_HAS_BEEN_RUN_BEFORE)
252 ENDIF(APPLE)
253
254 # This needs to be run very last so other parts of the scripts can take
255 # advantage of this.
256 IF(NOT ALMIXER_CONFIG_HAS_BEEN_RUN_BEFORE)
257 SET(ALMIXER_CONFIG_HAS_BEEN_RUN_BEFORE 1 CACHE INTERNAL "Flag to track whether this is the first time running CMake or if CMake has been configured before")
258 ENDIF(NOT ALMIXER_CONFIG_HAS_BEEN_RUN_BEFORE)
259
260
261