deps: python 3.7.4 for windows.
[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 # ***** END GPL LICENSE BLOCK *****
20
21 # Libraries configuration for Windows.
22
23 add_definitions(-DWIN32)
24
25 if(NOT MSVC)
26   message(FATAL_ERROR "Compiler is unsupported")
27 endif()
28
29 if(CMAKE_C_COMPILER_ID MATCHES "Clang")
30   set(MSVC_CLANG On)
31   set(VC_TOOLS_DIR $ENV{VCToolsRedistDir} CACHE STRING "Location of the msvc redistributables")
32   set(MSVC_REDIST_DIR ${VC_TOOLS_DIR})
33   if(DEFINED MSVC_REDIST_DIR)
34     file(TO_CMAKE_PATH ${MSVC_REDIST_DIR} MSVC_REDIST_DIR)
35   else()
36     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.")
37   endif()
38 endif()
39
40 set_property(GLOBAL PROPERTY USE_FOLDERS ${WINDOWS_USE_VISUAL_STUDIO_PROJECT_FOLDERS})
41
42 if(NOT WITH_PYTHON_MODULE)
43   set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT blender)
44 endif()
45
46 macro(warn_hardcoded_paths package_name
47   )
48   if(WITH_WINDOWS_FIND_MODULES)
49     message(WARNING "Using HARDCODED ${package_name} locations")
50   endif()
51 endmacro()
52
53 macro(windows_find_package package_name
54   )
55   if(WITH_WINDOWS_FIND_MODULES)
56     find_package(${package_name})
57   endif()
58 endmacro()
59
60 macro(find_package_wrapper)
61   if(WITH_WINDOWS_FIND_MODULES)
62     find_package(${ARGV})
63   endif()
64 endmacro()
65
66 add_definitions(-DWIN32)
67
68 # Needed, otherwise system encoding causes utf-8 encoding to fail in some cases (C4819)
69 add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
70 add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
71
72 # Minimum MSVC Version
73 if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
74   if(MSVC_VERSION EQUAL 1800)
75     set(_min_ver "18.0.31101")
76     if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${_min_ver})
77       message(FATAL_ERROR
78         "Visual Studio 2013 (Update 4, ${_min_ver}) required, "
79         "found (${CMAKE_CXX_COMPILER_VERSION})")
80     endif()
81   endif()
82   if(MSVC_VERSION EQUAL 1900)
83     set(_min_ver "19.0.24210")
84     if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${_min_ver})
85       message(FATAL_ERROR
86         "Visual Studio 2015 (Update 3, ${_min_ver}) required, "
87         "found (${CMAKE_CXX_COMPILER_VERSION})")
88     endif()
89   endif()
90 endif()
91 unset(_min_ver)
92
93 # needed for some MSVC installations
94 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
95 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
96 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
97
98 list(APPEND PLATFORM_LINKLIBS
99   ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32
100   advapi32 shfolder shell32 ole32 oleaut32 uuid psapi Dbghelp
101 )
102
103 if(WITH_INPUT_IME)
104   list(APPEND PLATFORM_LINKLIBS imm32)
105 endif()
106
107 add_definitions(
108   -D_CRT_NONSTDC_NO_DEPRECATE
109   -D_CRT_SECURE_NO_DEPRECATE
110   -D_SCL_SECURE_NO_DEPRECATE
111   -D_CONSOLE
112   -D_LIB
113 )
114
115 # MSVC11 needs _ALLOW_KEYWORD_MACROS to build
116 add_definitions(-D_ALLOW_KEYWORD_MACROS)
117
118 # We want to support Vista level ABI
119 add_definitions(-D_WIN32_WINNT=0x600)
120
121 # Make cmake find the msvc redistributables
122 set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP FALSE)
123 set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE)
124 set(CMAKE_INSTALL_OPENMP_LIBRARIES ${WITH_OPENMP})
125 set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
126 include(InstallRequiredSystemLibraries)
127
128 remove_cc_flag("/MDd" "/MD")
129
130 if(MSVC_CLANG) # Clangs version of cl doesn't support all flags
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 #JMC is available on msvc 15.8 (1915) and up
148 if(MSVC_VERSION GREATER 1914 AND NOT MSVC_CLANG)
149   set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /JMC")
150 endif()
151
152 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO ")
153 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib ")
154
155 # Ignore meaningless for us linker warnings.
156 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /ignore:4049 /ignore:4217 /ignore:4221")
157 set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221")
158
159 if(CMAKE_CL_64)
160   set(PLATFORM_LINKFLAGS "/MACHINE:X64 ${PLATFORM_LINKFLAGS}")
161 else()
162   set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
163 endif()
164
165 set(PLATFORM_LINKFLAGS_DEBUG "${PLATFORM_LINKFLAGS_DEBUG} /IGNORE:4099 /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
166
167 if(NOT DEFINED LIBDIR)
168
169   # Setup 64bit and 64bit windows systems
170   if(CMAKE_CL_64)
171     message(STATUS "64 bit compiler detected.")
172     set(LIBDIR_BASE "win64")
173   else()
174     message(FATAL_ERROR "32 bit compiler detected, blender no longer provides pre-build libraries for 32 bit windows, please set the LIBDIR cmake variable to your own library folder")
175   endif()
176   # Can be 1910..1912
177   if(MSVC_VERSION GREATER 1919)
178     message(STATUS "Visual Studio 2019 detected.")
179     set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc14)
180   elseif(MSVC_VERSION GREATER 1909)
181     message(STATUS "Visual Studio 2017 detected.")
182     set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc14)
183   elseif(MSVC_VERSION EQUAL 1900)
184     message(STATUS "Visual Studio 2015 detected.")
185     set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc14)
186   else()
187     message(STATUS "Visual Studio 2013 detected.")
188     set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc12)
189   endif()
190 else()
191   message(STATUS "Using pre-compiled LIBDIR: ${LIBDIR}")
192 endif()
193 if(NOT EXISTS "${LIBDIR}/")
194   message(FATAL_ERROR "Windows requires pre-compiled libs at: '${LIBDIR}'")
195 endif()
196
197 # Mark libdir as system headers with a lower warn level, to resolve some warnings
198 # that we have very little control over
199 if(MSVC_VERSION GREATER_EQUAL 1914 AND NOT MSVC_CLANG)
200   add_compile_options(/experimental:external /external:templates- /external:I "${LIBDIR}" /external:W0)
201 endif()
202
203 # Add each of our libraries to our cmake_prefix_path so find_package() could work
204 file(GLOB children RELATIVE ${LIBDIR} ${LIBDIR}/*)
205 foreach(child ${children})
206   if(IS_DIRECTORY ${LIBDIR}/${child})
207     list(APPEND CMAKE_PREFIX_PATH  ${LIBDIR}/${child})
208   endif()
209 endforeach()
210
211 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
212 set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz_st.lib)
213 set(ZLIB_INCLUDE_DIR ${LIBDIR}/zlib/include)
214 set(ZLIB_LIBRARY ${LIBDIR}/zlib/lib/libz_st.lib)
215 set(ZLIB_DIR ${LIBDIR}/zlib)
216
217 windows_find_package(zlib) # we want to find before finding things that depend on it like png
218 windows_find_package(png)
219
220 if(NOT PNG_FOUND)
221   warn_hardcoded_paths(libpng)
222   set(PNG_PNG_INCLUDE_DIR ${LIBDIR}/png/include)
223   set(PNG_LIBRARIES ${LIBDIR}/png/lib/libpng.lib)
224   set(PNG "${LIBDIR}/png")
225   set(PNG_INCLUDE_DIRS "${PNG}/include")
226   set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
227 endif()
228
229 set(JPEG_NAMES ${JPEG_NAMES} libjpeg)
230 windows_find_package(jpeg REQUIRED)
231 if(NOT JPEG_FOUND)
232   warn_hardcoded_paths(jpeg)
233   set(JPEG_INCLUDE_DIR ${LIBDIR}/jpeg/include)
234   set(JPEG_LIBRARIES ${LIBDIR}/jpeg/lib/libjpeg.lib)
235 endif()
236
237 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
238 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC3.lib)
239
240 set(FREETYPE ${LIBDIR}/freetype)
241 set(FREETYPE_INCLUDE_DIRS
242   ${LIBDIR}/freetype/include
243   ${LIBDIR}/freetype/include/freetype2
244 )
245 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
246 windows_find_package(freetype REQUIRED)
247
248 if(WITH_FFTW3)
249   set(FFTW3 ${LIBDIR}/fftw3)
250   set(FFTW3_LIBRARIES ${FFTW3}/lib/libfftw.lib)
251   set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
252   set(FFTW3_LIBPATH ${FFTW3}/lib)
253 endif()
254
255 if(WITH_OPENCOLLADA)
256   set(OPENCOLLADA ${LIBDIR}/opencollada)
257
258   set(OPENCOLLADA_INCLUDE_DIRS
259     ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
260     ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
261     ${OPENCOLLADA}/include/opencollada/COLLADAFramework
262     ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
263     ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
264   )
265
266   set(OPENCOLLADA_LIBRARIES
267     ${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader.lib
268     ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework.lib
269     ${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils.lib
270     ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter.lib
271     ${OPENCOLLADA}/lib/opencollada/MathMLSolver.lib
272     ${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser.lib
273     ${OPENCOLLADA}/lib/opencollada/xml.lib
274     ${OPENCOLLADA}/lib/opencollada/buffer.lib
275     ${OPENCOLLADA}/lib/opencollada/ftoa.lib
276   )
277
278   list(APPEND OPENCOLLADA_LIBRARIES ${OPENCOLLADA}/lib/opencollada/UTF.lib)
279
280   set(PCRE_LIBRARIES
281     ${OPENCOLLADA}/lib/opencollada/pcre.lib
282   )
283 endif()
284
285 if(WITH_CODEC_FFMPEG)
286   set(FFMPEG_INCLUDE_DIRS
287     ${LIBDIR}/ffmpeg/include
288     ${LIBDIR}/ffmpeg/include/msvc
289   )
290   windows_find_package(FFMPEG)
291   if(NOT FFMPEG_FOUND)
292     warn_hardcoded_paths(ffmpeg)
293     set(FFMPEG_LIBRARIES
294       ${LIBDIR}/ffmpeg/lib/avcodec.lib
295       ${LIBDIR}/ffmpeg/lib/avformat.lib
296       ${LIBDIR}/ffmpeg/lib/avdevice.lib
297       ${LIBDIR}/ffmpeg/lib/avutil.lib
298       ${LIBDIR}/ffmpeg/lib/swscale.lib
299       )
300   endif()
301 endif()
302
303 if(WITH_IMAGE_OPENEXR)
304   set(OPENEXR_ROOT_DIR ${LIBDIR}/openexr)
305   set(OPENEXR_VERSION "2.1")
306   windows_find_package(OPENEXR REQUIRED)
307   if(NOT OPENEXR_FOUND)
308     warn_hardcoded_paths(OpenEXR)
309     set(OPENEXR ${LIBDIR}/openexr)
310     set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
311     set(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR} ${OPENEXR}/include/OpenEXR)
312     set(OPENEXR_LIBPATH ${OPENEXR}/lib)
313     set(OPENEXR_LIBRARIES
314       optimized ${OPENEXR_LIBPATH}/Iex_s.lib
315       optimized ${OPENEXR_LIBPATH}/Half_s.lib
316       optimized ${OPENEXR_LIBPATH}/IlmImf_s.lib
317       optimized ${OPENEXR_LIBPATH}/Imath_s.lib
318       optimized ${OPENEXR_LIBPATH}/IlmThread_s.lib
319       debug ${OPENEXR_LIBPATH}/Iex_s_d.lib
320       debug ${OPENEXR_LIBPATH}/Half_s_d.lib
321       debug ${OPENEXR_LIBPATH}/IlmImf_s_d.lib
322       debug ${OPENEXR_LIBPATH}/Imath_s_d.lib
323       debug ${OPENEXR_LIBPATH}/IlmThread_s_d.lib
324     )
325   endif()
326 endif()
327
328 if(WITH_IMAGE_TIFF)
329   # Try to find tiff first then complain and set static and maybe wrong paths
330   windows_find_package(TIFF)
331   if(NOT TIFF_FOUND)
332     warn_hardcoded_paths(libtiff)
333     set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
334     set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
335   endif()
336 endif()
337
338 if(WITH_JACK)
339   set(JACK_INCLUDE_DIRS
340     ${LIBDIR}/jack/include/jack
341     ${LIBDIR}/jack/include
342   )
343   set(JACK_LIBRARIES optimized ${LIBDIR}/jack/lib/libjack.lib debug ${LIBDIR}/jack/lib/libjack_d.lib)
344 endif()
345
346 if(WITH_PYTHON)
347   set(PYTHON_VERSION 3.7) # CACHE STRING)
348
349   string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
350   set(PYTHON_LIBRARY ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/libs/python${_PYTHON_VERSION_NO_DOTS}.lib)
351   set(PYTHON_LIBRARY_DEBUG ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/libs/python${_PYTHON_VERSION_NO_DOTS}_d.lib)
352   
353   set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/include)
354   set(PYTHON_NUMPY_INCLUDE_DIRS ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/lib/site-packages/numpy/core/include)
355   set(NUMPY_FOUND On)
356   unset(_PYTHON_VERSION_NO_DOTS)
357   # uncached vars
358   set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
359   set(PYTHON_LIBRARIES debug "${PYTHON_LIBRARY_DEBUG}" optimized "${PYTHON_LIBRARY}" )
360 endif()
361
362 if(WITH_BOOST)
363   if(WITH_CYCLES_OSL)
364     set(boost_extra_libs wave)
365   endif()
366   if(WITH_INTERNATIONAL)
367     list(APPEND boost_extra_libs locale)
368   endif()
369   if(WITH_OPENVDB)
370     list(APPEND boost_extra_libs iostreams)
371   endif()
372   set(Boost_USE_STATIC_RUNTIME ON) # prefix lib
373   set(Boost_USE_MULTITHREADED ON) # suffix -mt
374   set(Boost_USE_STATIC_LIBS ON) # suffix -s
375   if(WITH_WINDOWS_FIND_MODULES)
376     find_package(Boost COMPONENTS date_time filesystem thread regex system ${boost_extra_libs})
377   endif()
378   if(NOT Boost_FOUND)
379     warn_hardcoded_paths(BOOST)
380     set(BOOST ${LIBDIR}/boost)
381     set(BOOST_INCLUDE_DIR ${BOOST}/include)
382     set(BOOST_LIBPATH ${BOOST}/lib)
383     if(CMAKE_CL_64)
384       set(BOOST_POSTFIX "vc140-mt-s-x64-1_68.lib")
385       set(BOOST_DEBUG_POSTFIX "vc140-mt-sgd-x64-1_68.lib")
386     endif()
387     set(BOOST_LIBRARIES
388       optimized ${BOOST_LIBPATH}/libboost_date_time-${BOOST_POSTFIX}
389       optimized ${BOOST_LIBPATH}/libboost_filesystem-${BOOST_POSTFIX}
390       optimized ${BOOST_LIBPATH}/libboost_regex-${BOOST_POSTFIX}
391       optimized ${BOOST_LIBPATH}/libboost_system-${BOOST_POSTFIX}
392       optimized ${BOOST_LIBPATH}/libboost_thread-${BOOST_POSTFIX}
393       optimized ${BOOST_LIBPATH}/libboost_chrono-${BOOST_POSTFIX}
394       debug ${BOOST_LIBPATH}/libboost_date_time-${BOOST_DEBUG_POSTFIX}
395       debug ${BOOST_LIBPATH}/libboost_filesystem-${BOOST_DEBUG_POSTFIX}
396       debug ${BOOST_LIBPATH}/libboost_regex-${BOOST_DEBUG_POSTFIX}
397       debug ${BOOST_LIBPATH}/libboost_system-${BOOST_DEBUG_POSTFIX}
398       debug ${BOOST_LIBPATH}/libboost_thread-${BOOST_DEBUG_POSTFIX}
399       debug ${BOOST_LIBPATH}/libboost_chrono-${BOOST_DEBUG_POSTFIX}
400     )
401     if(WITH_CYCLES_OSL)
402       set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
403         optimized ${BOOST_LIBPATH}/libboost_wave-${BOOST_POSTFIX}
404         debug ${BOOST_LIBPATH}/libboost_wave-${BOOST_DEBUG_POSTFIX})
405     endif()
406     if(WITH_INTERNATIONAL)
407       set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
408         optimized ${BOOST_LIBPATH}/libboost_locale-${BOOST_POSTFIX}
409         debug ${BOOST_LIBPATH}/libboost_locale-${BOOST_DEBUG_POSTFIX})
410     endif()
411   else() # we found boost using find_package
412     set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
413     set(BOOST_LIBRARIES ${Boost_LIBRARIES})
414     set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
415   endif()
416   set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
417 endif()
418
419 if(WITH_OPENIMAGEIO)
420   windows_find_package(OpenImageIO)
421   set(OPENIMAGEIO ${LIBDIR}/openimageio)
422   set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
423   set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
424   set(OIIO_OPTIMIZED optimized ${OPENIMAGEIO_LIBPATH}/OpenImageIO.lib optimized ${OPENIMAGEIO_LIBPATH}/OpenImageIO_Util.lib)
425   set(OIIO_DEBUG debug ${OPENIMAGEIO_LIBPATH}/OpenImageIO_d.lib debug ${OPENIMAGEIO_LIBPATH}/OpenImageIO_Util_d.lib)
426   set(OPENIMAGEIO_LIBRARIES ${OIIO_OPTIMIZED} ${OIIO_DEBUG})
427
428   set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0")
429   set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
430   set(OPENIMAGEIO_IDIFF "${OPENIMAGEIO}/bin/idiff.exe")
431   add_definitions(-DOIIO_STATIC_BUILD)
432   add_definitions(-DOIIO_NO_SSE=1)
433 endif()
434
435 if(WITH_LLVM)
436   set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH "Path to the LLVM installation")
437   set(LLVM_INCLUDE_DIRS ${LLVM_ROOT_DIR}/$<$<CONFIG:Debug>:Debug>/include CACHE PATH  "Path to the LLVM include directory")
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
466     optimized ${OPENCOLORIO_LIBPATH}/OpenColorIO.lib
467     optimized ${OPENCOLORIO_LIBPATH}/tinyxml.lib
468     optimized ${OPENCOLORIO_LIBPATH}/libyaml-cpp.lib
469     debug ${OPENCOLORIO_LIBPATH}/OpenColorIO_d.lib
470     debug ${OPENCOLORIO_LIBPATH}/tinyxml_d.lib
471     debug ${OPENCOLORIO_LIBPATH}/libyaml-cpp_d.lib
472   )
473   set(OPENCOLORIO_DEFINITIONS)
474 endif()
475
476 if(WITH_OPENVDB)
477   set(BLOSC_LIBRARIES optimized ${LIBDIR}/blosc/lib/libblosc.lib debug ${LIBDIR}/blosc/lib/libblosc_d.lib)
478   set(TBB_LIBRARIES optimized ${LIBDIR}/tbb/lib/tbb.lib debug ${LIBDIR}/tbb/lib/tbb_debug.lib)
479   set(TBB_INCLUDE_DIR ${LIBDIR}/tbb/include)
480   set(OPENVDB ${LIBDIR}/openvdb)
481   set(OPENVDB_LIBPATH ${LIBDIR}/openvdb/lib)
482   set(OPENVDB_INCLUDE_DIRS ${OPENVDB}/include ${TBB_INCLUDE_DIR})
483   set(OPENVDB_LIBRARIES optimized ${OPENVDB_LIBPATH}/openvdb.lib debug ${OPENVDB_LIBPATH}/openvdb_d.lib ${TBB_LIBRARIES} ${BLOSC_LIBRARIES})
484   set(OPENVDB_DEFINITIONS -DNOMINMAX)
485 endif()
486
487 if(WITH_ALEMBIC)
488   set(ALEMBIC ${LIBDIR}/alembic)
489   set(ALEMBIC_INCLUDE_DIR ${ALEMBIC}/include)
490   set(ALEMBIC_INCLUDE_DIRS ${ALEMBIC_INCLUDE_DIR})
491   set(ALEMBIC_LIBPATH ${ALEMBIC}/lib)
492   set(ALEMBIC_LIBRARIES optimized ${ALEMBIC}/lib/alembic.lib debug ${ALEMBIC}/lib/alembic_d.lib)
493   set(ALEMBIC_FOUND 1)
494 endif()
495
496 if(WITH_MOD_CLOTH_ELTOPO)
497   set(LAPACK ${LIBDIR}/lapack)
498   # set(LAPACK_INCLUDE_DIR ${LAPACK}/include)
499   set(LAPACK_LIBPATH ${LAPACK}/lib)
500   set(LAPACK_LIBRARIES
501     ${LIBDIR}/lapack/lib/libf2c.lib
502     ${LIBDIR}/lapack/lib/clapack_nowrap.lib
503     ${LIBDIR}/lapack/lib/BLAS_nowrap.lib
504   )
505 endif()
506
507 if(WITH_IMAGE_OPENJPEG)
508   set(OPENJPEG ${LIBDIR}/openjpeg)
509   set(OPENJPEG_INCLUDE_DIRS ${OPENJPEG}/include/openjpeg-2.3)
510   set(OPENJPEG_LIBRARIES ${OPENJPEG}/lib/openjp2.lib)
511 endif()
512
513 if(WITH_OPENSUBDIV)
514   set(OPENSUBDIV_INCLUDE_DIR ${LIBDIR}/opensubdiv/include)
515   set(OPENSUBDIV_LIBPATH ${LIBDIR}/opensubdiv/lib)
516   set(OPENSUBDIV_LIBRARIES
517     optimized ${OPENSUBDIV_LIBPATH}/osdCPU.lib
518     optimized ${OPENSUBDIV_LIBPATH}/osdGPU.lib
519     debug ${OPENSUBDIV_LIBPATH}/osdCPU_d.lib
520     debug ${OPENSUBDIV_LIBPATH}/osdGPU_d.lib
521   )
522   set(OPENSUBDIV_HAS_OPENMP TRUE)
523   set(OPENSUBDIV_HAS_TBB FALSE)
524   set(OPENSUBDIV_HAS_OPENCL TRUE)
525   set(OPENSUBDIV_HAS_CUDA FALSE)
526   set(OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK TRUE)
527   set(OPENSUBDIV_HAS_GLSL_COMPUTE TRUE)
528   windows_find_package(OpenSubdiv)
529 endif()
530
531 if(WITH_SDL)
532   set(SDL ${LIBDIR}/sdl)
533   set(SDL_INCLUDE_DIR ${SDL}/include)
534   set(SDL_LIBPATH ${SDL}/lib)
535   set(SDL_LIBRARY ${SDL_LIBPATH}/SDL2.lib)
536 endif()
537
538 # Audio IO
539 if(WITH_SYSTEM_AUDASPACE)
540   set(AUDASPACE_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
541   set(AUDASPACE_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace.lib)
542   set(AUDASPACE_C_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
543   set(AUDASPACE_C_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace-c.lib)
544   set(AUDASPACE_PY_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
545   set(AUDASPACE_PY_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace-py.lib)
546 endif()
547
548 # used in many places so include globally, like OpenGL
549 blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
550
551 #find signtool
552 set(ProgramFilesX86_NAME "ProgramFiles(x86)") #env dislikes the ( )
553 find_program(SIGNTOOL_EXE signtool
554   HINTS
555     "$ENV{${ProgramFilesX86_NAME}}/Windows Kits/10/bin/x86/"
556     "$ENV{ProgramFiles}/Windows Kits/10/bin/x86/"
557     "$ENV{${ProgramFilesX86_NAME}}/Windows Kits/8.1/bin/x86/"
558     "$ENV{ProgramFiles}/Windows Kits/8.1/bin/x86/"
559     "$ENV{${ProgramFilesX86_NAME}}/Windows Kits/8.0/bin/x86/"
560     "$ENV{ProgramFiles}/Windows Kits/8.0/bin/x86/"
561 )
562 set(WINTAB_INC ${LIBDIR}/wintab/include)
563
564 if(WITH_OPENAL)
565   set(OPENAL ${LIBDIR}/openal)
566   set(OPENALDIR ${LIBDIR}/openal)
567   set(OPENAL_INCLUDE_DIR ${OPENAL}/include/AL)
568   set(OPENAL_LIBPATH ${OPENAL}/lib)
569   if(MSVC)
570     set(OPENAL_LIBRARY ${OPENAL_LIBPATH}/openal32.lib)
571   else()
572     set(OPENAL_LIBRARY ${OPENAL_LIBPATH}/wrap_oal.lib)
573   endif()
574
575 endif()
576
577 if(WITH_CODEC_SNDFILE)
578   set(LIBSNDFILE ${LIBDIR}/sndfile)
579   set(LIBSNDFILE_INCLUDE_DIRS ${LIBSNDFILE}/include)
580   set(LIBSNDFILE_LIBPATH ${LIBSNDFILE}/lib) # TODO, deprecate
581   set(LIBSNDFILE_LIBRARIES ${LIBSNDFILE_LIBPATH}/libsndfile-1.lib)
582 endif()
583
584 if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
585   add_definitions(-D__SSE__ -D__MMX__)
586 endif()
587
588 if(WITH_CYCLES_OSL)
589   set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
590
591   find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
592   find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
593   find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
594   find_library(OSL_LIB_EXEC_DEBUG NAMES oslexec_d PATHS ${CYCLES_OSL}/lib)
595   find_library(OSL_LIB_COMP_DEBUG NAMES oslcomp_d PATHS ${CYCLES_OSL}/lib)
596   find_library(OSL_LIB_QUERY_DEBUG NAMES oslquery_d PATHS ${CYCLES_OSL}/lib)
597   list(APPEND OSL_LIBRARIES
598     optimized ${OSL_LIB_COMP}
599     optimized ${OSL_LIB_EXEC}
600     optimized ${OSL_LIB_QUERY}
601     optimized ${CYCLES_OSL}/lib/pugixml.lib
602     debug ${OSL_LIB_EXEC_DEBUG}
603     debug ${OSL_LIB_COMP_DEBUG}
604     debug ${OSL_LIB_QUERY_DEBUG}
605     debug ${CYCLES_OSL}/lib/pugixml_d.lib
606   )
607   find_path(OSL_INCLUDE_DIR OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
608   find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
609
610   if(OSL_INCLUDE_DIR AND OSL_LIBRARIES AND OSL_COMPILER)
611     set(OSL_FOUND TRUE)
612   else()
613     message(STATUS "OSL not found")
614     set(WITH_CYCLES_OSL OFF)
615   endif()
616 endif()
617
618 if(WITH_CYCLES_EMBREE)
619   windows_find_package(Embree)
620   if(NOT EMBREE_FOUND)
621     set(EMBREE_INCLUDE_DIRS ${LIBDIR}/embree/include)
622     set(EMBREE_LIBRARIES
623       optimized ${LIBDIR}/embree/lib/embree3.lib
624       optimized ${LIBDIR}/embree/lib/embree_avx2.lib
625       optimized ${LIBDIR}/embree/lib/embree_avx.lib
626       optimized ${LIBDIR}/embree/lib/embree_sse42.lib
627       optimized ${LIBDIR}/embree/lib/lexers.lib
628       optimized ${LIBDIR}/embree/lib/math.lib
629       optimized ${LIBDIR}/embree/lib/simd.lib
630       optimized ${LIBDIR}/embree/lib/sys.lib
631       optimized ${LIBDIR}/embree/lib/tasking.lib
632
633       debug ${LIBDIR}/embree/lib/embree3_d.lib
634       debug ${LIBDIR}/embree/lib/embree_avx2_d.lib
635       debug ${LIBDIR}/embree/lib/embree_avx_d.lib
636       debug ${LIBDIR}/embree/lib/embree_sse42_d.lib
637       debug ${LIBDIR}/embree/lib/lexers_d.lib
638       debug ${LIBDIR}/embree/lib/math_d.lib
639       debug ${LIBDIR}/embree/lib/simd_d.lib
640       debug ${LIBDIR}/embree/lib/sys_d.lib
641       debug ${LIBDIR}/embree/lib/tasking_d.lib)
642   endif()
643 endif()
644
645 if(WINDOWS_PYTHON_DEBUG)
646   # Include the system scripts in the blender_python_system_scripts project.
647   FILE(GLOB_RECURSE inFiles "${CMAKE_SOURCE_DIR}/release/scripts/*.*" )
648   ADD_CUSTOM_TARGET(blender_python_system_scripts SOURCES ${inFiles})
649   foreach(_source IN ITEMS ${inFiles})
650     get_filename_component(_source_path "${_source}" PATH)
651     string(REPLACE "${CMAKE_SOURCE_DIR}/release/scripts/" "" _source_path "${_source_path}")
652     string(REPLACE "/" "\\" _group_path "${_source_path}")
653     source_group("${_group_path}" FILES "${_source}")
654   endforeach()
655   # Include the user scripts from the profile folder in the blender_python_user_scripts project.
656   set(USER_SCRIPTS_ROOT "$ENV{appdata}/blender foundation/blender/${BLENDER_VERSION}")
657   file(TO_CMAKE_PATH ${USER_SCRIPTS_ROOT} USER_SCRIPTS_ROOT)
658   FILE(GLOB_RECURSE inFiles "${USER_SCRIPTS_ROOT}/scripts/*.*" )
659   ADD_CUSTOM_TARGET(blender_python_user_scripts SOURCES ${inFiles})
660   foreach(_source IN ITEMS ${inFiles})
661     get_filename_component(_source_path "${_source}" PATH)
662     string(REPLACE "${USER_SCRIPTS_ROOT}/scripts" "" _source_path "${_source_path}")
663     string(REPLACE "/" "\\" _group_path "${_source_path}")
664     source_group("${_group_path}" FILES "${_source}")
665   endforeach()
666   set_target_properties(blender_python_system_scripts PROPERTIES FOLDER "scripts")
667   set_target_properties(blender_python_user_scripts PROPERTIES FOLDER "scripts")
668   # Set the default debugging options for the project, only write this file once so the user
669   # is free to override them at their own perril.
670   set(USER_PROPS_FILE "${CMAKE_CURRENT_BINARY_DIR}/source/creator/blender.Cpp.user.props")
671   if(NOT EXISTS ${USER_PROPS_FILE})
672     # Layout below is messy, because otherwise the generated file will look messy.
673     file(WRITE ${USER_PROPS_FILE} "<?xml version=\"1.0\" encoding=\"utf-8\"?>
674 <Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">
675   <PropertyGroup>
676     <LocalDebuggerCommandArguments>-con --env-system-scripts \"${CMAKE_SOURCE_DIR}/release/scripts\" </LocalDebuggerCommandArguments>
677   </PropertyGroup>
678 </Project>")
679   endif()
680 endif()