a2fae22a96368dbf1f5fc611c248a14831fba124
[blender.git] / build_files / cmake / platform / platform_win32.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.
25
26 add_definitions(-DWIN32)
27
28 if(NOT MSVC)
29         message(FATAL_ERROR "Compiler is unsupported")
30 endif()
31
32 # Libraries configuration for Windows when compiling with MSVC.
33
34 macro(warn_hardcoded_paths package_name
35         )
36         if(WITH_WINDOWS_FIND_MODULES)
37                 message(WARNING "Using HARDCODED ${package_name} locations")
38         endif()
39 endmacro()
40
41 macro(windows_find_package package_name
42         )
43         if(WITH_WINDOWS_FIND_MODULES)
44                 find_package(${package_name})
45         endif()
46 endmacro()
47
48 macro(find_package_wrapper)
49         if(WITH_WINDOWS_FIND_MODULES)
50                 find_package(${ARGV})
51         endif()
52 endmacro()
53
54 add_definitions(-DWIN32)
55
56 # Needed, otherwise system encoding causes utf-8 encoding to fail in some cases (C4819)
57 add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
58 add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
59
60 # Minimum MSVC Version
61 if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
62         if(MSVC_VERSION EQUAL 1800)
63                 set(_min_ver "18.0.31101")
64                 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${_min_ver})
65                         message(FATAL_ERROR
66                                 "Visual Studio 2013 (Update 4, ${_min_ver}) required, "
67                                 "found (${CMAKE_CXX_COMPILER_VERSION})")
68                 endif()
69         endif()
70         if(MSVC_VERSION EQUAL 1900)
71                 set(_min_ver "19.0.24210")
72                 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${_min_ver})
73                         message(FATAL_ERROR
74                                 "Visual Studio 2015 (Update 3, ${_min_ver}) required, "
75                                 "found (${CMAKE_CXX_COMPILER_VERSION})")
76                 endif()
77         endif()
78 endif()
79 unset(_min_ver)
80
81 # needed for some MSVC installations
82 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
83 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
84 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
85
86 list(APPEND PLATFORM_LINKLIBS
87         ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32
88         advapi32 shfolder shell32 ole32 oleaut32 uuid psapi Dbghelp
89 )
90
91 if(WITH_INPUT_IME)
92         list(APPEND PLATFORM_LINKLIBS imm32)
93 endif()
94
95 add_definitions(
96         -D_CRT_NONSTDC_NO_DEPRECATE
97         -D_CRT_SECURE_NO_DEPRECATE
98         -D_SCL_SECURE_NO_DEPRECATE
99         -D_CONSOLE
100         -D_LIB
101 )
102
103 # MSVC11 needs _ALLOW_KEYWORD_MACROS to build
104 add_definitions(-D_ALLOW_KEYWORD_MACROS)
105
106 # We want to support Vista level ABI
107 add_definitions(-D_WIN32_WINNT=0x600)
108
109 # Make cmake find the msvc redistributables
110 set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP FALSE)
111 set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE)
112 set(CMAKE_INSTALL_OPENMP_LIBRARIES ${WITH_OPENMP})
113 set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
114 include(InstallRequiredSystemLibraries)
115
116 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /nologo /J /Gd /MP /EHsc")
117 set(CMAKE_C_FLAGS     "${CMAKE_C_FLAGS} /nologo /J /Gd /MP")
118
119 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
120 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
121 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
122 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
123 set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MT")
124 set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /MT")
125 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MT")
126 set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MT")
127
128 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO ")
129 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib ")
130
131 # Ignore meaningless for us linker warnings.
132 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /ignore:4049 /ignore:4217 /ignore:4221")
133 set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221")
134
135 if(CMAKE_CL_64)
136         set(PLATFORM_LINKFLAGS "/MACHINE:X64 ${PLATFORM_LINKFLAGS}")
137 else()
138         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
139 endif()
140
141 set(PLATFORM_LINKFLAGS_DEBUG "/IGNORE:4099 /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
142
143 if(NOT DEFINED LIBDIR)
144
145         # Setup 64bit and 64bit windows systems
146         if(CMAKE_CL_64)
147                 message(STATUS "64 bit compiler detected.")
148                 set(LIBDIR_BASE "win64")
149         else()
150                 message(STATUS "32 bit compiler detected.")
151                 set(LIBDIR_BASE "windows")
152         endif()
153         # Can be 1910..1912
154         if(MSVC_VERSION GREATER 1909)
155                 message(STATUS "Visual Studio 2017 detected.")
156                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc14)
157         elseif(MSVC_VERSION EQUAL 1900)
158                 message(STATUS "Visual Studio 2015 detected.")
159                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc14)
160         else()
161                 message(STATUS "Visual Studio 2013 detected.")
162                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc12)
163         endif()
164 else()
165         message(STATUS "Using pre-compiled LIBDIR: ${LIBDIR}")
166 endif()
167 if(NOT EXISTS "${LIBDIR}/")
168         message(FATAL_ERROR "Windows requires pre-compiled libs at: '${LIBDIR}'")
169 endif()
170
171 # Add each of our libraries to our cmake_prefix_path so find_package() could work
172 file(GLOB children RELATIVE ${LIBDIR} ${LIBDIR}/*)
173 foreach(child ${children})
174         if(IS_DIRECTORY ${LIBDIR}/${child})
175                 list(APPEND CMAKE_PREFIX_PATH  ${LIBDIR}/${child})
176         endif()
177 endforeach()
178
179 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
180 set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz_st.lib)
181 set(ZLIB_INCLUDE_DIR ${LIBDIR}/zlib/include)
182 set(ZLIB_LIBRARY ${LIBDIR}/zlib/lib/libz_st.lib)
183 set(ZLIB_DIR ${LIBDIR}/zlib)
184
185 windows_find_package(zlib) # we want to find before finding things that depend on it like png
186 windows_find_package(png)
187
188 if(NOT PNG_FOUND)
189         warn_hardcoded_paths(libpng)
190         set(PNG_PNG_INCLUDE_DIR ${LIBDIR}/png/include)
191         set(PNG_LIBRARIES ${LIBDIR}/png/lib/libpng.lib)
192         set(PNG "${LIBDIR}/png")
193         set(PNG_INCLUDE_DIRS "${PNG}/include")
194         set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
195 endif()
196
197 set(JPEG_NAMES ${JPEG_NAMES} libjpeg)
198 windows_find_package(jpeg REQUIRED)
199 if(NOT JPEG_FOUND)
200         warn_hardcoded_paths(jpeg)
201         set(JPEG_INCLUDE_DIR ${LIBDIR}/jpeg/include)
202         set(JPEG_LIBRARIES ${LIBDIR}/jpeg/lib/libjpeg.lib)
203 endif()
204
205 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
206 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
207
208 set(FREETYPE ${LIBDIR}/freetype)
209 set(FREETYPE_INCLUDE_DIRS
210         ${LIBDIR}/freetype/include
211         ${LIBDIR}/freetype/include/freetype2
212 )
213 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
214 windows_find_package(freetype REQUIRED)
215
216 if(WITH_FFTW3)
217         set(FFTW3 ${LIBDIR}/fftw3)
218         set(FFTW3_LIBRARIES ${FFTW3}/lib/libfftw.lib)
219         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
220         set(FFTW3_LIBPATH ${FFTW3}/lib)
221 endif()
222
223 if(WITH_OPENCOLLADA)
224         set(OPENCOLLADA ${LIBDIR}/opencollada)
225
226         set(OPENCOLLADA_INCLUDE_DIRS
227                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
228                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
229                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
230                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
231                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
232         )
233
234         set(OPENCOLLADA_LIBRARIES
235                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader.lib
236                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework.lib
237                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils.lib
238                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter.lib
239                 ${OPENCOLLADA}/lib/opencollada/MathMLSolver.lib
240                 ${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser.lib
241                 ${OPENCOLLADA}/lib/opencollada/xml.lib
242                 ${OPENCOLLADA}/lib/opencollada/buffer.lib
243                 ${OPENCOLLADA}/lib/opencollada/ftoa.lib
244         )
245
246         if(NOT WITH_LLVM)
247                 list(APPEND OPENCOLLADA_LIBRARIES ${OPENCOLLADA}/lib/opencollada/UTF.lib)
248         endif()
249
250         set(PCRE_LIBRARIES
251                 ${OPENCOLLADA}/lib/opencollada/pcre.lib
252         )
253 endif()
254
255 if(WITH_CODEC_FFMPEG)
256         set(FFMPEG_INCLUDE_DIRS
257                 ${LIBDIR}/ffmpeg/include
258                 ${LIBDIR}/ffmpeg/include/msvc
259         )
260         windows_find_package(FFMPEG)
261         if(NOT FFMPEG_FOUND)
262                 warn_hardcoded_paths(ffmpeg)
263                 set(FFMPEG_LIBRARY_VERSION 57)
264                 set(FFMPEG_LIBRARY_VERSION_AVU 55)
265                 set(FFMPEG_LIBRARIES
266                         ${LIBDIR}/ffmpeg/lib/avcodec.lib
267                         ${LIBDIR}/ffmpeg/lib/avformat.lib
268                         ${LIBDIR}/ffmpeg/lib/avdevice.lib
269                         ${LIBDIR}/ffmpeg/lib/avutil.lib
270                         ${LIBDIR}/ffmpeg/lib/swscale.lib
271                         )
272         endif()
273 endif()
274
275 if(WITH_IMAGE_OPENEXR)
276         set(OPENEXR_ROOT_DIR ${LIBDIR}/openexr)
277         set(OPENEXR_VERSION "2.1")
278         windows_find_package(OPENEXR REQUIRED)
279         if(NOT OPENEXR_FOUND)
280                 warn_hardcoded_paths(OpenEXR)
281                 set(OPENEXR ${LIBDIR}/openexr)
282                 set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
283                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR} ${OPENEXR}/include/OpenEXR)
284                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
285                 set(OPENEXR_LIBRARIES
286                         optimized ${OPENEXR_LIBPATH}/Iex-2_2.lib
287                         optimized ${OPENEXR_LIBPATH}/Half.lib
288                         optimized ${OPENEXR_LIBPATH}/IlmImf-2_2.lib
289                         optimized ${OPENEXR_LIBPATH}/Imath-2_2.lib
290                         optimized ${OPENEXR_LIBPATH}/IlmThread-2_2.lib
291                         debug ${OPENEXR_LIBPATH}/Iex-2_2_d.lib
292                         debug ${OPENEXR_LIBPATH}/Half_d.lib
293                         debug ${OPENEXR_LIBPATH}/IlmImf-2_2_d.lib
294                         debug ${OPENEXR_LIBPATH}/Imath-2_2_d.lib
295                         debug ${OPENEXR_LIBPATH}/IlmThread-2_2_d.lib
296                 )
297         endif()
298 endif()
299
300 if(WITH_IMAGE_TIFF)
301         # Try to find tiff first then complain and set static and maybe wrong paths
302         windows_find_package(TIFF)
303         if(NOT TIFF_FOUND)
304                 warn_hardcoded_paths(libtiff)
305                 set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
306                 set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
307         endif()
308 endif()
309
310 if(WITH_JACK)
311         set(JACK_INCLUDE_DIRS
312                 ${LIBDIR}/jack/include/jack
313                 ${LIBDIR}/jack/include
314         )
315         set(JACK_LIBRARIES optimized ${LIBDIR}/jack/lib/libjack.lib debug ${LIBDIR}/jack/lib/libjack_d.lib)
316 endif()
317
318 if(WITH_PYTHON)
319         set(PYTHON_VERSION 3.6) # CACHE STRING)
320
321         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
322         # Use shared libs for vc2008 and vc2010 until we actually have vc2010 libs
323         set(PYTHON_LIBRARY ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}.lib)
324         unset(_PYTHON_VERSION_NO_DOTS)
325
326         # Shared includes for both vc2008 and vc2010
327         set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/include/python${PYTHON_VERSION})
328
329         # uncached vars
330         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
331         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
332 endif()
333
334 if(WITH_BOOST)
335         if(WITH_CYCLES_OSL)
336                 set(boost_extra_libs wave)
337         endif()
338         if(WITH_INTERNATIONAL)
339                 list(APPEND boost_extra_libs locale)
340         endif()
341         if(WITH_OPENVDB)
342                 list(APPEND boost_extra_libs iostreams)
343         endif()
344         set(Boost_USE_STATIC_RUNTIME ON) # prefix lib
345         set(Boost_USE_MULTITHREADED ON) # suffix -mt
346         set(Boost_USE_STATIC_LIBS ON) # suffix -s
347         if(WITH_WINDOWS_FIND_MODULES)
348                 find_package(Boost COMPONENTS date_time filesystem thread regex system ${boost_extra_libs})
349         endif()
350         if(NOT Boost_FOUND)
351                 warn_hardcoded_paths(BOOST)
352                 set(BOOST ${LIBDIR}/boost)
353                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
354                 if(MSVC12)
355                         set(BOOST_LIBPATH ${BOOST}/lib)
356                         set(BOOST_POSTFIX "vc120-mt-s-1_60.lib")
357                         set(BOOST_DEBUG_POSTFIX "vc120-mt-sgd-1_60.lib")
358                 else()
359                         set(BOOST_LIBPATH ${BOOST}/lib)
360                         set(BOOST_POSTFIX "vc140-mt-s-1_60.lib")
361                         set(BOOST_DEBUG_POSTFIX "vc140-mt-sgd-1_60.lib")
362                 endif()
363                 set(BOOST_LIBRARIES
364                         optimized ${BOOST_LIBPATH}/libboost_date_time-${BOOST_POSTFIX}
365                         optimized ${BOOST_LIBPATH}/libboost_filesystem-${BOOST_POSTFIX}
366                         optimized ${BOOST_LIBPATH}/libboost_regex-${BOOST_POSTFIX}
367                         optimized ${BOOST_LIBPATH}/libboost_system-${BOOST_POSTFIX}
368                         optimized ${BOOST_LIBPATH}/libboost_thread-${BOOST_POSTFIX}
369                         optimized ${BOOST_LIBPATH}/libboost_chrono-${BOOST_POSTFIX}
370                         debug ${BOOST_LIBPATH}/libboost_date_time-${BOOST_DEBUG_POSTFIX}
371                         debug ${BOOST_LIBPATH}/libboost_filesystem-${BOOST_DEBUG_POSTFIX}
372                         debug ${BOOST_LIBPATH}/libboost_regex-${BOOST_DEBUG_POSTFIX}
373                         debug ${BOOST_LIBPATH}/libboost_system-${BOOST_DEBUG_POSTFIX}
374                         debug ${BOOST_LIBPATH}/libboost_thread-${BOOST_DEBUG_POSTFIX}
375                         debug ${BOOST_LIBPATH}/libboost_chrono-${BOOST_DEBUG_POSTFIX}
376                 )
377                 if(WITH_CYCLES_OSL)
378                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
379                                 optimized ${BOOST_LIBPATH}/libboost_wave-${BOOST_POSTFIX}
380                                 debug ${BOOST_LIBPATH}/libboost_wave-${BOOST_DEBUG_POSTFIX})
381                 endif()
382                 if(WITH_INTERNATIONAL)
383                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
384                                 optimized ${BOOST_LIBPATH}/libboost_locale-${BOOST_POSTFIX}
385                                 debug ${BOOST_LIBPATH}/libboost_locale-${BOOST_DEBUG_POSTFIX})
386                 endif()
387         else() # we found boost using find_package
388                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
389                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
390                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
391         endif()
392         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
393 endif()
394
395 if(WITH_OPENIMAGEIO)
396         windows_find_package(OpenImageIO)
397         set(OPENIMAGEIO ${LIBDIR}/openimageio)
398         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
399         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
400         set(OIIO_OPTIMIZED optimized ${OPENIMAGEIO_LIBPATH}/OpenImageIO.lib optimized ${OPENIMAGEIO_LIBPATH}/OpenImageIO_Util.lib)
401         set(OIIO_DEBUG debug ${OPENIMAGEIO_LIBPATH}/OpenImageIO_d.lib debug ${OPENIMAGEIO_LIBPATH}/OpenImageIO_Util_d.lib)
402         set(OPENIMAGEIO_LIBRARIES ${OIIO_OPTIMIZED} ${OIIO_DEBUG})
403         
404         set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0")
405         set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
406         set(OPENIMAGEIO_IDIFF "${OPENIMAGEIO}/bin/idiff.exe")
407         add_definitions(-DOIIO_STATIC_BUILD)
408         add_definitions(-DOIIO_NO_SSE=1)
409 endif()
410
411 if(WITH_LLVM)
412         set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH     "Path to the LLVM installation")
413         file(GLOB LLVM_LIBRARY_OPTIMIZED ${LLVM_ROOT_DIR}/lib/*.lib)
414
415         if(EXISTS ${LLVM_ROOT_DIR}/debug/lib)
416                 foreach(LLVM_OPTIMIZED_LIB ${LLVM_LIBRARY_OPTIMIZED})
417                         get_filename_component(LIBNAME ${LLVM_OPTIMIZED_LIB} ABSOLUTE)
418                         list(APPEND LLVM_LIBS optimized ${LIBNAME})
419                 endforeach(LLVM_OPTIMIZED_LIB)
420
421                 file(GLOB LLVM_LIBRARY_DEBUG ${LLVM_ROOT_DIR}/debug/lib/*.lib)
422
423                 foreach(LLVM_DEBUG_LIB ${LLVM_LIBRARY_DEBUG})
424                         get_filename_component(LIBNAME ${LLVM_DEBUG_LIB} ABSOLUTE)
425                         list(APPEND LLVM_LIBS debug ${LIBNAME})
426                 endforeach(LLVM_DEBUG_LIB)
427
428                 set(LLVM_LIBRARY ${LLVM_LIBS})
429         else()
430                 message(WARNING "LLVM debug libs not present on this system. Using release libs for debug builds.")
431                 set(LLVM_LIBRARY ${LLVM_LIBRARY_OPTIMIZED})
432         endif()
433
434 endif()
435
436 if(WITH_OPENCOLORIO)
437         set(OPENCOLORIO ${LIBDIR}/opencolorio)
438         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
439         set(OPENCOLORIO_LIBPATH ${LIBDIR}/opencolorio/lib)
440         set(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBPATH}/OpenColorIO.lib)
441         set(OPENCOLORIO_DEFINITIONS)
442 endif()
443
444 if(WITH_OPENVDB)
445         set(BLOSC_LIBRARIES optimized ${LIBDIR}/blosc/lib/libblosc.lib debug ${LIBDIR}/blosc/lib/libblosc_d.lib)
446         set(TBB_LIBRARIES optimized ${LIBDIR}/tbb/lib/tbb.lib debug ${LIBDIR}/tbb/lib/tbb_debug.lib)
447         set(TBB_INCLUDE_DIR ${LIBDIR}/tbb/include)
448         set(OPENVDB ${LIBDIR}/openvdb)
449         set(OPENVDB_LIBPATH ${LIBDIR}/openvdb/lib)
450         set(OPENVDB_INCLUDE_DIRS ${OPENVDB}/include ${TBB_INCLUDE_DIR})
451         set(OPENVDB_LIBRARIES optimized ${OPENVDB_LIBPATH}/openvdb.lib debug ${OPENVDB_LIBPATH}/openvdb_d.lib ${TBB_LIBRARIES} ${BLOSC_LIBRARIES})
452         
453 endif()
454
455 if(WITH_ALEMBIC)
456         set(ALEMBIC ${LIBDIR}/alembic)
457         set(ALEMBIC_INCLUDE_DIR ${ALEMBIC}/include)
458         set(ALEMBIC_INCLUDE_DIRS ${ALEMBIC_INCLUDE_DIR})
459         set(ALEMBIC_LIBPATH ${ALEMBIC}/lib)
460         set(ALEMBIC_LIBRARIES optimized ${ALEMBIC}/lib/alembic.lib debug ${ALEMBIC}/lib/alembic_d.lib)
461         set(ALEMBIC_FOUND 1)
462 endif()
463
464 if(WITH_MOD_CLOTH_ELTOPO)
465         set(LAPACK ${LIBDIR}/lapack)
466         # set(LAPACK_INCLUDE_DIR ${LAPACK}/include)
467         set(LAPACK_LIBPATH ${LAPACK}/lib)
468         set(LAPACK_LIBRARIES
469                 ${LIBDIR}/lapack/lib/libf2c.lib
470                 ${LIBDIR}/lapack/lib/clapack_nowrap.lib
471                 ${LIBDIR}/lapack/lib/BLAS_nowrap.lib
472         )
473 endif()
474
475 if(WITH_OPENSUBDIV OR WITH_CYCLES_OPENSUBDIV)
476         set(OPENSUBDIV_INCLUDE_DIR ${LIBDIR}/opensubdiv/include)
477         set(OPENSUBDIV_LIBPATH ${LIBDIR}/opensubdiv/lib)
478         set(OPENSUBDIV_LIBRARIES
479                 optimized ${OPENSUBDIV_LIBPATH}/osdCPU.lib
480                 optimized ${OPENSUBDIV_LIBPATH}/osdGPU.lib
481                 debug ${OPENSUBDIV_LIBPATH}/osdCPU_d.lib
482                 debug ${OPENSUBDIV_LIBPATH}/osdGPU_d.lib
483         )
484         set(OPENSUBDIV_HAS_OPENMP TRUE)
485         set(OPENSUBDIV_HAS_TBB FALSE)
486         set(OPENSUBDIV_HAS_OPENCL TRUE)
487         set(OPENSUBDIV_HAS_CUDA FALSE)
488         set(OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK TRUE)
489         set(OPENSUBDIV_HAS_GLSL_COMPUTE TRUE)
490         windows_find_package(OpenSubdiv)
491 endif()
492
493 if(WITH_SDL)
494         set(SDL ${LIBDIR}/sdl)
495         set(SDL_INCLUDE_DIR ${SDL}/include)
496         set(SDL_LIBPATH ${SDL}/lib)
497         set(SDL_LIBRARY ${SDL_LIBPATH}/SDL2.lib)
498 endif()
499
500 # Audio IO
501 if(WITH_SYSTEM_AUDASPACE)
502         set(AUDASPACE_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
503         set(AUDASPACE_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace.lib)
504         set(AUDASPACE_C_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
505         set(AUDASPACE_C_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace-c.lib)
506         set(AUDASPACE_PY_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
507         set(AUDASPACE_PY_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace-py.lib)
508 endif()
509
510 # used in many places so include globally, like OpenGL
511 blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
512
513 #find signtool
514 set(ProgramFilesX86_NAME "ProgramFiles(x86)") #env dislikes the ( )
515 find_program(SIGNTOOL_EXE signtool
516         HINTS
517                 "$ENV{${ProgramFilesX86_NAME}}/Windows Kits/10/bin/x86/"
518                 "$ENV{ProgramFiles}/Windows Kits/10/bin/x86/"
519                 "$ENV{${ProgramFilesX86_NAME}}/Windows Kits/8.1/bin/x86/"
520                 "$ENV{ProgramFiles}/Windows Kits/8.1/bin/x86/"
521                 "$ENV{${ProgramFilesX86_NAME}}/Windows Kits/8.0/bin/x86/"
522                 "$ENV{ProgramFiles}/Windows Kits/8.0/bin/x86/"
523 )
524 set(WINTAB_INC ${LIBDIR}/wintab/include)
525
526 if(WITH_OPENAL)
527         set(OPENAL ${LIBDIR}/openal)
528         set(OPENALDIR ${LIBDIR}/openal)
529         set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
530         set(OPENAL_LIBPATH ${OPENAL}/lib)
531         if(MSVC)
532                 set(OPENAL_LIBRARY ${OPENAL_LIBPATH}/openal32.lib)
533         else()
534                 set(OPENAL_LIBRARY ${OPENAL_LIBPATH}/wrap_oal.lib)
535         endif()
536         
537 endif()
538
539 if(WITH_CODEC_SNDFILE)
540         set(SNDFILE ${LIBDIR}/sndfile)
541         set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
542         set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
543         set(SNDFILE_LIBRARIES ${SNDFILE_LIBPATH}/libsndfile-1.lib)
544         
545 endif()
546
547 if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
548         add_definitions(-D__SSE__ -D__MMX__)
549 endif()
550
551 if(WITH_CYCLES_OSL)
552         set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
553
554         find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
555         find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
556         find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
557         find_library(OSL_LIB_EXEC_DEBUG NAMES oslexec_d PATHS ${CYCLES_OSL}/lib)
558         find_library(OSL_LIB_COMP_DEBUG NAMES oslcomp_d PATHS ${CYCLES_OSL}/lib)
559         find_library(OSL_LIB_QUERY_DEBUG NAMES oslquery_d PATHS ${CYCLES_OSL}/lib)
560         list(APPEND OSL_LIBRARIES
561                 optimized ${OSL_LIB_COMP}
562                 optimized ${OSL_LIB_EXEC}
563                 optimized ${OSL_LIB_QUERY}
564                 debug ${OSL_LIB_EXEC_DEBUG}
565                 debug ${OSL_LIB_COMP_DEBUG}
566                 debug ${OSL_LIB_QUERY_DEBUG}
567         )
568         find_path(OSL_INCLUDE_DIR OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
569         find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
570
571         if(OSL_INCLUDE_DIR AND OSL_LIBRARIES AND OSL_COMPILER)
572                 set(OSL_FOUND TRUE)
573         else()
574                 message(STATUS "OSL not found")
575                 set(WITH_CYCLES_OSL OFF)
576         endif()
577 endif()