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