Cleanup: remove contributors for CMake files
[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_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 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO ")
148 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib ")
149
150 # Ignore meaningless for us linker warnings.
151 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /ignore:4049 /ignore:4217 /ignore:4221")
152 set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221")
153
154 if(CMAKE_CL_64)
155         set(PLATFORM_LINKFLAGS "/MACHINE:X64 ${PLATFORM_LINKFLAGS}")
156 else()
157         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
158 endif()
159
160 set(PLATFORM_LINKFLAGS_DEBUG "${PLATFORM_LINKFLAGS_DEBUG} /IGNORE:4099 /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
161
162 if(NOT DEFINED LIBDIR)
163
164         # Setup 64bit and 64bit windows systems
165         if(CMAKE_CL_64)
166                 message(STATUS "64 bit compiler detected.")
167                 set(LIBDIR_BASE "win64")
168         else()
169                 message(STATUS "32 bit compiler detected.")
170                 set(LIBDIR_BASE "windows")
171         endif()
172         # Can be 1910..1912
173         if(MSVC_VERSION GREATER 1909)
174                 message(STATUS "Visual Studio 2017 detected.")
175                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc14)
176         elseif(MSVC_VERSION EQUAL 1900)
177                 message(STATUS "Visual Studio 2015 detected.")
178                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc14)
179         else()
180                 message(STATUS "Visual Studio 2013 detected.")
181                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc12)
182         endif()
183 else()
184         message(STATUS "Using pre-compiled LIBDIR: ${LIBDIR}")
185 endif()
186 if(NOT EXISTS "${LIBDIR}/")
187         message(FATAL_ERROR "Windows requires pre-compiled libs at: '${LIBDIR}'")
188 endif()
189
190 # Add each of our libraries to our cmake_prefix_path so find_package() could work
191 file(GLOB children RELATIVE ${LIBDIR} ${LIBDIR}/*)
192 foreach(child ${children})
193         if(IS_DIRECTORY ${LIBDIR}/${child})
194                 list(APPEND CMAKE_PREFIX_PATH  ${LIBDIR}/${child})
195         endif()
196 endforeach()
197
198 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
199 set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz_st.lib)
200 set(ZLIB_INCLUDE_DIR ${LIBDIR}/zlib/include)
201 set(ZLIB_LIBRARY ${LIBDIR}/zlib/lib/libz_st.lib)
202 set(ZLIB_DIR ${LIBDIR}/zlib)
203
204 windows_find_package(zlib) # we want to find before finding things that depend on it like png
205 windows_find_package(png)
206
207 if(NOT PNG_FOUND)
208         warn_hardcoded_paths(libpng)
209         set(PNG_PNG_INCLUDE_DIR ${LIBDIR}/png/include)
210         set(PNG_LIBRARIES ${LIBDIR}/png/lib/libpng.lib)
211         set(PNG "${LIBDIR}/png")
212         set(PNG_INCLUDE_DIRS "${PNG}/include")
213         set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
214 endif()
215
216 set(JPEG_NAMES ${JPEG_NAMES} libjpeg)
217 windows_find_package(jpeg REQUIRED)
218 if(NOT JPEG_FOUND)
219         warn_hardcoded_paths(jpeg)
220         set(JPEG_INCLUDE_DIR ${LIBDIR}/jpeg/include)
221         set(JPEG_LIBRARIES ${LIBDIR}/jpeg/lib/libjpeg.lib)
222 endif()
223
224 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
225 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC3.lib)
226
227 set(FREETYPE ${LIBDIR}/freetype)
228 set(FREETYPE_INCLUDE_DIRS
229         ${LIBDIR}/freetype/include
230         ${LIBDIR}/freetype/include/freetype2
231 )
232 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
233 windows_find_package(freetype REQUIRED)
234
235 if(WITH_FFTW3)
236         set(FFTW3 ${LIBDIR}/fftw3)
237         set(FFTW3_LIBRARIES ${FFTW3}/lib/libfftw.lib)
238         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
239         set(FFTW3_LIBPATH ${FFTW3}/lib)
240 endif()
241
242 if(WITH_OPENCOLLADA)
243         set(OPENCOLLADA ${LIBDIR}/opencollada)
244
245         set(OPENCOLLADA_INCLUDE_DIRS
246                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
247                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
248                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
249                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
250                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
251         )
252
253         set(OPENCOLLADA_LIBRARIES
254                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader.lib
255                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework.lib
256                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils.lib
257                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter.lib
258                 ${OPENCOLLADA}/lib/opencollada/MathMLSolver.lib
259                 ${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser.lib
260                 ${OPENCOLLADA}/lib/opencollada/xml.lib
261                 ${OPENCOLLADA}/lib/opencollada/buffer.lib
262                 ${OPENCOLLADA}/lib/opencollada/ftoa.lib
263         )
264
265         list(APPEND OPENCOLLADA_LIBRARIES ${OPENCOLLADA}/lib/opencollada/UTF.lib)
266
267         set(PCRE_LIBRARIES
268                 ${OPENCOLLADA}/lib/opencollada/pcre.lib
269         )
270 endif()
271
272 if(WITH_CODEC_FFMPEG)
273         set(FFMPEG_INCLUDE_DIRS
274                 ${LIBDIR}/ffmpeg/include
275                 ${LIBDIR}/ffmpeg/include/msvc
276         )
277         windows_find_package(FFMPEG)
278         if(NOT FFMPEG_FOUND)
279                 warn_hardcoded_paths(ffmpeg)
280                 set(FFMPEG_LIBRARIES
281                         ${LIBDIR}/ffmpeg/lib/avcodec.lib
282                         ${LIBDIR}/ffmpeg/lib/avformat.lib
283                         ${LIBDIR}/ffmpeg/lib/avdevice.lib
284                         ${LIBDIR}/ffmpeg/lib/avutil.lib
285                         ${LIBDIR}/ffmpeg/lib/swscale.lib
286                         )
287         endif()
288 endif()
289
290 if(WITH_IMAGE_OPENEXR)
291         set(OPENEXR_ROOT_DIR ${LIBDIR}/openexr)
292         set(OPENEXR_VERSION "2.1")
293         windows_find_package(OPENEXR REQUIRED)
294         if(NOT OPENEXR_FOUND)
295                 warn_hardcoded_paths(OpenEXR)
296                 set(OPENEXR ${LIBDIR}/openexr)
297                 set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
298                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR} ${OPENEXR}/include/OpenEXR)
299                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
300                 set(OPENEXR_LIBRARIES
301                         optimized ${OPENEXR_LIBPATH}/Iex_s.lib
302                         optimized ${OPENEXR_LIBPATH}/Half_s.lib
303                         optimized ${OPENEXR_LIBPATH}/IlmImf_s.lib
304                         optimized ${OPENEXR_LIBPATH}/Imath_s.lib
305                         optimized ${OPENEXR_LIBPATH}/IlmThread_s.lib
306                         debug ${OPENEXR_LIBPATH}/Iex_s_d.lib
307                         debug ${OPENEXR_LIBPATH}/Half_s_d.lib
308                         debug ${OPENEXR_LIBPATH}/IlmImf_s_d.lib
309                         debug ${OPENEXR_LIBPATH}/Imath_s_d.lib
310                         debug ${OPENEXR_LIBPATH}/IlmThread_s_d.lib
311                 )
312         endif()
313 endif()
314
315 if(WITH_IMAGE_TIFF)
316         # Try to find tiff first then complain and set static and maybe wrong paths
317         windows_find_package(TIFF)
318         if(NOT TIFF_FOUND)
319                 warn_hardcoded_paths(libtiff)
320                 set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
321                 set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
322         endif()
323 endif()
324
325 if(WITH_JACK)
326         set(JACK_INCLUDE_DIRS
327                 ${LIBDIR}/jack/include/jack
328                 ${LIBDIR}/jack/include
329         )
330         set(JACK_LIBRARIES optimized ${LIBDIR}/jack/lib/libjack.lib debug ${LIBDIR}/jack/lib/libjack_d.lib)
331 endif()
332
333 if(WITH_PYTHON)
334         set(PYTHON_VERSION 3.7) # CACHE STRING)
335
336         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
337         # Use shared libs for vc2008 and vc2010 until we actually have vc2010 libs
338         set(PYTHON_LIBRARY ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}.lib)
339         unset(_PYTHON_VERSION_NO_DOTS)
340
341         # Shared includes for both vc2008 and vc2010
342         set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/include/python${PYTHON_VERSION})
343
344         # uncached vars
345         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
346         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
347 endif()
348
349 if(WITH_BOOST)
350         if(WITH_CYCLES_OSL)
351                 set(boost_extra_libs wave)
352         endif()
353         if(WITH_INTERNATIONAL)
354                 list(APPEND boost_extra_libs locale)
355         endif()
356         if(WITH_OPENVDB)
357                 list(APPEND boost_extra_libs iostreams)
358         endif()
359         set(Boost_USE_STATIC_RUNTIME ON) # prefix lib
360         set(Boost_USE_MULTITHREADED ON) # suffix -mt
361         set(Boost_USE_STATIC_LIBS ON) # suffix -s
362         if(WITH_WINDOWS_FIND_MODULES)
363                 find_package(Boost COMPONENTS date_time filesystem thread regex system ${boost_extra_libs})
364         endif()
365         if(NOT Boost_FOUND)
366                 warn_hardcoded_paths(BOOST)
367                 set(BOOST ${LIBDIR}/boost)
368                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
369                 set(BOOST_LIBPATH ${BOOST}/lib)
370                 if(CMAKE_CL_64)
371                         set(BOOST_POSTFIX "vc140-mt-s-x64-1_68.lib")
372                         set(BOOST_DEBUG_POSTFIX "vc140-mt-sgd-x64-1_68.lib")
373                 else()
374                         set(BOOST_POSTFIX "vc140-mt-s-x32-1_68.lib")
375                         set(BOOST_DEBUG_POSTFIX "vc140-mt-sgd-x32-1_68.lib")
376                 endif()
377                 set(BOOST_LIBRARIES
378                         optimized ${BOOST_LIBPATH}/libboost_date_time-${BOOST_POSTFIX}
379                         optimized ${BOOST_LIBPATH}/libboost_filesystem-${BOOST_POSTFIX}
380                         optimized ${BOOST_LIBPATH}/libboost_regex-${BOOST_POSTFIX}
381                         optimized ${BOOST_LIBPATH}/libboost_system-${BOOST_POSTFIX}
382                         optimized ${BOOST_LIBPATH}/libboost_thread-${BOOST_POSTFIX}
383                         optimized ${BOOST_LIBPATH}/libboost_chrono-${BOOST_POSTFIX}
384                         debug ${BOOST_LIBPATH}/libboost_date_time-${BOOST_DEBUG_POSTFIX}
385                         debug ${BOOST_LIBPATH}/libboost_filesystem-${BOOST_DEBUG_POSTFIX}
386                         debug ${BOOST_LIBPATH}/libboost_regex-${BOOST_DEBUG_POSTFIX}
387                         debug ${BOOST_LIBPATH}/libboost_system-${BOOST_DEBUG_POSTFIX}
388                         debug ${BOOST_LIBPATH}/libboost_thread-${BOOST_DEBUG_POSTFIX}
389                         debug ${BOOST_LIBPATH}/libboost_chrono-${BOOST_DEBUG_POSTFIX}
390                 )
391                 if(WITH_CYCLES_OSL)
392                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
393                                 optimized ${BOOST_LIBPATH}/libboost_wave-${BOOST_POSTFIX}
394                                 debug ${BOOST_LIBPATH}/libboost_wave-${BOOST_DEBUG_POSTFIX})
395                 endif()
396                 if(WITH_INTERNATIONAL)
397                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
398                                 optimized ${BOOST_LIBPATH}/libboost_locale-${BOOST_POSTFIX}
399                                 debug ${BOOST_LIBPATH}/libboost_locale-${BOOST_DEBUG_POSTFIX})
400                 endif()
401         else() # we found boost using find_package
402                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
403                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
404                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
405         endif()
406         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
407 endif()
408
409 if(WITH_OPENIMAGEIO)
410         windows_find_package(OpenImageIO)
411         set(OPENIMAGEIO ${LIBDIR}/openimageio)
412         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
413         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
414         set(OIIO_OPTIMIZED optimized ${OPENIMAGEIO_LIBPATH}/OpenImageIO.lib optimized ${OPENIMAGEIO_LIBPATH}/OpenImageIO_Util.lib)
415         set(OIIO_DEBUG debug ${OPENIMAGEIO_LIBPATH}/OpenImageIO_d.lib debug ${OPENIMAGEIO_LIBPATH}/OpenImageIO_Util_d.lib)
416         set(OPENIMAGEIO_LIBRARIES ${OIIO_OPTIMIZED} ${OIIO_DEBUG})
417
418         set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0")
419         set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
420         set(OPENIMAGEIO_IDIFF "${OPENIMAGEIO}/bin/idiff.exe")
421         add_definitions(-DOIIO_STATIC_BUILD)
422         add_definitions(-DOIIO_NO_SSE=1)
423 endif()
424
425 if(WITH_LLVM)
426         set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH     "Path to the LLVM installation")
427         file(GLOB LLVM_LIBRARY_OPTIMIZED ${LLVM_ROOT_DIR}/lib/*.lib)
428
429         if(EXISTS ${LLVM_ROOT_DIR}/debug/lib)
430                 foreach(LLVM_OPTIMIZED_LIB ${LLVM_LIBRARY_OPTIMIZED})
431                         get_filename_component(LIBNAME ${LLVM_OPTIMIZED_LIB} ABSOLUTE)
432                         list(APPEND LLVM_LIBS optimized ${LIBNAME})
433                 endforeach(LLVM_OPTIMIZED_LIB)
434
435                 file(GLOB LLVM_LIBRARY_DEBUG ${LLVM_ROOT_DIR}/debug/lib/*.lib)
436
437                 foreach(LLVM_DEBUG_LIB ${LLVM_LIBRARY_DEBUG})
438                         get_filename_component(LIBNAME ${LLVM_DEBUG_LIB} ABSOLUTE)
439                         list(APPEND LLVM_LIBS debug ${LIBNAME})
440                 endforeach(LLVM_DEBUG_LIB)
441
442                 set(LLVM_LIBRARY ${LLVM_LIBS})
443         else()
444                 message(WARNING "LLVM debug libs not present on this system. Using release libs for debug builds.")
445                 set(LLVM_LIBRARY ${LLVM_LIBRARY_OPTIMIZED})
446         endif()
447
448 endif()
449
450 if(WITH_OPENCOLORIO)
451         set(OPENCOLORIO ${LIBDIR}/opencolorio)
452         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
453         set(OPENCOLORIO_LIBPATH ${LIBDIR}/opencolorio/lib)
454         set(OPENCOLORIO_LIBRARIES
455                 optimized ${OPENCOLORIO_LIBPATH}/OpenColorIO.lib
456                 optimized ${OPENCOLORIO_LIBPATH}/tinyxml.lib
457                 optimized ${OPENCOLORIO_LIBPATH}/libyaml-cpp.lib
458                 debug ${OPENCOLORIO_LIBPATH}/OpenColorIO_d.lib
459                 debug ${OPENCOLORIO_LIBPATH}/tinyxml_d.lib
460                 debug ${OPENCOLORIO_LIBPATH}/libyaml-cpp_d.lib
461         )
462         set(OPENCOLORIO_DEFINITIONS)
463 endif()
464
465 if(WITH_OPENVDB)
466         set(BLOSC_LIBRARIES optimized ${LIBDIR}/blosc/lib/libblosc.lib debug ${LIBDIR}/blosc/lib/libblosc_d.lib)
467         set(TBB_LIBRARIES optimized ${LIBDIR}/tbb/lib/tbb.lib debug ${LIBDIR}/tbb/lib/tbb_debug.lib)
468         set(TBB_INCLUDE_DIR ${LIBDIR}/tbb/include)
469         set(OPENVDB ${LIBDIR}/openvdb)
470         set(OPENVDB_LIBPATH ${LIBDIR}/openvdb/lib)
471         set(OPENVDB_INCLUDE_DIRS ${OPENVDB}/include ${TBB_INCLUDE_DIR})
472         set(OPENVDB_LIBRARIES optimized ${OPENVDB_LIBPATH}/openvdb.lib debug ${OPENVDB_LIBPATH}/openvdb_d.lib ${TBB_LIBRARIES} ${BLOSC_LIBRARIES})
473         set(OPENVDB_DEFINITIONS -DNOMINMAX)
474 endif()
475
476 if(WITH_ALEMBIC)
477         set(ALEMBIC ${LIBDIR}/alembic)
478         set(ALEMBIC_INCLUDE_DIR ${ALEMBIC}/include)
479         set(ALEMBIC_INCLUDE_DIRS ${ALEMBIC_INCLUDE_DIR})
480         set(ALEMBIC_LIBPATH ${ALEMBIC}/lib)
481         set(ALEMBIC_LIBRARIES optimized ${ALEMBIC}/lib/alembic.lib debug ${ALEMBIC}/lib/alembic_d.lib)
482         set(ALEMBIC_FOUND 1)
483 endif()
484
485 if(WITH_MOD_CLOTH_ELTOPO)
486         set(LAPACK ${LIBDIR}/lapack)
487         # set(LAPACK_INCLUDE_DIR ${LAPACK}/include)
488         set(LAPACK_LIBPATH ${LAPACK}/lib)
489         set(LAPACK_LIBRARIES
490                 ${LIBDIR}/lapack/lib/libf2c.lib
491                 ${LIBDIR}/lapack/lib/clapack_nowrap.lib
492                 ${LIBDIR}/lapack/lib/BLAS_nowrap.lib
493         )
494 endif()
495
496 if(WITH_IMAGE_OPENJPEG)
497         set(OPENJPEG ${LIBDIR}/openjpeg)
498         set(OPENJPEG_INCLUDE_DIRS ${OPENJPEG}/include/openjpeg-2.3)
499         set(OPENJPEG_LIBRARIES ${OPENJPEG}/lib/openjp2.lib)
500 endif()
501
502 if(WITH_OPENSUBDIV)
503         set(OPENSUBDIV_INCLUDE_DIR ${LIBDIR}/opensubdiv/include)
504         set(OPENSUBDIV_LIBPATH ${LIBDIR}/opensubdiv/lib)
505         set(OPENSUBDIV_LIBRARIES
506                 optimized ${OPENSUBDIV_LIBPATH}/osdCPU.lib
507                 optimized ${OPENSUBDIV_LIBPATH}/osdGPU.lib
508                 debug ${OPENSUBDIV_LIBPATH}/osdCPU_d.lib
509                 debug ${OPENSUBDIV_LIBPATH}/osdGPU_d.lib
510         )
511         set(OPENSUBDIV_HAS_OPENMP TRUE)
512         set(OPENSUBDIV_HAS_TBB FALSE)
513         set(OPENSUBDIV_HAS_OPENCL TRUE)
514         set(OPENSUBDIV_HAS_CUDA FALSE)
515         set(OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK TRUE)
516         set(OPENSUBDIV_HAS_GLSL_COMPUTE TRUE)
517         windows_find_package(OpenSubdiv)
518 endif()
519
520 if(WITH_SDL)
521         set(SDL ${LIBDIR}/sdl)
522         set(SDL_INCLUDE_DIR ${SDL}/include)
523         set(SDL_LIBPATH ${SDL}/lib)
524         set(SDL_LIBRARY ${SDL_LIBPATH}/SDL2.lib)
525 endif()
526
527 # Audio IO
528 if(WITH_SYSTEM_AUDASPACE)
529         set(AUDASPACE_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
530         set(AUDASPACE_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace.lib)
531         set(AUDASPACE_C_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
532         set(AUDASPACE_C_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace-c.lib)
533         set(AUDASPACE_PY_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
534         set(AUDASPACE_PY_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace-py.lib)
535 endif()
536
537 # used in many places so include globally, like OpenGL
538 blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
539
540 #find signtool
541 set(ProgramFilesX86_NAME "ProgramFiles(x86)") #env dislikes the ( )
542 find_program(SIGNTOOL_EXE signtool
543         HINTS
544                 "$ENV{${ProgramFilesX86_NAME}}/Windows Kits/10/bin/x86/"
545                 "$ENV{ProgramFiles}/Windows Kits/10/bin/x86/"
546                 "$ENV{${ProgramFilesX86_NAME}}/Windows Kits/8.1/bin/x86/"
547                 "$ENV{ProgramFiles}/Windows Kits/8.1/bin/x86/"
548                 "$ENV{${ProgramFilesX86_NAME}}/Windows Kits/8.0/bin/x86/"
549                 "$ENV{ProgramFiles}/Windows Kits/8.0/bin/x86/"
550 )
551 set(WINTAB_INC ${LIBDIR}/wintab/include)
552
553 if(WITH_OPENAL)
554         set(OPENAL ${LIBDIR}/openal)
555         set(OPENALDIR ${LIBDIR}/openal)
556         set(OPENAL_INCLUDE_DIR ${OPENAL}/include/AL)
557         set(OPENAL_LIBPATH ${OPENAL}/lib)
558         if(MSVC)
559                 set(OPENAL_LIBRARY ${OPENAL_LIBPATH}/openal32.lib)
560         else()
561                 set(OPENAL_LIBRARY ${OPENAL_LIBPATH}/wrap_oal.lib)
562         endif()
563
564 endif()
565
566 if(WITH_CODEC_SNDFILE)
567         set(LIBSNDFILE ${LIBDIR}/sndfile)
568         set(LIBSNDFILE_INCLUDE_DIRS ${LIBSNDFILE}/include)
569         set(LIBSNDFILE_LIBPATH ${LIBSNDFILE}/lib) # TODO, deprecate
570         set(LIBSNDFILE_LIBRARIES ${LIBSNDFILE_LIBPATH}/libsndfile-1.lib)
571 endif()
572
573 if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
574         add_definitions(-D__SSE__ -D__MMX__)
575 endif()
576
577 if(WITH_CYCLES_OSL)
578         set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
579
580         find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
581         find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
582         find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
583         find_library(OSL_LIB_EXEC_DEBUG NAMES oslexec_d PATHS ${CYCLES_OSL}/lib)
584         find_library(OSL_LIB_COMP_DEBUG NAMES oslcomp_d PATHS ${CYCLES_OSL}/lib)
585         find_library(OSL_LIB_QUERY_DEBUG NAMES oslquery_d PATHS ${CYCLES_OSL}/lib)
586         list(APPEND OSL_LIBRARIES
587                 optimized ${OSL_LIB_COMP}
588                 optimized ${OSL_LIB_EXEC}
589                 optimized ${OSL_LIB_QUERY}
590                 optimized ${CYCLES_OSL}/lib/pugixml.lib
591                 debug ${OSL_LIB_EXEC_DEBUG}
592                 debug ${OSL_LIB_COMP_DEBUG}
593                 debug ${OSL_LIB_QUERY_DEBUG}
594                 debug ${CYCLES_OSL}/lib/pugixml_d.lib
595         )
596         find_path(OSL_INCLUDE_DIR OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
597         find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
598
599         if(OSL_INCLUDE_DIR AND OSL_LIBRARIES AND OSL_COMPILER)
600                 set(OSL_FOUND TRUE)
601         else()
602                 message(STATUS "OSL not found")
603                 set(WITH_CYCLES_OSL OFF)
604         endif()
605 endif()
606
607 if(WITH_CYCLES_EMBREE)
608         windows_find_package(Embree)
609         if(NOT EMBREE_FOUND)
610                 set(EMBREE_INCLUDE_DIRS ${LIBDIR}/embree/include)
611                 set(EMBREE_LIBRARIES
612                         optimized ${LIBDIR}/embree/lib/embree3.lib
613                         optimized ${LIBDIR}/embree/lib/embree_avx2.lib
614                         optimized ${LIBDIR}/embree/lib/embree_avx.lib
615                         optimized ${LIBDIR}/embree/lib/embree_sse42.lib
616                         optimized ${LIBDIR}/embree/lib/lexers.lib
617                         optimized ${LIBDIR}/embree/lib/math.lib
618                         optimized ${LIBDIR}/embree/lib/simd.lib
619                         optimized ${LIBDIR}/embree/lib/sys.lib
620                         optimized ${LIBDIR}/embree/lib/tasking.lib
621
622                         debug ${LIBDIR}/embree/lib/embree3_d.lib
623                         debug ${LIBDIR}/embree/lib/embree_avx2_d.lib
624                         debug ${LIBDIR}/embree/lib/embree_avx_d.lib
625                         debug ${LIBDIR}/embree/lib/embree_sse42_d.lib
626                         debug ${LIBDIR}/embree/lib/lexers_d.lib
627                         debug ${LIBDIR}/embree/lib/math_d.lib
628                         debug ${LIBDIR}/embree/lib/simd_d.lib
629                         debug ${LIBDIR}/embree/lib/sys_d.lib
630                         debug ${LIBDIR}/embree/lib/tasking_d.lib)
631         endif()
632 endif()
633
634 if (WINDOWS_PYTHON_DEBUG)
635         # Include the system scripts in the blender_python_system_scripts project.
636         FILE(GLOB_RECURSE inFiles "${CMAKE_SOURCE_DIR}/release/scripts/*.*" )
637         ADD_CUSTOM_TARGET(blender_python_system_scripts SOURCES ${inFiles})
638         foreach(_source IN ITEMS ${inFiles})
639                 get_filename_component(_source_path "${_source}" PATH)
640                 string(REPLACE "${CMAKE_SOURCE_DIR}/release/scripts/" "" _source_path "${_source_path}")
641                 string(REPLACE "/" "\\" _group_path "${_source_path}")
642                 source_group("${_group_path}" FILES "${_source}")
643         endforeach()
644         # Include the user scripts from the profile folder in the blender_python_user_scripts project.
645         set(USER_SCRIPTS_ROOT "$ENV{appdata}/blender foundation/blender/${BLENDER_VERSION}")
646         file(TO_CMAKE_PATH ${USER_SCRIPTS_ROOT} USER_SCRIPTS_ROOT)
647         FILE(GLOB_RECURSE inFiles "${USER_SCRIPTS_ROOT}/scripts/*.*" )
648         ADD_CUSTOM_TARGET(blender_python_user_scripts SOURCES ${inFiles})
649         foreach(_source IN ITEMS ${inFiles})
650                 get_filename_component(_source_path "${_source}" PATH)
651                 string(REPLACE "${USER_SCRIPTS_ROOT}/scripts" "" _source_path "${_source_path}")
652                 string(REPLACE "/" "\\" _group_path "${_source_path}")
653                 source_group("${_group_path}" FILES "${_source}")
654         endforeach()
655         set_target_properties(blender_python_system_scripts PROPERTIES FOLDER "scripts")
656         set_target_properties(blender_python_user_scripts PROPERTIES FOLDER "scripts")
657         # Set the default debugging options for the project, only write this file once so the user
658         # is free to override them at their own perril.
659         set(USER_PROPS_FILE "${CMAKE_CURRENT_BINARY_DIR}/source/creator/blender.Cpp.user.props")
660         if(NOT EXISTS ${USER_PROPS_FILE})
661                 # Layout below is messy, because otherwise the generated file will look messy.
662                 file(WRITE ${USER_PROPS_FILE} "<?xml version=\"1.0\" encoding=\"utf-8\"?>
663 <Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">
664         <PropertyGroup>
665                 <LocalDebuggerCommandArguments>-con --env-system-scripts \"${CMAKE_SOURCE_DIR}/release/scripts\" </LocalDebuggerCommandArguments>
666         </PropertyGroup>
667 </Project>")
668         endif()
669 endif()