WITH_SAMPLERATE option for cmake, without this playback wont behave right so this...
[blender-staging.git] / build_files / cmake / macros.cmake
1
2 # only MSVC uses SOURCE_GROUP
3 MACRO(BLENDERLIB_NOLIST
4         name
5         sources
6         includes)
7
8         MESSAGE(STATUS "Configuring library ${name}")
9
10         # Gather all headers
11         FILE(GLOB_RECURSE INC_ALL *.h)
12                  
13         INCLUDE_DIRECTORIES(${includes})
14         ADD_LIBRARY(${name} ${INC_ALL} ${sources})
15
16         # Group by location on disk
17         SOURCE_GROUP("Source Files" FILES CMakeLists.txt)
18         SET(ALL_FILES ${sources} ${INC_ALL})
19         FOREACH(SRC ${ALL_FILES})
20                 GET_FILENAME_COMPONENT(SRC_EXT ${SRC} EXT)
21                 IF(${SRC_EXT} MATCHES ".h" OR ${SRC_EXT} MATCHES ".hpp") 
22                         SOURCE_GROUP("Header Files" FILES ${SRC})
23                 ELSE()
24                         SOURCE_GROUP("Source Files" FILES ${SRC})
25                 ENDIF()
26         ENDFOREACH(SRC)
27 ENDMACRO(BLENDERLIB_NOLIST)
28
29 #       # works fine but having the includes listed is helpful for IDE's (QtCreator/MSVC)
30 #       MACRO(BLENDERLIB_NOLIST
31 #               name
32 #               sources
33 #               includes)
34 #
35 #               MESSAGE(STATUS "Configuring library ${name}")
36 #               INCLUDE_DIRECTORIES(${includes})
37 #               ADD_LIBRARY(${name} ${sources})
38 #       ENDMACRO(BLENDERLIB_NOLIST)
39
40
41 MACRO(BLENDERLIB
42         name
43         sources
44         includes)
45
46         BLENDERLIB_NOLIST(${name} "${sources}" "${includes}")
47
48         # Add to blender's list of libraries
49         FILE(APPEND ${CMAKE_BINARY_DIR}/cmake_blender_libs.txt "${name};")
50 ENDMACRO(BLENDERLIB)
51
52 MACRO(SETUP_LIBDIRS)
53         # see "cmake --help-policy CMP0003"
54         if(COMMAND cmake_policy)
55                 CMAKE_POLICY(SET CMP0003 NEW)
56         endif(COMMAND cmake_policy)
57         
58         LINK_DIRECTORIES(${JPEG_LIBPATH} ${PNG_LIBPATH} ${ZLIB_LIBPATH} ${FREETYPE_LIBPATH})
59
60         IF(WITH_PYTHON)
61                 LINK_DIRECTORIES(${PYTHON_LIBPATH})
62         ENDIF(WITH_PYTHON)
63         IF(WITH_INTERNATIONAL)
64                 LINK_DIRECTORIES(${ICONV_LIBPATH})
65                 LINK_DIRECTORIES(${GETTEXT_LIBPATH})
66         ENDIF(WITH_INTERNATIONAL)
67         IF(WITH_SDL)
68                 LINK_DIRECTORIES(${SDL_LIBPATH})
69         ENDIF(WITH_SDL)
70         IF(WITH_FFMPEG)
71                 LINK_DIRECTORIES(${FFMPEG_LIBPATH})
72         ENDIF(WITH_FFMPEG)
73         IF(WITH_IMAGE_OPENEXR)
74                 LINK_DIRECTORIES(${OPENEXR_LIBPATH})
75         ENDIF(WITH_IMAGE_OPENEXR)
76         IF(WITH_IMAGE_TIFF)
77                 LINK_DIRECTORIES(${TIFF_LIBPATH})
78         ENDIF(WITH_IMAGE_TIFF)
79         IF(WITH_LCMS)
80                 LINK_DIRECTORIES(${LCMS_LIBPATH})
81         ENDIF(WITH_LCMS)
82         IF(WITH_QUICKTIME)
83                 LINK_DIRECTORIES(${QUICKTIME_LIBPATH})
84         ENDIF(WITH_QUICKTIME)
85         IF(WITH_OPENAL)
86                 LINK_DIRECTORIES(${OPENAL_LIBPATH})
87         ENDIF(WITH_OPENAL)
88         IF(WITH_JACK)
89                 LINK_DIRECTORIES(${JACK_LIBPATH})
90         ENDIF(WITH_JACK)
91         IF(WITH_SNDFILE)
92                 LINK_DIRECTORIES(${SNDFILE_LIBPATH})
93         ENDIF(WITH_SNDFILE)
94         IF(WITH_SAMPLERATE)
95                 LINK_DIRECTORIES(${LIBSAMPLERATE_LIBPATH})
96         ENDIF(WITH_SAMPLERATE)
97         IF(WITH_FFTW3)
98                 LINK_DIRECTORIES(${FFTW3_LIBPATH})
99         ENDIF(WITH_FFTW3)
100         IF(WITH_OPENCOLLADA)
101                 LINK_DIRECTORIES(${OPENCOLLADA_LIBPATH})
102                 LINK_DIRECTORIES(${PCRE_LIBPATH})
103                 LINK_DIRECTORIES(${EXPAT_LIBPATH})
104         ENDIF(WITH_OPENCOLLADA)
105
106         IF(WIN32 AND NOT UNIX)
107                 LINK_DIRECTORIES(${PTHREADS_LIBPATH})
108         ENDIF(WIN32 AND NOT UNIX)
109 ENDMACRO(SETUP_LIBDIRS)
110
111 MACRO(SETUP_LIBLINKS
112         target)
113         SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS} ")
114
115         TARGET_LINK_LIBRARIES(${target} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${JPEG_LIBRARY} ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} ${LLIBS})
116
117         # since we are using the local libs for python when compiling msvc projects, we need to add _d when compiling debug versions
118         IF(WITH_PYTHON)
119                 TARGET_LINK_LIBRARIES(${target} ${PYTHON_LINKFLAGS})
120
121                 IF(WIN32 AND NOT UNIX)
122                         TARGET_LINK_LIBRARIES(${target} debug ${PYTHON_LIB}_d)
123                         TARGET_LINK_LIBRARIES(${target} optimized ${PYTHON_LIB})
124                 ELSE(WIN32 AND NOT UNIX)
125                         TARGET_LINK_LIBRARIES(${target} ${PYTHON_LIB})
126                 ENDIF(WIN32 AND NOT UNIX)
127         ENDIF(WITH_PYTHON)
128
129         TARGET_LINK_LIBRARIES(${target} ${OPENGL_glu_LIBRARY} ${JPEG_LIB} ${PNG_LIB} ${ZLIB_LIB})
130         TARGET_LINK_LIBRARIES(${target} ${FREETYPE_LIBRARY})
131
132         IF(WITH_INTERNATIONAL)
133                 TARGET_LINK_LIBRARIES(${target} ${GETTEXT_LIB})
134
135                 IF(WIN32 AND NOT UNIX)
136                         TARGET_LINK_LIBRARIES(${target} ${ICONV_LIB})
137                 ENDIF(WIN32 AND NOT UNIX)
138         ENDIF(WITH_INTERNATIONAL)
139
140         IF(WITH_OPENAL)
141                 TARGET_LINK_LIBRARIES(${target} ${OPENAL_LIBRARY})
142         ENDIF(WITH_OPENAL)
143         IF(WITH_FFTW3)  
144                 TARGET_LINK_LIBRARIES(${target} ${FFTW3_LIB})
145         ENDIF(WITH_FFTW3)
146         IF(WITH_JACK)
147                 TARGET_LINK_LIBRARIES(${target} ${JACK_LIB})
148         ENDIF(WITH_JACK)
149         IF(WITH_SNDFILE)
150                 TARGET_LINK_LIBRARIES(${target} ${SNDFILE_LIB})
151         ENDIF(WITH_SNDFILE)
152         IF(WITH_SAMPLERATE)
153                 TARGET_LINK_LIBRARIES(${target} ${LIBSAMPLERATE_LIB})
154         ENDIF(WITH_SAMPLERATE)  
155         IF(WITH_SDL)
156                 TARGET_LINK_LIBRARIES(${target} ${SDL_LIBRARY})
157         ENDIF(WITH_SDL)
158         IF(WITH_QUICKTIME)
159                 TARGET_LINK_LIBRARIES(${target} ${QUICKTIME_LIB})
160         ENDIF(WITH_QUICKTIME)
161         IF(WITH_IMAGE_TIFF)
162                 TARGET_LINK_LIBRARIES(${target} ${TIFF_LIBRARY})
163         ENDIF(WITH_IMAGE_TIFF)
164         IF(WITH_IMAGE_OPENEXR)
165                 IF(WIN32 AND NOT UNIX)
166                         FOREACH(loop_var ${OPENEXR_LIB})
167                                 TARGET_LINK_LIBRARIES(${target} debug ${loop_var}_d)
168                                 TARGET_LINK_LIBRARIES(${target} optimized ${loop_var})
169                         ENDFOREACH(loop_var)
170                 ELSE(WIN32 AND NOT UNIX)
171                         TARGET_LINK_LIBRARIES(${target} ${OPENEXR_LIB})
172                 ENDIF(WIN32 AND NOT UNIX)
173         ENDIF(WITH_IMAGE_OPENEXR)
174         IF(WITH_LCMS)
175                 TARGET_LINK_LIBRARIES(${target} ${LCMS_LIBRARY})
176         ENDIF(WITH_LCMS)
177         IF(WITH_FFMPEG)
178                 TARGET_LINK_LIBRARIES(${target} ${FFMPEG_LIB})
179         ENDIF(WITH_FFMPEG)
180         IF(WITH_OPENCOLLADA)
181                 IF(WIN32 AND NOT UNIX)
182                         FOREACH(loop_var ${OPENCOLLADA_LIB})
183                                 TARGET_LINK_LIBRARIES(${target} debug ${loop_var}_d)
184                                 TARGET_LINK_LIBRARIES(${target} optimized ${loop_var})
185                         ENDFOREACH(loop_var)
186                         TARGET_LINK_LIBRARIES(${target} debug ${PCRE_LIB}_d)
187                         TARGET_LINK_LIBRARIES(${target} optimized ${PCRE_LIB})
188                         IF(EXPAT_LIB)
189                                 TARGET_LINK_LIBRARIES(${target} debug ${EXPAT_LIB}_d)
190                                 TARGET_LINK_LIBRARIES(${target} optimized ${EXPAT_LIB})
191                         ENDIF(EXPAT_LIB)
192                 ELSE(WIN32 AND NOT UNIX)
193                         TARGET_LINK_LIBRARIES(${target} ${OPENCOLLADA_LIB})
194                         TARGET_LINK_LIBRARIES(${target} ${PCRE_LIB})
195                         TARGET_LINK_LIBRARIES(${target} ${EXPAT_LIB})
196                 ENDIF(WIN32 AND NOT UNIX)
197         ENDIF(WITH_OPENCOLLADA)
198         IF(WITH_LCMS)
199                 IF(WIN32 AND NOT UNIX)
200                         TARGET_LINK_LIBRARIES(${target} debug ${LCMS_LIB}_d)
201                         TARGET_LINK_LIBRARIES(${target} optimized ${LCMS_LIB})
202                 ENDIF(WIN32 AND NOT UNIX)
203         ENDIF(WITH_LCMS)
204         IF(WIN32 AND NOT UNIX)
205                 TARGET_LINK_LIBRARIES(${target} ${PTHREADS_LIB})
206         ENDIF(WIN32 AND NOT UNIX)
207 ENDMACRO(SETUP_LIBLINKS)
208
209 MACRO(TEST_SSE_SUPPORT)
210         INCLUDE(CheckCSourceRuns)
211
212         MESSAGE(STATUS "Detecting SSE support")
213         IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
214                 SET(CMAKE_REQUIRED_FLAGS "-msse -msse2")
215         ELSEIF(MSVC)
216                 SET(CMAKE_REQUIRED_FLAGS "/arch:SSE2") # TODO, SSE 1 ?
217         ENDIF()
218
219         CHECK_C_SOURCE_RUNS("
220                 #include <xmmintrin.h>
221                 int main() { __m128 v = _mm_setzero_ps(); return 0; }"
222         SUPPORT_SSE_BUILD)
223
224         CHECK_C_SOURCE_RUNS("
225                 #include <emmintrin.h>
226                 int main() { __m128d v = _mm_setzero_pd(); return 0; }"
227         SUPPORT_SSE2_BUILD)
228         MESSAGE(STATUS "Detecting SSE support")
229
230         IF(SUPPORT_SSE_BUILD)
231                 MESSAGE(STATUS "   ...SSE support found.")
232         ELSE(SUPPORT_SSE_BUILD)
233                 MESSAGE(STATUS "   ...SSE support missing.")
234         ENDIF(SUPPORT_SSE_BUILD)
235
236         IF(SUPPORT_SSE2_BUILD)
237                 MESSAGE(STATUS "   ...SSE2 support found.")
238         ELSE(SUPPORT_SSE2_BUILD)
239                 MESSAGE(STATUS "   ...SSE2 support missing.")
240         ENDIF(SUPPORT_SSE2_BUILD)
241
242 ENDMACRO(TEST_SSE_SUPPORT)
243
244 # when we have warnings as errors applied globally this
245 # needs to be removed for some external libs which we dont maintain.
246
247 # utility macro
248 MACRO(_REMOVE_STRICT_FLAGS
249         flag)
250         
251         STRING(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
252         STRING(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
253         STRING(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
254         STRING(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_MINSIZEREL ${CMAKE_C_FLAGS_MINSIZEREL})
255         STRING(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELWITHDEBINFO ${CMAKE_C_FLAGS_RELWITHDEBINFO})
256
257         STRING(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
258         STRING(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
259         STRING(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
260         STRING(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL})
261         STRING(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
262
263 ENDMACRO(_REMOVE_STRICT_FLAGS)
264
265 MACRO(REMOVE_STRICT_FLAGS)
266
267         IF(CMAKE_COMPILER_IS_GNUCC)
268                 _REMOVE_STRICT_FLAGS("-Wunused-parameter")
269                 _REMOVE_STRICT_FLAGS("-Werror=[^ ]+")
270                 _REMOVE_STRICT_FLAGS("-Werror")
271         ENDIF(CMAKE_COMPILER_IS_GNUCC)
272
273         IF(MSVC)
274                 # TODO
275         ENDIF(MSVC)
276
277 ENDMACRO(REMOVE_STRICT_FLAGS)
278
279
280 MACRO(GET_BLENDER_VERSION)
281         FILE(READ ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h CONTENT)
282         STRING(REGEX REPLACE "\n" ";" CONTENT "${CONTENT}")
283         STRING(REGEX REPLACE "\t" ";" CONTENT "${CONTENT}")
284         STRING(REGEX REPLACE " " ";" CONTENT "${CONTENT}")
285
286         FOREACH(ITEM ${CONTENT})
287                 IF(LASTITEM MATCHES "BLENDER_VERSION")
288                         MATH(EXPR BLENDER_VERSION_MAJOR "${ITEM} / 100")
289                         MATH(EXPR BLENDER_VERSION_MINOR "${ITEM} % 100")
290                         SET(BLENDER_VERSION "${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}")
291                 ENDIF(LASTITEM MATCHES "BLENDER_VERSION")
292                 
293                 IF(LASTITEM MATCHES "BLENDER_SUBVERSION")
294                         SET(BLENDER_SUBVERSION ${ITEM})
295                 ENDIF(LASTITEM MATCHES "BLENDER_SUBVERSION")
296                 
297                 IF(LASTITEM MATCHES "BLENDER_MINVERSION")
298                         MATH(EXPR BLENDER_MINVERSION_MAJOR "${ITEM} / 100")
299                         MATH(EXPR BLENDER_MINVERSION_MINOR "${ITEM} % 100")
300                         SET(BLENDER_MINVERSION "${BLENDER_MINVERSION_MAJOR}.${BLENDER_MINVERSION_MINOR}")
301                 ENDIF(LASTITEM MATCHES "BLENDER_MINVERSION")
302                 
303                 IF(LASTITEM MATCHES "BLENDER_MINSUBVERSION")
304                         SET(BLENDER_MINSUBVERSION ${ITEM})
305                 ENDIF(LASTITEM MATCHES "BLENDER_MINSUBVERSION")
306
307                 SET(LASTITEM ${ITEM})
308         ENDFOREACH(ITEM ${CONTENT})
309         
310         MESSAGE(STATUS "Version major: ${BLENDER_VERSION_MAJOR}, Version minor: ${BLENDER_VERSION_MINOR}, Subversion: ${BLENDER_SUBVERSION}, Version: ${BLENDER_VERSION}")
311         MESSAGE(STATUS "Minversion major: ${BLENDER_MINVERSION_MAJOR}, Minversion minor: ${BLENDER_MINVERSION_MINOR}, MinSubversion: ${BLENDER_MINSUBVERSION}, Minversion: ${BLENDER_MINVERSION}")
312 ENDMACRO(GET_BLENDER_VERSION)