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