216568bd0690e9ac4a446b9ec641069d5c4c6823
[blender-staging.git] / build_files / cmake / platform / platform_win32_mingw.cmake
1 # ***** BEGIN GPL LICENSE BLOCK *****
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # The Original Code is Copyright (C) 2016, Blender Foundation
18 # All rights reserved.
19 #
20 # Contributor(s): Sergey Sharybin.
21 #
22 # ***** END GPL LICENSE BLOCK *****
23
24 # Libraries configuration for Windows when compiling with MinGW.
25
26 # keep GCC specific stuff here
27 include(CheckCSourceCompiles)
28 # Setup 64bit and 64bit windows systems
29 CHECK_C_SOURCE_COMPILES("
30         #ifndef __MINGW64__
31         #error
32         #endif
33         int main(void) { return 0; }
34         "
35         WITH_MINGW64
36 )
37
38 if(NOT DEFINED LIBDIR)
39         if(WITH_MINGW64)
40                 message(STATUS "Compiling for 64 bit with MinGW-w64.")
41                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
42         else()
43                 message(STATUS "Compiling for 32 bit with MinGW-w32.")
44                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
45
46                 if(WITH_RAYOPTIMIZATION)
47                         message(WARNING "MinGW-w32 is known to be unstable with 'WITH_RAYOPTIMIZATION' option enabled.")
48                 endif()
49         endif()
50 else()
51         message(STATUS "Using pre-compiled LIBDIR: ${LIBDIR}")
52 endif()
53 if(NOT EXISTS "${LIBDIR}/")
54         message(FATAL_ERROR "Windows requires pre-compiled libs at: '${LIBDIR}'")
55 endif()
56
57 list(APPEND PLATFORM_LINKLIBS
58         -lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32
59         -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi -ldbghelp
60 )
61
62 if(WITH_INPUT_IME)
63         list(APPEND PLATFORM_LINKLIBS -limm32)
64 endif()
65
66 set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
67
68 if(WITH_MINGW64)
69         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
70         list(APPEND PLATFORM_LINKLIBS -lpthread)
71
72         add_definitions(-DFREE_WINDOWS64 -DMS_WIN64)
73 endif()
74
75 add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
76
77 add_definitions(-DFREE_WINDOWS)
78
79 set(PNG "${LIBDIR}/png")
80 set(PNG_INCLUDE_DIRS "${PNG}/include")
81 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
82
83 if(WITH_MINGW64)
84         set(JPEG_LIBRARIES jpeg)
85 else()
86         set(JPEG_LIBRARIES libjpeg)
87 endif()
88 set(PNG_LIBRARIES png)
89
90 set(ZLIB ${LIBDIR}/zlib)
91 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
92 set(ZLIB_LIBPATH ${ZLIB}/lib)
93 set(ZLIB_LIBRARIES z)
94
95 set(JPEG "${LIBDIR}/jpeg")
96 set(JPEG_INCLUDE_DIR "${JPEG}/include")
97 set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
98
99 # comes with own pthread library
100 if(NOT WITH_MINGW64)
101         set(PTHREADS ${LIBDIR}/pthreads)
102         #set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
103         set(PTHREADS_LIBPATH ${PTHREADS}/lib)
104         set(PTHREADS_LIBRARIES pthreadGC2)
105 endif()
106
107 set(FREETYPE ${LIBDIR}/freetype)
108 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
109 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
110 set(FREETYPE_LIBRARY freetype)
111
112 if(WITH_FFTW3)
113         set(FFTW3 ${LIBDIR}/fftw3)
114         set(FFTW3_LIBRARIES fftw3)
115         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
116         set(FFTW3_LIBPATH ${FFTW3}/lib)
117 endif()
118
119 if(WITH_OPENCOLLADA)
120         set(OPENCOLLADA ${LIBDIR}/opencollada)
121         set(OPENCOLLADA_INCLUDE_DIRS
122                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
123                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
124                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
125                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
126                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
127         )
128         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib/opencollada)
129         set(OPENCOLLADA_LIBRARIES
130                 OpenCOLLADAStreamWriter
131                 OpenCOLLADASaxFrameworkLoader
132                 OpenCOLLADAFramework
133                 OpenCOLLADABaseUtils
134                 GeneratedSaxParser
135                 UTF MathMLSolver buffer ftoa xml
136         )
137         set(PCRE_LIBRARIES pcre)
138 endif()
139
140 if(WITH_CODEC_FFMPEG)
141         set(FFMPEG ${LIBDIR}/ffmpeg)
142         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
143         if(WITH_MINGW64)
144                 set(FFMPEG_LIBRARIES avcodec.dll avformat.dll avdevice.dll avutil.dll swscale.dll swresample.dll)
145         else()
146                 set(FFMPEG_LIBRARIES avcodec-55 avformat-55 avdevice-55 avutil-52 swscale-2)
147         endif()
148         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
149 endif()
150
151 if(WITH_IMAGE_OPENEXR)
152         set(OPENEXR ${LIBDIR}/openexr)
153         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
154         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
155         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
156         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
157 endif()
158
159 if(WITH_IMAGE_TIFF)
160         set(TIFF ${LIBDIR}/tiff)
161         set(TIFF_LIBRARY tiff)
162         set(TIFF_INCLUDE_DIR ${TIFF}/include)
163         set(TIFF_LIBPATH ${TIFF}/lib)
164 endif()
165
166 if(WITH_JACK)
167         set(JACK ${LIBDIR}/jack)
168         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
169         set(JACK_LIBRARIES jack)
170         set(JACK_LIBPATH ${JACK}/lib)
171
172         # TODO, gives linking errors, force off
173         set(WITH_JACK OFF)
174 endif()
175
176 if(WITH_PYTHON)
177         # normally cached but not since we include them with blender
178         set(PYTHON_VERSION 3.5) #  CACHE STRING)
179         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
180         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
181         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}mw.lib")  # CACHE FILEPATH)
182         unset(_PYTHON_VERSION_NO_DOTS)
183
184         # uncached vars
185         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
186         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
187 endif()
188
189 if(WITH_BOOST)
190         set(BOOST ${LIBDIR}/boost)
191         set(BOOST_INCLUDE_DIR ${BOOST}/include)
192         if(WITH_MINGW64)
193                 set(BOOST_POSTFIX "mgw47-mt-s-1_49")
194                 set(BOOST_DEBUG_POSTFIX "mgw47-mt-sd-1_49")
195         else()
196                 set(BOOST_POSTFIX "mgw46-mt-s-1_49")
197                 set(BOOST_DEBUG_POSTFIX "mgw46-mt-sd-1_49")
198         endif()
199         set(BOOST_LIBRARIES
200                 optimized boost_date_time-${BOOST_POSTFIX} boost_filesystem-${BOOST_POSTFIX}
201                 boost_regex-${BOOST_POSTFIX}
202                 boost_system-${BOOST_POSTFIX} boost_thread-${BOOST_POSTFIX}
203                 debug boost_date_time-${BOOST_DEBUG_POSTFIX} boost_filesystem-${BOOST_DEBUG_POSTFIX}
204                 boost_regex-${BOOST_DEBUG_POSTFIX}
205                 boost_system-${BOOST_DEBUG_POSTFIX} boost_thread-${BOOST_DEBUG_POSTFIX})
206         if(WITH_INTERNATIONAL)
207                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
208                         optimized boost_locale-${BOOST_POSTFIX}
209                         debug boost_locale-${BOOST_DEBUG_POSTFIX}
210                 )
211         endif()
212         if(WITH_CYCLES_OSL)
213                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
214                         optimized boost_wave-${BOOST_POSTFIX}
215                         debug boost_wave-${BOOST_DEBUG_POSTFIX}
216                 )
217         endif()
218         set(BOOST_LIBPATH ${BOOST}/lib)
219         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB -DBOOST_THREAD_USE_LIB ")
220 endif()
221
222 if(WITH_OPENIMAGEIO)
223         set(OPENIMAGEIO ${LIBDIR}/openimageio)
224         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
225         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
226         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
227         set(OPENIMAGEIO_DEFINITIONS "")
228         set(OPENIMAGEIO_IDIFF "${OPENIMAGEIO}/bin/idiff.exe")
229 endif()
230
231 if(WITH_LLVM)
232         set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH     "Path to the LLVM installation")
233         set(LLVM_LIBPATH ${LLVM_ROOT_DIR}/lib)
234         # Explicitly set llvm lib order.
235         #---- WARNING ON GCC ORDER OF LIBS IS IMPORTANT, DO NOT CHANGE! ---------
236         set(LLVM_LIBRARY LLVMSelectionDAG LLVMCodeGen LLVMScalarOpts LLVMAnalysis LLVMArchive
237                 LLVMAsmParser LLVMAsmPrinter
238                 LLVMBitReader LLVMBitWriter
239                 LLVMDebugInfo LLVMExecutionEngine
240                 LLVMInstCombine LLVMInstrumentation
241                 LLVMInterpreter LLVMJIT
242                 LLVMLinker LLVMMC
243                 LLVMMCDisassembler LLVMMCJIT
244                 LLVMMCParser LLVMObject
245                 LLVMRuntimeDyld
246                 LLVMSupport
247                 LLVMTableGen LLVMTarget
248                 LLVMTransformUtils LLVMVectorize
249                 LLVMX86AsmParser LLVMX86AsmPrinter
250                 LLVMX86CodeGen LLVMX86Desc
251                 LLVMX86Disassembler LLVMX86Info
252                 LLVMX86Utils LLVMipa
253                 LLVMipo LLVMCore)
254         # imagehelp is needed by LLVM 3.1 on MinGW, check lib\Support\Windows\Signals.inc
255         list(APPEND PLATFORM_LINKLIBS -limagehlp)
256 endif()
257
258 if(WITH_OPENCOLORIO)
259         set(OPENCOLORIO ${LIBDIR}/opencolorio)
260         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
261         set(OPENCOLORIO_LIBRARIES OpenColorIO)
262         set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
263         set(OPENCOLORIO_DEFINITIONS)
264 endif()
265
266 if(WITH_SDL)
267         set(SDL ${LIBDIR}/sdl)
268         set(SDL_INCLUDE_DIR ${SDL}/include)
269         set(SDL_LIBRARY SDL)
270         set(SDL_LIBPATH ${SDL}/lib)
271 endif()
272
273 if(WITH_OPENVDB)
274         set(OPENVDB ${LIBDIR}/openvdb)
275         set(OPENVDB_INCLUDE_DIRS ${OPENVDB}/include)
276         set(OPENVDB_LIBRARIES openvdb ${TBB_LIBRARIES})
277         set(OPENVDB_LIBPATH ${LIBDIR}/openvdb/lib)
278         set(OPENVDB_DEFINITIONS)
279 endif()
280
281 if(WITH_ALEMBIC)
282         # TODO(sergey): For until someone drops by and compiles libraries for
283         # MinGW we allow users to compile their own Alembic library and use
284         # that via find_package(),
285         #
286         # Once precompiled libraries are there we'll use hardcoded locations.
287         find_package_wrapper(Alembic)
288         if(WITH_ALEMBIC_HDF5)
289                 set(HDF5_ROOT_DIR ${LIBDIR}/hdf5)
290                 find_package_wrapper(HDF5)
291         endif()
292         if(NOT ALEMBIC_FOUND OR (WITH_ALEMBIC_HDF5 AND NOT HDF5_FOUND))
293                 set(WITH_ALEMBIC OFF)
294                 set(WITH_ALEMBIC_HDF5 OFF)
295         endif()
296 endif()
297
298 set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
299
300 ## DISABLE - causes linking errors
301 ## for re-distribution, so users dont need mingw installed
302 # set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-libgcc -static-libstdc++")