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