Fixed missed selection oulines for curves/surfaces/fonts/armature when texture shadin...
[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} ${LIBSAMPLERATE_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_FFTW3)
95                 LINK_DIRECTORIES(${FFTW3_LIBPATH})
96         ENDIF(WITH_FFTW3)
97         IF(WITH_OPENCOLLADA)
98                 LINK_DIRECTORIES(${OPENCOLLADA_LIBPATH})
99                 LINK_DIRECTORIES(${PCRE_LIBPATH})
100                 LINK_DIRECTORIES(${EXPAT_LIBPATH})
101         ENDIF(WITH_OPENCOLLADA)
102
103         IF(WIN32 AND NOT UNIX)
104                 LINK_DIRECTORIES(${PTHREADS_LIBPATH})
105         ENDIF(WIN32 AND NOT UNIX)
106 ENDMACRO(SETUP_LIBDIRS)
107
108 MACRO(SETUP_LIBLINKS
109         target)
110         SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS} ")
111
112         TARGET_LINK_LIBRARIES(${target} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${JPEG_LIBRARY} ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} ${LLIBS})
113
114         # since we are using the local libs for python when compiling msvc projects, we need to add _d when compiling debug versions
115         IF(WITH_PYTHON)
116                 TARGET_LINK_LIBRARIES(${target} ${PYTHON_LINKFLAGS})
117
118                 IF(WIN32 AND NOT UNIX)
119                         TARGET_LINK_LIBRARIES(${target} debug ${PYTHON_LIB}_d)
120                         TARGET_LINK_LIBRARIES(${target} optimized ${PYTHON_LIB})
121                 ELSE(WIN32 AND NOT UNIX)
122                         TARGET_LINK_LIBRARIES(${target} ${PYTHON_LIB})
123                 ENDIF(WIN32 AND NOT UNIX)
124         ENDIF(WITH_PYTHON)
125
126         TARGET_LINK_LIBRARIES(${target} ${OPENGL_glu_LIBRARY} ${JPEG_LIB} ${PNG_LIB} ${ZLIB_LIB})
127         TARGET_LINK_LIBRARIES(${target} ${FREETYPE_LIBRARY} ${LIBSAMPLERATE_LIB})
128
129         IF(WITH_INTERNATIONAL)
130                 TARGET_LINK_LIBRARIES(${target} ${GETTEXT_LIB})
131
132                 IF(WIN32 AND NOT UNIX)
133                         TARGET_LINK_LIBRARIES(${target} ${ICONV_LIB})
134                 ENDIF(WIN32 AND NOT UNIX)
135         ENDIF(WITH_INTERNATIONAL)
136
137         IF(WITH_OPENAL)
138                 TARGET_LINK_LIBRARIES(${target} ${OPENAL_LIBRARY})
139         ENDIF(WITH_OPENAL)
140         IF(WITH_FFTW3)  
141                 TARGET_LINK_LIBRARIES(${target} ${FFTW3_LIB})
142         ENDIF(WITH_FFTW3)
143         IF(WITH_JACK)
144                 TARGET_LINK_LIBRARIES(${target} ${JACK_LIB})
145         ENDIF(WITH_JACK)
146         IF(WITH_SNDFILE)
147                 TARGET_LINK_LIBRARIES(${target} ${SNDFILE_LIB})
148         ENDIF(WITH_SNDFILE)
149         IF(WITH_SDL)
150                 TARGET_LINK_LIBRARIES(${target} ${SDL_LIBRARY})
151         ENDIF(WITH_SDL)
152         IF(WITH_QUICKTIME)
153                 TARGET_LINK_LIBRARIES(${target} ${QUICKTIME_LIB})
154         ENDIF(WITH_QUICKTIME)
155         IF(WITH_IMAGE_TIFF)
156                 TARGET_LINK_LIBRARIES(${target} ${TIFF_LIBRARY})
157         ENDIF(WITH_IMAGE_TIFF)
158         IF(WITH_IMAGE_OPENEXR)
159                 IF(WIN32 AND NOT UNIX)
160                         FOREACH(loop_var ${OPENEXR_LIB})
161                                 TARGET_LINK_LIBRARIES(${target} debug ${loop_var}_d)
162                                 TARGET_LINK_LIBRARIES(${target} optimized ${loop_var})
163                         ENDFOREACH(loop_var)
164                 ELSE(WIN32 AND NOT UNIX)
165                         TARGET_LINK_LIBRARIES(${target} ${OPENEXR_LIB})
166                 ENDIF(WIN32 AND NOT UNIX)
167         ENDIF(WITH_IMAGE_OPENEXR)
168         IF(WITH_LCMS)
169                 TARGET_LINK_LIBRARIES(${target} ${LCMS_LIBRARY})
170         ENDIF(WITH_LCMS)
171         IF(WITH_FFMPEG)
172                 TARGET_LINK_LIBRARIES(${target} ${FFMPEG_LIB})
173         ENDIF(WITH_FFMPEG)
174         IF(WITH_OPENCOLLADA)
175                 IF(WIN32 AND NOT UNIX)
176                         FOREACH(loop_var ${OPENCOLLADA_LIB})
177                                 TARGET_LINK_LIBRARIES(${target} debug ${loop_var}_d)
178                                 TARGET_LINK_LIBRARIES(${target} optimized ${loop_var})
179                         ENDFOREACH(loop_var)
180                         TARGET_LINK_LIBRARIES(${target} debug ${PCRE_LIB}_d)
181                         TARGET_LINK_LIBRARIES(${target} optimized ${PCRE_LIB})
182                         IF(EXPAT_LIB)
183                                 TARGET_LINK_LIBRARIES(${target} debug ${EXPAT_LIB}_d)
184                                 TARGET_LINK_LIBRARIES(${target} optimized ${EXPAT_LIB})
185                         ENDIF(EXPAT_LIB)
186                 ELSE(WIN32 AND NOT UNIX)
187                         TARGET_LINK_LIBRARIES(${target} ${OPENCOLLADA_LIB})
188                         TARGET_LINK_LIBRARIES(${target} ${PCRE_LIB})
189                         TARGET_LINK_LIBRARIES(${target} ${EXPAT_LIB})
190                 ENDIF(WIN32 AND NOT UNIX)
191         ENDIF(WITH_OPENCOLLADA)
192         IF(WITH_LCMS)
193                 IF(WIN32 AND NOT UNIX)
194                         TARGET_LINK_LIBRARIES(${target} debug ${LCMS_LIB}_d)
195                         TARGET_LINK_LIBRARIES(${target} optimized ${LCMS_LIB})
196                 ENDIF(WIN32 AND NOT UNIX)
197         ENDIF(WITH_LCMS)
198         IF(WIN32 AND NOT UNIX)
199                 TARGET_LINK_LIBRARIES(${target} ${PTHREADS_LIB})
200         ENDIF(WIN32 AND NOT UNIX)
201 ENDMACRO(SETUP_LIBLINKS)
202
203 MACRO(TEST_SSE_SUPPORT)
204         INCLUDE(CheckCSourceRuns)
205
206         MESSAGE(STATUS "Detecting SSE support")
207         IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
208                 SET(CMAKE_REQUIRED_FLAGS "-msse -msse2")
209         ELSEIF(MSVC)
210                 SET(CMAKE_REQUIRED_FLAGS "/arch:SSE2") # TODO, SSE 1 ?
211         ENDIF()
212
213         CHECK_C_SOURCE_RUNS("
214                 #include <xmmintrin.h>
215                 int main() { __m128 v = _mm_setzero_ps(); return 0; }"
216         SUPPORT_SSE_BUILD)
217
218         CHECK_C_SOURCE_RUNS("
219                 #include <emmintrin.h>
220                 int main() { __m128d v = _mm_setzero_pd(); return 0; }"
221         SUPPORT_SSE2_BUILD)
222         MESSAGE(STATUS "Detecting SSE support")
223
224         IF(SUPPORT_SSE_BUILD)
225                 MESSAGE(STATUS "   ...SSE support found.")
226         ELSE(SUPPORT_SSE_BUILD)
227                 MESSAGE(STATUS "   ...SSE support missing.")
228         ENDIF(SUPPORT_SSE_BUILD)
229
230         IF(SUPPORT_SSE2_BUILD)
231                 MESSAGE(STATUS "   ...SSE2 support found.")
232         ELSE(SUPPORT_SSE2_BUILD)
233                 MESSAGE(STATUS "   ...SSE2 support missing.")
234         ENDIF(SUPPORT_SSE2_BUILD)
235
236 ENDMACRO(TEST_SSE_SUPPORT)
237
238 # when we have warnings as errors applied globally this
239 # needs to be removed for some external libs which we dont maintain.
240
241 # utility macro
242 MACRO(_REMOVE_STRICT_FLAGS
243         flag)
244         
245         STRING(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
246         STRING(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
247         STRING(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
248         STRING(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_MINSIZEREL ${CMAKE_C_FLAGS_MINSIZEREL})
249         STRING(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELWITHDEBINFO ${CMAKE_C_FLAGS_RELWITHDEBINFO})
250
251         STRING(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
252         STRING(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
253         STRING(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
254         STRING(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL})
255         STRING(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
256
257 ENDMACRO(_REMOVE_STRICT_FLAGS)
258
259 MACRO(REMOVE_STRICT_FLAGS)
260
261         IF(CMAKE_COMPILER_IS_GNUCC)
262                 _REMOVE_STRICT_FLAGS("-Wunused-parameter")
263                 _REMOVE_STRICT_FLAGS("-Werror=[^ ]+")
264                 _REMOVE_STRICT_FLAGS("-Werror")
265         ENDIF(CMAKE_COMPILER_IS_GNUCC)
266
267         IF(MSVC)
268                 # TODO
269         ENDIF(MSVC)
270
271 ENDMACRO(REMOVE_STRICT_FLAGS)
272
273
274 MACRO(GET_BLENDER_VERSION)
275         FILE(READ ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h CONTENT)
276         STRING(REGEX REPLACE "\n" ";" CONTENT "${CONTENT}")
277         STRING(REGEX REPLACE "\t" ";" CONTENT "${CONTENT}")
278         STRING(REGEX REPLACE " " ";" CONTENT "${CONTENT}")
279
280         FOREACH(ITEM ${CONTENT})
281                 IF(LASTITEM MATCHES "BLENDER_VERSION")
282                         MATH(EXPR BLENDER_VERSION_MAJOR "${ITEM} / 100")
283                         MATH(EXPR BLENDER_VERSION_MINOR "${ITEM} % 100")
284                         SET(BLENDER_VERSION "${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}")
285                 ENDIF(LASTITEM MATCHES "BLENDER_VERSION")
286                 
287                 IF(LASTITEM MATCHES "BLENDER_SUBVERSION")
288                         SET(BLENDER_SUBVERSION ${ITEM})
289                 ENDIF(LASTITEM MATCHES "BLENDER_SUBVERSION")
290                 
291                 IF(LASTITEM MATCHES "BLENDER_MINVERSION")
292                         MATH(EXPR BLENDER_MINVERSION_MAJOR "${ITEM} / 100")
293                         MATH(EXPR BLENDER_MINVERSION_MINOR "${ITEM} % 100")
294                         SET(BLENDER_MINVERSION "${BLENDER_MINVERSION_MAJOR}.${BLENDER_MINVERSION_MINOR}")
295                 ENDIF(LASTITEM MATCHES "BLENDER_MINVERSION")
296                 
297                 IF(LASTITEM MATCHES "BLENDER_MINSUBVERSION")
298                         SET(BLENDER_MINSUBVERSION ${ITEM})
299                 ENDIF(LASTITEM MATCHES "BLENDER_MINSUBVERSION")
300
301                 SET(LASTITEM ${ITEM})
302         ENDFOREACH(ITEM ${CONTENT})
303         
304         MESSAGE(STATUS "Version major: ${BLENDER_VERSION_MAJOR}, Version minor: ${BLENDER_VERSION_MINOR}, Subversion: ${BLENDER_SUBVERSION}, Version: ${BLENDER_VERSION}")
305         MESSAGE(STATUS "Minversion major: ${BLENDER_MINVERSION_MAJOR}, Minversion minor: ${BLENDER_MINVERSION_MINOR}, MinSubversion: ${BLENDER_MINSUBVERSION}, Minversion: ${BLENDER_MINVERSION}")
306 ENDMACRO(GET_BLENDER_VERSION)