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