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