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