Merge branch 'blender-v2.90-release'
[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   # 1) CMake has issues detecting openmp support in clang-cl so we have to provide
39   #    the right switches here.
40   # 2) While the /openmp switch *should* work, it currently doesn't as for clang 9.0.0
41   if(WITH_OPENMP)
42     set(OPENMP_CUSTOM ON)
43     set(OPENMP_FOUND ON)
44     set(OpenMP_C_FLAGS "/clang:-fopenmp")
45     set(OpenMP_CXX_FLAGS "/clang:-fopenmp")
46     GET_FILENAME_COMPONENT(LLVMROOT "[HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\LLVM\\LLVM;]" ABSOLUTE CACHE)
47     set(CLANG_OPENMP_DLL "${LLVMROOT}/bin/libomp.dll")
48     set(CLANG_OPENMP_LIB "${LLVMROOT}/lib/libomp.lib")
49     if(NOT EXISTS "${CLANG_OPENMP_DLL}")
50       message(FATAL_ERROR "Clang OpenMP library (${CLANG_OPENMP_DLL}) not found.")
51     endif()
52     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} \"${CLANG_OPENMP_LIB}\"")
53   endif()
54   if(WITH_WINDOWS_STRIPPED_PDB)
55     message(WARNING "stripped pdb not supported with clang, disabling..")
56     set(WITH_WINDOWS_STRIPPED_PDB Off)
57   endif()
58 endif()
59
60 set_property(GLOBAL PROPERTY USE_FOLDERS ${WINDOWS_USE_VISUAL_STUDIO_PROJECT_FOLDERS})
61
62 if(NOT WITH_PYTHON_MODULE)
63   set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT blender)
64 endif()
65
66 macro(warn_hardcoded_paths package_name
67   )
68   if(WITH_WINDOWS_FIND_MODULES)
69     message(WARNING "Using HARDCODED ${package_name} locations")
70   endif()
71 endmacro()
72
73 macro(windows_find_package package_name
74   )
75   if(WITH_WINDOWS_FIND_MODULES)
76     find_package(${package_name})
77   endif()
78 endmacro()
79
80 macro(find_package_wrapper)
81   if(WITH_WINDOWS_FIND_MODULES)
82     find_package(${ARGV})
83   endif()
84 endmacro()
85
86 add_definitions(-DWIN32)
87
88 # Needed, otherwise system encoding causes utf-8 encoding to fail in some cases (C4819)
89 add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
90 add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
91
92 # Minimum MSVC Version
93 if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
94   if(MSVC_VERSION EQUAL 1800)
95     set(_min_ver "18.0.31101")
96     if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${_min_ver})
97       message(FATAL_ERROR
98         "Visual Studio 2013 (Update 4, ${_min_ver}) required, "
99         "found (${CMAKE_CXX_COMPILER_VERSION})")
100     endif()
101   endif()
102   if(MSVC_VERSION EQUAL 1900)
103     set(_min_ver "19.0.24210")
104     if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${_min_ver})
105       message(FATAL_ERROR
106         "Visual Studio 2015 (Update 3, ${_min_ver}) required, "
107         "found (${CMAKE_CXX_COMPILER_VERSION})")
108     endif()
109   endif()
110 endif()
111 unset(_min_ver)
112
113 # needed for some MSVC installations
114 # 4099 : PDB 'filename' was not found with 'object/library'
115 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO /ignore:4099")
116 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO /ignore:4099")
117 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO /ignore:4099")
118
119 list(APPEND PLATFORM_LINKLIBS
120   ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 Comctl32 version
121   advapi32 shfolder shell32 ole32 oleaut32 uuid psapi Dbghelp Shlwapi
122 )
123
124 if(WITH_INPUT_IME)
125   list(APPEND PLATFORM_LINKLIBS imm32)
126 endif()
127
128 add_definitions(
129   -D_CRT_NONSTDC_NO_DEPRECATE
130   -D_CRT_SECURE_NO_DEPRECATE
131   -D_SCL_SECURE_NO_DEPRECATE
132   -D_CONSOLE
133   -D_LIB
134 )
135
136 # MSVC11 needs _ALLOW_KEYWORD_MACROS to build
137 add_definitions(-D_ALLOW_KEYWORD_MACROS)
138
139 # We want to support Windows 7 level ABI
140 add_definitions(-D_WIN32_WINNT=0x601)
141 include(build_files/cmake/platform/platform_win32_bundle_crt.cmake)
142 remove_cc_flag("/MDd" "/MD" "/Zi")
143
144 if(WITH_WINDOWS_PDB)
145         set(PDB_INFO_OVERRIDE_FLAGS "/Z7")
146         set(PDB_INFO_OVERRIDE_LINKER_FLAGS "/DEBUG /OPT:REF /OPT:ICF /INCREMENTAL:NO")
147 endif()
148
149 if(MSVC_CLANG) # Clangs version of cl doesn't support all flags
150   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_WARN_FLAGS} /nologo /J /Gd /EHsc -Wno-unused-command-line-argument -Wno-microsoft-enum-forward-reference ")
151   set(CMAKE_C_FLAGS     "${CMAKE_C_FLAGS} /nologo /J /Gd -Wno-unused-command-line-argument -Wno-microsoft-enum-forward-reference")
152 else()
153   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /nologo /J /Gd /MP /EHsc /bigobj")
154   set(CMAKE_C_FLAGS     "${CMAKE_C_FLAGS} /nologo /J /Gd /MP /bigobj")
155 endif()
156
157 # C++ standards conformace (/permissive-) is available on msvc 15.5 (1912) and up
158 if(MSVC_VERSION GREATER 1911 AND NOT MSVC_CLANG)
159   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-")
160   # Two-phase name lookup does not place nicely with OpenMP yet, so disable for now
161   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:twoPhase-")
162 endif()
163
164 if(WITH_WINDOWS_SCCACHE AND CMAKE_VS_MSBUILD_COMMAND)
165     message(WARNING "Disabling sccache, sccache is not supported with msbuild")
166     set(WITH_WINDOWS_SCCACHE Off)
167 endif()
168
169 if(WITH_WINDOWS_SCCACHE)
170     set(CMAKE_C_COMPILER_LAUNCHER sccache)
171     set(CMAKE_CXX_COMPILER_LAUNCHER sccache)
172     set(SYMBOL_FORMAT /Z7)
173 else()
174     unset(CMAKE_C_COMPILER_LAUNCHER)
175     unset(CMAKE_CXX_COMPILER_LAUNCHER)
176     set(SYMBOL_FORMAT /ZI)
177 endif()
178
179 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd ${SYMBOL_FORMAT}")
180 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MDd ${SYMBOL_FORMAT}")
181 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD ${PDB_INFO_OVERRIDE_FLAGS}")
182 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MD ${PDB_INFO_OVERRIDE_FLAGS}")
183 set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MD ${PDB_INFO_OVERRIDE_FLAGS}")
184 set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /MD ${PDB_INFO_OVERRIDE_FLAGS}")
185 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MD ${SYMBOL_FORMAT}")
186 set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MD ${SYMBOL_FORMAT}")
187 unset(SYMBOL_FORMAT)
188 # JMC is available on msvc 15.8 (1915) and up
189 if(MSVC_VERSION GREATER 1914 AND NOT MSVC_CLANG)
190   set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /JMC")
191 endif()
192
193 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /SUBSYSTEM:CONSOLE /STACK:2097152")
194 set(PLATFORM_LINKFLAGS_RELEASE "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrtd.lib")
195 set(PLATFORM_LINKFLAGS_DEBUG "${PLATFORM_LINKFLAGS_DEBUG} /IGNORE:4099 /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcmtd.lib")
196
197 # Ignore meaningless for us linker warnings.
198 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /ignore:4049 /ignore:4217 /ignore:4221")
199 set(PLATFORM_LINKFLAGS_RELEASE "${PLATFORM_LINKFLAGS} ${PDB_INFO_OVERRIDE_LINKER_FLAGS}")
200 set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221")
201
202 if(CMAKE_CL_64)
203   set(PLATFORM_LINKFLAGS "/MACHINE:X64 ${PLATFORM_LINKFLAGS}")
204 else()
205   set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
206 endif()
207
208 if(NOT DEFINED LIBDIR)
209
210   # Setup 64bit and 64bit windows systems
211   if(CMAKE_CL_64)
212     message(STATUS "64 bit compiler detected.")
213     set(LIBDIR_BASE "win64")
214   else()
215     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")
216   endif()
217   # Can be 1910..1912
218   if(MSVC_VERSION GREATER 1919)
219     message(STATUS "Visual Studio 2019 detected.")
220     set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc15)
221   elseif(MSVC_VERSION GREATER 1909)
222     message(STATUS "Visual Studio 2017 detected.")
223     set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc15)
224   elseif(MSVC_VERSION EQUAL 1900)
225     message(STATUS "Visual Studio 2015 detected.")
226     set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc15)
227   endif()
228 else()
229   message(STATUS "Using pre-compiled LIBDIR: ${LIBDIR}")
230 endif()
231 if(NOT EXISTS "${LIBDIR}/")
232   message(FATAL_ERROR "\n\nWindows requires pre-compiled libs at: '${LIBDIR}'. Please run `make update` in the blender source folder to obtain them.")
233 endif()
234
235 # Mark libdir as system headers with a lower warn level, to resolve some warnings
236 # that we have very little control over
237 if(MSVC_VERSION GREATER_EQUAL 1914 AND NOT MSVC_CLANG AND NOT WITH_WINDOWS_SCCACHE)
238   add_compile_options(/experimental:external /external:templates- /external:I "${LIBDIR}" /external:W0)
239 endif()
240
241 # Add each of our libraries to our cmake_prefix_path so find_package() could work
242 file(GLOB children RELATIVE ${LIBDIR} ${LIBDIR}/*)
243 foreach(child ${children})
244   if(IS_DIRECTORY ${LIBDIR}/${child})
245     list(APPEND CMAKE_PREFIX_PATH  ${LIBDIR}/${child})
246   endif()
247 endforeach()
248
249 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
250 set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz_st.lib)
251 set(ZLIB_INCLUDE_DIR ${LIBDIR}/zlib/include)
252 set(ZLIB_LIBRARY ${LIBDIR}/zlib/lib/libz_st.lib)
253 set(ZLIB_DIR ${LIBDIR}/zlib)
254
255 windows_find_package(zlib) # we want to find before finding things that depend on it like png
256 windows_find_package(png)
257
258 if(NOT PNG_FOUND)
259   warn_hardcoded_paths(libpng)
260   set(PNG_PNG_INCLUDE_DIR ${LIBDIR}/png/include)
261   set(PNG_LIBRARIES ${LIBDIR}/png/lib/libpng.lib ${ZLIB_LIBRARY})
262   set(PNG "${LIBDIR}/png")
263   set(PNG_INCLUDE_DIRS "${PNG}/include")
264   set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
265 endif()
266
267 set(JPEG_NAMES ${JPEG_NAMES} libjpeg)
268 windows_find_package(jpeg REQUIRED)
269 if(NOT JPEG_FOUND)
270   warn_hardcoded_paths(jpeg)
271   set(JPEG_INCLUDE_DIR ${LIBDIR}/jpeg/include)
272   set(JPEG_LIBRARIES ${LIBDIR}/jpeg/lib/libjpeg.lib)
273 endif()
274
275 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
276 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC3.lib)
277
278 set(FREETYPE ${LIBDIR}/freetype)
279 set(FREETYPE_INCLUDE_DIRS
280   ${LIBDIR}/freetype/include
281   ${LIBDIR}/freetype/include/freetype2
282 )
283 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
284 windows_find_package(freetype REQUIRED)
285
286 if(WITH_FFTW3)
287   set(FFTW3 ${LIBDIR}/fftw3)
288   set(FFTW3_LIBRARIES ${FFTW3}/lib/libfftw.lib)
289   set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
290   set(FFTW3_LIBPATH ${FFTW3}/lib)
291 endif()
292
293 if(WITH_OPENCOLLADA)
294   set(OPENCOLLADA ${LIBDIR}/opencollada)
295
296   set(OPENCOLLADA_INCLUDE_DIRS
297     ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
298     ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
299     ${OPENCOLLADA}/include/opencollada/COLLADAFramework
300     ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
301     ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
302   )
303
304   set(OPENCOLLADA_LIBRARIES
305     optimized ${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader.lib
306     optimized ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework.lib
307     optimized ${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils.lib
308     optimized ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter.lib
309     optimized ${OPENCOLLADA}/lib/opencollada/MathMLSolver.lib
310     optimized ${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser.lib
311     optimized ${OPENCOLLADA}/lib/opencollada/xml.lib
312     optimized ${OPENCOLLADA}/lib/opencollada/buffer.lib
313     optimized ${OPENCOLLADA}/lib/opencollada/ftoa.lib
314
315     debug ${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader_d.lib
316     debug ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework_d.lib
317     debug ${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils_d.lib
318     debug ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter_d.lib
319     debug ${OPENCOLLADA}/lib/opencollada/MathMLSolver_d.lib
320     debug ${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser_d.lib
321     debug ${OPENCOLLADA}/lib/opencollada/xml_d.lib
322     debug ${OPENCOLLADA}/lib/opencollada/buffer_d.lib
323     debug ${OPENCOLLADA}/lib/opencollada/ftoa_d.lib
324   )
325
326   list(APPEND OPENCOLLADA_LIBRARIES ${OPENCOLLADA}/lib/opencollada/UTF.lib)
327
328   set(PCRE_LIBRARIES
329     optimized ${OPENCOLLADA}/lib/opencollada/pcre.lib
330
331     debug ${OPENCOLLADA}/lib/opencollada/pcre_d.lib
332   )
333 endif()
334
335 if(WITH_CODEC_FFMPEG)
336   set(FFMPEG_INCLUDE_DIRS
337     ${LIBDIR}/ffmpeg/include
338     ${LIBDIR}/ffmpeg/include/msvc
339   )
340   windows_find_package(FFMPEG)
341   if(NOT FFMPEG_FOUND)
342     warn_hardcoded_paths(ffmpeg)
343     set(FFMPEG_LIBRARIES
344       ${LIBDIR}/ffmpeg/lib/avcodec.lib
345       ${LIBDIR}/ffmpeg/lib/avformat.lib
346       ${LIBDIR}/ffmpeg/lib/avdevice.lib
347       ${LIBDIR}/ffmpeg/lib/avutil.lib
348       ${LIBDIR}/ffmpeg/lib/swscale.lib
349       )
350   endif()
351 endif()
352
353 if(WITH_IMAGE_OPENEXR)
354   set(OPENEXR_ROOT_DIR ${LIBDIR}/openexr)
355   set(OPENEXR_VERSION "2.1")
356   windows_find_package(OPENEXR REQUIRED)
357   if(NOT OPENEXR_FOUND)
358     warn_hardcoded_paths(OpenEXR)
359     set(OPENEXR ${LIBDIR}/openexr)
360     set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
361     set(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR} ${OPENEXR}/include/OpenEXR)
362     set(OPENEXR_LIBPATH ${OPENEXR}/lib)
363     set(OPENEXR_LIBRARIES
364       optimized ${OPENEXR_LIBPATH}/Iex_s.lib
365       optimized ${OPENEXR_LIBPATH}/Half_s.lib
366       optimized ${OPENEXR_LIBPATH}/IlmImf_s.lib
367       optimized ${OPENEXR_LIBPATH}/Imath_s.lib
368       optimized ${OPENEXR_LIBPATH}/IlmThread_s.lib
369       debug ${OPENEXR_LIBPATH}/Iex_s_d.lib
370       debug ${OPENEXR_LIBPATH}/Half_s_d.lib
371       debug ${OPENEXR_LIBPATH}/IlmImf_s_d.lib
372       debug ${OPENEXR_LIBPATH}/Imath_s_d.lib
373       debug ${OPENEXR_LIBPATH}/IlmThread_s_d.lib
374     )
375   endif()
376 endif()
377
378 if(WITH_IMAGE_TIFF)
379   # Try to find tiff first then complain and set static and maybe wrong paths
380   windows_find_package(TIFF)
381   if(NOT TIFF_FOUND)
382     warn_hardcoded_paths(libtiff)
383     set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
384     set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
385   endif()
386 endif()
387
388 if(WITH_JACK)
389   set(JACK_INCLUDE_DIRS
390     ${LIBDIR}/jack/include/jack
391     ${LIBDIR}/jack/include
392   )
393   set(JACK_LIBRARIES optimized ${LIBDIR}/jack/lib/libjack.lib debug ${LIBDIR}/jack/lib/libjack_d.lib)
394 endif()
395
396 if(WITH_PYTHON)
397   set(PYTHON_VERSION 3.7) # CACHE STRING)
398
399   string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
400   set(PYTHON_LIBRARY ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/libs/python${_PYTHON_VERSION_NO_DOTS}.lib)
401   set(PYTHON_LIBRARY_DEBUG ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/libs/python${_PYTHON_VERSION_NO_DOTS}_d.lib)
402
403   set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/include)
404   set(PYTHON_NUMPY_INCLUDE_DIRS ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/lib/site-packages/numpy/core/include)
405   set(NUMPY_FOUND On)
406   unset(_PYTHON_VERSION_NO_DOTS)
407   # uncached vars
408   set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
409   set(PYTHON_LIBRARIES debug "${PYTHON_LIBRARY_DEBUG}" optimized "${PYTHON_LIBRARY}" )
410 endif()
411
412 if(WITH_BOOST)
413   if(WITH_CYCLES_OSL)
414     set(boost_extra_libs wave)
415   endif()
416   if(WITH_INTERNATIONAL)
417     list(APPEND boost_extra_libs locale)
418   endif()
419   set(Boost_USE_STATIC_RUNTIME ON) # prefix lib
420   set(Boost_USE_MULTITHREADED ON) # suffix -mt
421   set(Boost_USE_STATIC_LIBS ON) # suffix -s
422   if(WITH_WINDOWS_FIND_MODULES)
423     find_package(Boost COMPONENTS date_time filesystem thread regex system ${boost_extra_libs})
424   endif()
425   if(NOT Boost_FOUND)
426     warn_hardcoded_paths(BOOST)
427     set(BOOST ${LIBDIR}/boost)
428     set(BOOST_INCLUDE_DIR ${BOOST}/include)
429     set(BOOST_LIBPATH ${BOOST}/lib)
430     if(CMAKE_CL_64)
431       set(BOOST_POSTFIX "vc141-mt-x64-1_70.lib")
432       set(BOOST_DEBUG_POSTFIX "vc141-mt-gd-x64-1_70.lib")
433     endif()
434     set(BOOST_LIBRARIES
435       optimized ${BOOST_LIBPATH}/libboost_date_time-${BOOST_POSTFIX}
436       optimized ${BOOST_LIBPATH}/libboost_filesystem-${BOOST_POSTFIX}
437       optimized ${BOOST_LIBPATH}/libboost_regex-${BOOST_POSTFIX}
438       optimized ${BOOST_LIBPATH}/libboost_system-${BOOST_POSTFIX}
439       optimized ${BOOST_LIBPATH}/libboost_thread-${BOOST_POSTFIX}
440       optimized ${BOOST_LIBPATH}/libboost_chrono-${BOOST_POSTFIX}
441       debug ${BOOST_LIBPATH}/libboost_date_time-${BOOST_DEBUG_POSTFIX}
442       debug ${BOOST_LIBPATH}/libboost_filesystem-${BOOST_DEBUG_POSTFIX}
443       debug ${BOOST_LIBPATH}/libboost_regex-${BOOST_DEBUG_POSTFIX}
444       debug ${BOOST_LIBPATH}/libboost_system-${BOOST_DEBUG_POSTFIX}
445       debug ${BOOST_LIBPATH}/libboost_thread-${BOOST_DEBUG_POSTFIX}
446       debug ${BOOST_LIBPATH}/libboost_chrono-${BOOST_DEBUG_POSTFIX}
447     )
448     if(WITH_CYCLES_OSL)
449       set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
450         optimized ${BOOST_LIBPATH}/libboost_wave-${BOOST_POSTFIX}
451         debug ${BOOST_LIBPATH}/libboost_wave-${BOOST_DEBUG_POSTFIX})
452     endif()
453     if(WITH_INTERNATIONAL)
454       set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
455         optimized ${BOOST_LIBPATH}/libboost_locale-${BOOST_POSTFIX}
456         debug ${BOOST_LIBPATH}/libboost_locale-${BOOST_DEBUG_POSTFIX})
457     endif()
458   else() # we found boost using find_package
459     set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
460     set(BOOST_LIBRARIES ${Boost_LIBRARIES})
461     set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
462   endif()
463   set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
464 endif()
465
466 if(WITH_OPENIMAGEIO)
467   windows_find_package(OpenImageIO)
468   set(OPENIMAGEIO ${LIBDIR}/OpenImageIO)
469   set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
470   set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
471   set(OIIO_OPTIMIZED optimized ${OPENIMAGEIO_LIBPATH}/OpenImageIO.lib optimized ${OPENIMAGEIO_LIBPATH}/OpenImageIO_Util.lib)
472   set(OIIO_DEBUG debug ${OPENIMAGEIO_LIBPATH}/OpenImageIO_d.lib debug ${OPENIMAGEIO_LIBPATH}/OpenImageIO_Util_d.lib)
473   set(OPENIMAGEIO_LIBRARIES ${OIIO_OPTIMIZED} ${OIIO_DEBUG})
474
475   set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0")
476   set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
477   set(OPENIMAGEIO_IDIFF "${OPENIMAGEIO}/bin/idiff.exe")
478   add_definitions(-DOIIO_STATIC_DEFINE)
479   add_definitions(-DOIIO_NO_SSE=1)
480 endif()
481
482 if(WITH_LLVM)
483   set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH "Path to the LLVM installation")
484   set(LLVM_INCLUDE_DIRS ${LLVM_ROOT_DIR}/$<$<CONFIG:Debug>:Debug>/include CACHE PATH  "Path to the LLVM include directory")
485   file(GLOB LLVM_LIBRARY_OPTIMIZED ${LLVM_ROOT_DIR}/lib/*.lib)
486
487   if(EXISTS ${LLVM_ROOT_DIR}/debug/lib)
488     foreach(LLVM_OPTIMIZED_LIB ${LLVM_LIBRARY_OPTIMIZED})
489       get_filename_component(LIBNAME ${LLVM_OPTIMIZED_LIB} ABSOLUTE)
490       list(APPEND LLVM_LIBS optimized ${LIBNAME})
491     endforeach(LLVM_OPTIMIZED_LIB)
492
493     file(GLOB LLVM_LIBRARY_DEBUG ${LLVM_ROOT_DIR}/debug/lib/*.lib)
494
495     foreach(LLVM_DEBUG_LIB ${LLVM_LIBRARY_DEBUG})
496       get_filename_component(LIBNAME ${LLVM_DEBUG_LIB} ABSOLUTE)
497       list(APPEND LLVM_LIBS debug ${LIBNAME})
498     endforeach(LLVM_DEBUG_LIB)
499
500     set(LLVM_LIBRARY ${LLVM_LIBS})
501   else()
502     message(WARNING "LLVM debug libs not present on this system. Using release libs for debug builds.")
503     set(LLVM_LIBRARY ${LLVM_LIBRARY_OPTIMIZED})
504   endif()
505
506 endif()
507
508 if(WITH_OPENCOLORIO)
509   set(OPENCOLORIO ${LIBDIR}/OpenColorIO)
510   set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
511   set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
512   set(OPENCOLORIO_LIBRARIES
513     optimized ${OPENCOLORIO_LIBPATH}/OpenColorIO.lib
514     optimized ${OPENCOLORIO_LIBPATH}/tinyxml.lib
515     optimized ${OPENCOLORIO_LIBPATH}/libyaml-cpp.lib
516     debug ${OPENCOLORIO_LIBPATH}/OpencolorIO_d.lib
517     debug ${OPENCOLORIO_LIBPATH}/tinyxml_d.lib
518     debug ${OPENCOLORIO_LIBPATH}/libyaml-cpp_d.lib
519   )
520   set(OPENCOLORIO_DEFINITIONS)
521 endif()
522
523 if(WITH_OPENVDB)
524   set(OPENVDB ${LIBDIR}/openVDB)
525   set(OPENVDB_LIBPATH ${OPENVDB}/lib)
526   set(OPENVDB_INCLUDE_DIRS ${OPENVDB}/include)
527   set(OPENVDB_LIBRARIES optimized ${OPENVDB_LIBPATH}/openvdb.lib debug ${OPENVDB_LIBPATH}/openvdb_d.lib )
528   set(OPENVDB_DEFINITIONS -DNOMINMAX -D_USE_MATH_DEFINES)
529 endif()
530
531 if(WITH_OPENIMAGEDENOISE)
532   set(OPENIMAGEDENOISE ${LIBDIR}/OpenImageDenoise)
533   set(OPENIMAGEDENOISE_LIBPATH ${LIBDIR}/OpenImageDenoise/lib)
534   set(OPENIMAGEDENOISE_INCLUDE_DIRS ${OPENIMAGEDENOISE}/include)
535   set(OPENIMAGEDENOISE_LIBRARIES
536     optimized ${OPENIMAGEDENOISE_LIBPATH}/OpenImageDenoise.lib
537     optimized ${OPENIMAGEDENOISE_LIBPATH}/common.lib
538     optimized ${OPENIMAGEDENOISE_LIBPATH}/dnnl.lib
539     debug ${OPENIMAGEDENOISE_LIBPATH}/OpenImageDenoise_d.lib
540     debug ${OPENIMAGEDENOISE_LIBPATH}/common_d.lib
541     debug ${OPENIMAGEDENOISE_LIBPATH}/dnnl_d.lib)
542   set(OPENIMAGEDENOISE_DEFINITIONS)
543 endif()
544
545 if(WITH_ALEMBIC)
546   set(ALEMBIC ${LIBDIR}/alembic)
547   set(ALEMBIC_INCLUDE_DIR ${ALEMBIC}/include)
548   set(ALEMBIC_INCLUDE_DIRS ${ALEMBIC_INCLUDE_DIR})
549   set(ALEMBIC_LIBPATH ${ALEMBIC}/lib)
550   set(ALEMBIC_LIBRARIES optimized ${ALEMBIC}/lib/Alembic.lib debug ${ALEMBIC}/lib/Alembic_d.lib)
551   set(ALEMBIC_FOUND 1)
552 endif()
553
554 if(WITH_IMAGE_OPENJPEG)
555   set(OPENJPEG ${LIBDIR}/openjpeg)
556   set(OPENJPEG_INCLUDE_DIRS ${OPENJPEG}/include/openjpeg-2.3)
557   set(OPENJPEG_LIBRARIES ${OPENJPEG}/lib/openjp2.lib)
558 endif()
559
560 if(WITH_OPENSUBDIV)
561   set(OPENSUBDIV_INCLUDE_DIR ${LIBDIR}/opensubdiv/include)
562   set(OPENSUBDIV_LIBPATH ${LIBDIR}/opensubdiv/lib)
563   set(OPENSUBDIV_LIBRARIES
564     optimized ${OPENSUBDIV_LIBPATH}/osdCPU.lib
565     optimized ${OPENSUBDIV_LIBPATH}/osdGPU.lib
566     debug ${OPENSUBDIV_LIBPATH}/osdCPU_d.lib
567     debug ${OPENSUBDIV_LIBPATH}/osdGPU_d.lib
568   )
569   set(OPENSUBDIV_HAS_OPENMP TRUE)
570   set(OPENSUBDIV_HAS_TBB FALSE)
571   set(OPENSUBDIV_HAS_OPENCL TRUE)
572   set(OPENSUBDIV_HAS_CUDA FALSE)
573   set(OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK TRUE)
574   set(OPENSUBDIV_HAS_GLSL_COMPUTE TRUE)
575   windows_find_package(OpenSubdiv)
576 endif()
577
578 if(WITH_SDL)
579   set(SDL ${LIBDIR}/sdl)
580   set(SDL_INCLUDE_DIR ${SDL}/include)
581   set(SDL_LIBPATH ${SDL}/lib)
582   set(SDL_LIBRARY ${SDL_LIBPATH}/SDL2.lib)
583 endif()
584
585 # Audio IO
586 if(WITH_SYSTEM_AUDASPACE)
587   set(AUDASPACE_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
588   set(AUDASPACE_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace.lib)
589   set(AUDASPACE_C_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
590   set(AUDASPACE_C_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace-c.lib)
591   set(AUDASPACE_PY_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
592   set(AUDASPACE_PY_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace-py.lib)
593 endif()
594
595 if(WITH_TBB)
596   set(TBB_LIBRARIES optimized ${LIBDIR}/tbb/lib/tbb.lib debug ${LIBDIR}/tbb/lib/debug/tbb_debug.lib)
597   set(TBB_INCLUDE_DIR ${LIBDIR}/tbb/include)
598   set(TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR})
599   if(WITH_TBB_MALLOC_PROXY)
600     add_definitions(-DWITH_TBB_MALLOC)
601   endif()
602 endif()
603
604 # used in many places so include globally, like OpenGL
605 blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
606
607 set(WINTAB_INC ${LIBDIR}/wintab/include)
608
609 if(WITH_OPENAL)
610   set(OPENAL ${LIBDIR}/openal)
611   set(OPENALDIR ${LIBDIR}/openal)
612   set(OPENAL_INCLUDE_DIR ${OPENAL}/include/AL)
613   set(OPENAL_LIBPATH ${OPENAL}/lib)
614   if(MSVC)
615     set(OPENAL_LIBRARY ${OPENAL_LIBPATH}/openal32.lib)
616   else()
617     set(OPENAL_LIBRARY ${OPENAL_LIBPATH}/wrap_oal.lib)
618   endif()
619
620 endif()
621
622 if(WITH_CODEC_SNDFILE)
623   set(LIBSNDFILE ${LIBDIR}/sndfile)
624   set(LIBSNDFILE_INCLUDE_DIRS ${LIBSNDFILE}/include)
625   set(LIBSNDFILE_LIBPATH ${LIBSNDFILE}/lib) # TODO, deprecate
626   set(LIBSNDFILE_LIBRARIES ${LIBSNDFILE_LIBPATH}/libsndfile-1.lib)
627 endif()
628
629 if(WITH_CYCLES_OSL)
630   set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
631   set(OSL_SHADER_DIR ${CYCLES_OSL}/shaders)
632   find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
633   find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
634   find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
635   find_library(OSL_LIB_EXEC_DEBUG NAMES oslexec_d PATHS ${CYCLES_OSL}/lib)
636   find_library(OSL_LIB_COMP_DEBUG NAMES oslcomp_d PATHS ${CYCLES_OSL}/lib)
637   find_library(OSL_LIB_QUERY_DEBUG NAMES oslquery_d PATHS ${CYCLES_OSL}/lib)
638   list(APPEND OSL_LIBRARIES
639     optimized ${OSL_LIB_COMP}
640     optimized ${OSL_LIB_EXEC}
641     optimized ${OSL_LIB_QUERY}
642     optimized ${CYCLES_OSL}/lib/pugixml.lib
643     debug ${OSL_LIB_EXEC_DEBUG}
644     debug ${OSL_LIB_COMP_DEBUG}
645     debug ${OSL_LIB_QUERY_DEBUG}
646     debug ${CYCLES_OSL}/lib/pugixml_d.lib
647   )
648   find_path(OSL_INCLUDE_DIR OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
649   find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
650
651   if(OSL_INCLUDE_DIR AND OSL_LIBRARIES AND OSL_COMPILER)
652     set(OSL_FOUND TRUE)
653   else()
654     message(STATUS "OSL not found")
655     set(WITH_CYCLES_OSL OFF)
656   endif()
657 endif()
658
659 if(WITH_CYCLES_EMBREE)
660   windows_find_package(Embree)
661   if(NOT EMBREE_FOUND)
662     set(EMBREE_INCLUDE_DIRS ${LIBDIR}/embree/include)
663     set(EMBREE_LIBRARIES
664       optimized ${LIBDIR}/embree/lib/embree3.lib
665       optimized ${LIBDIR}/embree/lib/embree_avx2.lib
666       optimized ${LIBDIR}/embree/lib/embree_avx.lib
667       optimized ${LIBDIR}/embree/lib/embree_sse42.lib
668       optimized ${LIBDIR}/embree/lib/lexers.lib
669       optimized ${LIBDIR}/embree/lib/math.lib
670       optimized ${LIBDIR}/embree/lib/simd.lib
671       optimized ${LIBDIR}/embree/lib/sys.lib
672       optimized ${LIBDIR}/embree/lib/tasking.lib
673
674       debug ${LIBDIR}/embree/lib/embree3_d.lib
675       debug ${LIBDIR}/embree/lib/embree_avx2_d.lib
676       debug ${LIBDIR}/embree/lib/embree_avx_d.lib
677       debug ${LIBDIR}/embree/lib/embree_sse42_d.lib
678       debug ${LIBDIR}/embree/lib/lexers_d.lib
679       debug ${LIBDIR}/embree/lib/math_d.lib
680       debug ${LIBDIR}/embree/lib/simd_d.lib
681       debug ${LIBDIR}/embree/lib/sys_d.lib
682       debug ${LIBDIR}/embree/lib/tasking_d.lib)
683   endif()
684 endif()
685
686 if(WITH_USD)
687   windows_find_package(USD)
688   if(NOT USD_FOUND)
689     set(USD_FOUND ON)
690     set(USD_INCLUDE_DIRS ${LIBDIR}/usd/include)
691     set(USD_RELEASE_LIB ${LIBDIR}/usd/lib/libusd_m.lib)
692     set(USD_DEBUG_LIB ${LIBDIR}/usd/lib/libusd_m_d.lib)
693     set(USD_LIBRARY_DIR ${LIBDIR}/usd/lib)
694     set(USD_LIBRARIES
695       debug ${USD_DEBUG_LIB}
696       optimized ${USD_RELEASE_LIB}
697     )
698   endif()
699 endif()
700
701 if(WINDOWS_PYTHON_DEBUG)
702   # Include the system scripts in the blender_python_system_scripts project.
703   FILE(GLOB_RECURSE inFiles "${CMAKE_SOURCE_DIR}/release/scripts/*.*" )
704   ADD_CUSTOM_TARGET(blender_python_system_scripts SOURCES ${inFiles})
705   foreach(_source IN ITEMS ${inFiles})
706     get_filename_component(_source_path "${_source}" PATH)
707     string(REPLACE "${CMAKE_SOURCE_DIR}/release/scripts/" "" _source_path "${_source_path}")
708     string(REPLACE "/" "\\" _group_path "${_source_path}")
709     source_group("${_group_path}" FILES "${_source}")
710   endforeach()
711   # Include the user scripts from the profile folder in the blender_python_user_scripts project.
712   set(USER_SCRIPTS_ROOT "$ENV{appdata}/blender foundation/blender/${BLENDER_VERSION}")
713   file(TO_CMAKE_PATH ${USER_SCRIPTS_ROOT} USER_SCRIPTS_ROOT)
714   FILE(GLOB_RECURSE inFiles "${USER_SCRIPTS_ROOT}/scripts/*.*" )
715   ADD_CUSTOM_TARGET(blender_python_user_scripts SOURCES ${inFiles})
716   foreach(_source IN ITEMS ${inFiles})
717     get_filename_component(_source_path "${_source}" PATH)
718     string(REPLACE "${USER_SCRIPTS_ROOT}/scripts" "" _source_path "${_source_path}")
719     string(REPLACE "/" "\\" _group_path "${_source_path}")
720     source_group("${_group_path}" FILES "${_source}")
721   endforeach()
722   set_target_properties(blender_python_system_scripts PROPERTIES FOLDER "scripts")
723   set_target_properties(blender_python_user_scripts PROPERTIES FOLDER "scripts")
724   # Set the default debugging options for the project, only write this file once so the user
725   # is free to override them at their own perril.
726   set(USER_PROPS_FILE "${CMAKE_CURRENT_BINARY_DIR}/source/creator/blender.Cpp.user.props")
727   if(NOT EXISTS ${USER_PROPS_FILE})
728     # Layout below is messy, because otherwise the generated file will look messy.
729     file(WRITE ${USER_PROPS_FILE} "<?xml version=\"1.0\" encoding=\"utf-8\"?>
730 <Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">
731   <PropertyGroup>
732     <LocalDebuggerCommandArguments>-con --env-system-scripts \"${CMAKE_SOURCE_DIR}/release/scripts\" </LocalDebuggerCommandArguments>
733   </PropertyGroup>
734 </Project>")
735   endif()
736 endif()
737
738 if(WITH_XR_OPENXR)
739   if(EXISTS ${LIBDIR}/xr_openxr_sdk)
740     set(XR_OPENXR_SDK ${LIBDIR}/xr_openxr_sdk)
741     set(XR_OPENXR_SDK_LIBPATH ${LIBDIR}/xr_openxr_sdk/lib)
742     set(XR_OPENXR_SDK_INCLUDE_DIR ${XR_OPENXR_SDK}/include)
743     set(XR_OPENXR_SDK_LIBRARIES optimized ${XR_OPENXR_SDK_LIBPATH}/openxr_loader.lib debug ${XR_OPENXR_SDK_LIBPATH}/openxr_loader_d.lib)
744   else()
745     message(WARNING "OpenXR-SDK was not found, disabling WITH_XR_OPENXR")
746     set(WITH_XR_OPENXR OFF)
747   endif()
748 endif()
749
750 if(WITH_GMP)
751   set(GMP_INCLUDE_DIRS ${LIBDIR}/gmp/include)
752   set(GMP_LIBRARIES ${LIBDIR}/gmp/lib/libgmp-10.lib optimized ${LIBDIR}/gmp/lib/libgmpxx.lib debug ${LIBDIR}/gmp/lib/libgmpxx_d.lib)
753   set(GMP_ROOT_DIR ${LIBDIR}/gmp)
754   set(GMP_FOUND On)
755 endif()