cmake
[blender.git] / build_files / cmake / macros.cmake
1 MACRO(BLENDERLIB_NOLIST
2         name
3         sources
4         includes)
5
6         # Gather all headers
7         FILE(GLOB_RECURSE INC_ALL *.h)
8                  
9         INCLUDE_DIRECTORIES(${includes})
10         ADD_LIBRARY(${name} ${INC_ALL} ${sources})
11
12         # Group by location on disk
13         SOURCE_GROUP(Files FILES CMakeLists.txt)
14         SET(ALL_FILES ${sources} ${INC_ALL})
15         FOREACH(SRC ${ALL_FILES})
16                 STRING(REGEX REPLACE ${CMAKE_CURRENT_SOURCE_DIR} "Files" REL_DIR "${SRC}")
17                 STRING(REGEX REPLACE "[\\\\/][^\\\\/]*$" "" REL_DIR "${REL_DIR}")
18                 STRING(REGEX REPLACE "^[\\\\/]" "" REL_DIR "${REL_DIR}")
19                 IF(REL_DIR)
20                         SOURCE_GROUP(${REL_DIR} FILES ${SRC})
21                 ELSE(REL_DIR)
22                         SOURCE_GROUP(Files FILES ${SRC})
23                 ENDIF(REL_DIR)
24         ENDFOREACH(SRC)
25
26         MESSAGE(STATUS "Configuring library ${name}")
27 ENDMACRO(BLENDERLIB_NOLIST)
28
29 MACRO(BLENDERLIB
30         name
31         sources
32         includes)
33
34         BLENDERLIB_NOLIST(${name} "${sources}" "${includes}")
35
36         # Add to blender's list of libraries
37         FILE(APPEND ${CMAKE_BINARY_DIR}/cmake_blender_libs.txt "${name};")
38 ENDMACRO(BLENDERLIB)
39
40 MACRO(SETUP_LIBDIRS)
41         # see "cmake --help-policy CMP0003"
42         if(COMMAND cmake_policy)
43                 CMAKE_POLICY(SET CMP0003 NEW)
44         endif(COMMAND cmake_policy)
45         
46         LINK_DIRECTORIES(${JPEG_LIBPATH} ${PNG_LIBPATH} ${ZLIB_LIBPATH} ${FREETYPE_LIBPATH} ${LIBSAMPLERATE_LIBPATH})
47         
48         IF(WITH_PYTHON)
49                 LINK_DIRECTORIES(${PYTHON_LIBPATH})
50         ENDIF(WITH_PYTHON)
51         IF(WITH_INTERNATIONAL)
52                 LINK_DIRECTORIES(${ICONV_LIBPATH})
53                 LINK_DIRECTORIES(${GETTEXT_LIBPATH})
54         ENDIF(WITH_INTERNATIONAL)
55         IF(WITH_SDL)
56                 LINK_DIRECTORIES(${SDL_LIBPATH})
57         ENDIF(WITH_SDL)
58         IF(WITH_FFMPEG)
59                 LINK_DIRECTORIES(${FFMPEG_LIBPATH})
60         ENDIF(WITH_FFMPEG)
61         IF(WITH_OPENEXR)
62                 LINK_DIRECTORIES(${OPENEXR_LIBPATH})
63         ENDIF(WITH_OPENEXR)
64         IF(WITH_TIFF)
65                 LINK_DIRECTORIES(${TIFF_LIBPATH})
66         ENDIF(WITH_TIFF)
67         IF(WITH_LCMS)
68                 LINK_DIRECTORIES(${LCMS_LIBPATH})
69         ENDIF(WITH_LCMS)
70         IF(WITH_QUICKTIME)
71                 LINK_DIRECTORIES(${QUICKTIME_LIBPATH})
72         ENDIF(WITH_QUICKTIME)
73         IF(WITH_OPENAL)
74                 LINK_DIRECTORIES(${OPENAL_LIBPATH})
75         ENDIF(WITH_OPENAL)
76         IF(WITH_JACK)
77                 LINK_DIRECTORIES(${JACK_LIBPATH})
78         ENDIF(WITH_JACK)
79         IF(WITH_SNDFILE)
80                 LINK_DIRECTORIES(${SNDFILE_LIBPATH})
81         ENDIF(WITH_SNDFILE)
82         IF(WITH_FFTW3)
83                 LINK_DIRECTORIES(${FFTW3_LIBPATH})
84         ENDIF(WITH_FFTW3)
85         IF(WITH_OPENCOLLADA)
86                 LINK_DIRECTORIES(${OPENCOLLADA_LIBPATH})
87                 LINK_DIRECTORIES(${PCRE_LIBPATH})
88                 LINK_DIRECTORIES(${EXPAT_LIBPATH})
89         ENDIF(WITH_OPENCOLLADA)
90
91         IF(WIN32)
92                 LINK_DIRECTORIES(${PTHREADS_LIBPATH})
93         ENDIF(WIN32)
94 ENDMACRO(SETUP_LIBDIRS)
95
96 MACRO(SETUP_LIBLINKS
97         target)
98         SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS} ")
99
100         TARGET_LINK_LIBRARIES(${target} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${JPEG_LIBRARY} ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} ${LLIBS})
101
102         # since we are using the local libs for python when compiling msvc projects, we need to add _d when compiling debug versions
103         IF(WITH_PYTHON)
104                 TARGET_LINK_LIBRARIES(${target} ${PYTHON_LINKFLAGS})
105
106                 IF(WIN32)
107                         TARGET_LINK_LIBRARIES(${target} debug ${PYTHON_LIB}_d)
108                         TARGET_LINK_LIBRARIES(${target} optimized ${PYTHON_LIB})
109                 ELSE(WIN32)
110                         TARGET_LINK_LIBRARIES(${target} ${PYTHON_LIB})
111                 ENDIF(WIN32)
112         ENDIF(WITH_PYTHON)
113
114         TARGET_LINK_LIBRARIES(${target} ${OPENGL_glu_LIBRARY} ${JPEG_LIB} ${PNG_LIB} ${ZLIB_LIB})
115         TARGET_LINK_LIBRARIES(${target} ${FREETYPE_LIBRARY} ${LIBSAMPLERATE_LIB})
116
117         IF(WITH_INTERNATIONAL)
118                 TARGET_LINK_LIBRARIES(${target} ${GETTEXT_LIB})
119
120                 IF(WIN32)
121                         TARGET_LINK_LIBRARIES(${target} ${ICONV_LIB})
122                 ENDIF(WIN32)
123         ENDIF(WITH_INTERNATIONAL)
124
125         IF(WITH_OPENAL)
126                 TARGET_LINK_LIBRARIES(${target} ${OPENAL_LIBRARY})
127         ENDIF(WITH_OPENAL)
128         IF(WITH_FFTW3)  
129                 TARGET_LINK_LIBRARIES(${target} ${FFTW3_LIB})
130         ENDIF(WITH_FFTW3)
131         IF(WITH_JACK)
132                 TARGET_LINK_LIBRARIES(${target} ${JACK_LIB})
133         ENDIF(WITH_JACK)
134         IF(WITH_SNDFILE)
135                 TARGET_LINK_LIBRARIES(${target} ${SNDFILE_LIB})
136         ENDIF(WITH_SNDFILE)
137         IF(WITH_SDL)
138                 TARGET_LINK_LIBRARIES(${target} ${SDL_LIBRARY})
139         ENDIF(WITH_SDL)
140         IF(WITH_QUICKTIME)
141                 TARGET_LINK_LIBRARIES(${target} ${QUICKTIME_LIB})
142         ENDIF(WITH_QUICKTIME)
143         IF(WITH_TIFF)
144                 TARGET_LINK_LIBRARIES(${target} ${TIFF_LIBRARY})
145         ENDIF(WITH_TIFF)
146         IF(WITH_OPENEXR)
147                 IF(WIN32)
148                         FOREACH(loop_var ${OPENEXR_LIB})
149                                 TARGET_LINK_LIBRARIES(${target} debug ${loop_var}_d)
150                                 TARGET_LINK_LIBRARIES(${target} optimized ${loop_var})
151                         ENDFOREACH(loop_var)
152                 ELSE(WIN32)
153                         TARGET_LINK_LIBRARIES(${target} ${OPENEXR_LIB})
154                 ENDIF(WIN32)
155         ENDIF(WITH_OPENEXR)
156         IF(WITH_LCMS)
157                 TARGET_LINK_LIBRARIES(${target} ${LCMS_LIBRARY})
158         ENDIF(WITH_LCMS)
159         IF(WITH_FFMPEG)
160                 TARGET_LINK_LIBRARIES(${target} ${FFMPEG_LIB})
161         ENDIF(WITH_FFMPEG)
162         IF(WITH_OPENCOLLADA)
163                 IF(WIN32)
164                         FOREACH(loop_var ${OPENCOLLADA_LIB})
165                                 TARGET_LINK_LIBRARIES(${target} debug ${loop_var}_d)
166                                 TARGET_LINK_LIBRARIES(${target} optimized ${loop_var})
167                         ENDFOREACH(loop_var)
168                         TARGET_LINK_LIBRARIES(${target} debug ${PCRE_LIB}_d)
169                         TARGET_LINK_LIBRARIES(${target} optimized ${PCRE_LIB})
170                         IF(EXPAT_LIB)
171                                 TARGET_LINK_LIBRARIES(${target} debug ${EXPAT_LIB}_d)
172                                 TARGET_LINK_LIBRARIES(${target} optimized ${EXPAT_LIB})
173                         ENDIF(EXPAT_LIB)
174                 ELSE(WIN32)
175                 TARGET_LINK_LIBRARIES(${target} ${OPENCOLLADA_LIB})
176                         TARGET_LINK_LIBRARIES(${target} ${PCRE_LIB})
177                         TARGET_LINK_LIBRARIES(${target} ${EXPAT_LIB})
178                 ENDIF(WIN32)
179         ENDIF(WITH_OPENCOLLADA)
180         IF(WIN32)
181                 TARGET_LINK_LIBRARIES(${target} ${PTHREADS_LIB})
182         ENDIF(WIN32)
183 ENDMACRO(SETUP_LIBLINKS)
184
185 MACRO(TEST_SSE_SUPPORT)
186         INCLUDE(CheckCXXSourceCompiles)
187
188         MESSAGE(STATUS "Detecting SSE support")
189         IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
190                 SET(CMAKE_REQUIRED_FLAGS "-msse -msse2")
191         ELSEIF(MSVC)
192                 SET(CMAKE_REQUIRED_FLAGS "/arch:SSE2")
193         ENDIF()
194
195         CHECK_CXX_SOURCE_COMPILES("
196                 #include <xmmintrin.h>
197                 int main() { __m128 v = _mm_setzero_ps(); return 0; }"
198         SUPPORT_SSE_BUILD)
199 ENDMACRO(TEST_SSE_SUPPORT)
200
201
202 MACRO(GET_BLENDER_VERSION)
203         FILE(READ ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h CONTENT)
204         STRING(REGEX REPLACE "\n" ";" CONTENT "${CONTENT}")
205         STRING(REGEX REPLACE "\t" ";" CONTENT "${CONTENT}")
206         STRING(REGEX REPLACE " " ";" CONTENT "${CONTENT}")
207
208         FOREACH(ITEM ${CONTENT})
209                 IF(LASTITEM MATCHES "BLENDER_VERSION")
210                         MATH(EXPR BLENDER_VERSION_MAJOR "${ITEM} / 100")
211                         MATH(EXPR BLENDER_VERSION_MINOR "${ITEM} % 100")
212                         SET(BLENDER_VERSION "${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}")
213                 ENDIF(LASTITEM MATCHES "BLENDER_VERSION")
214                 
215                 IF(LASTITEM MATCHES "BLENDER_SUBVERSION")
216                         SET(BLENDER_SUBVERSION ${ITEM})
217                 ENDIF(LASTITEM MATCHES "BLENDER_SUBVERSION")
218                 
219                 IF(LASTITEM MATCHES "BLENDER_MINVERSION")
220                         MATH(EXPR BLENDER_MINVERSION_MAJOR "${ITEM} / 100")
221                         MATH(EXPR BLENDER_MINVERSION_MINOR "${ITEM} % 100")
222                         SET(BLENDER_MINVERSION "${BLENDER_MINVERSION_MAJOR}.${BLENDER_MINVERSION_MINOR}")
223                 ENDIF(LASTITEM MATCHES "BLENDER_MINVERSION")
224                 
225                 IF(LASTITEM MATCHES "BLENDER_MINSUBVERSION")
226                         SET(BLENDER_MINSUBVERSION ${ITEM})
227                 ENDIF(LASTITEM MATCHES "BLENDER_MINSUBVERSION")
228
229                 SET(LASTITEM ${ITEM})
230         ENDFOREACH(ITEM ${CONTENT})
231         
232         MESSAGE(STATUS "Version major: ${BLENDER_VERSION_MAJOR}, Version minor: ${BLENDER_VERSION_MINOR}, Subversion: ${BLENDER_SUBVERSION}, Version: ${BLENDER_VERSION}")
233         MESSAGE(STATUS "Minversion major: ${BLENDER_MINVERSION_MAJOR}, Minversion minor: ${BLENDER_MINVERSION_MINOR}, MinSubversion: ${BLENDER_MINSUBVERSION}, Minversion: ${BLENDER_MINVERSION}")
234 ENDMACRO(GET_BLENDER_VERSION)