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