ef3ef7b65170fa697182e0e68e7d49ac580ed238
[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 # Libraries configuration for Windows when compiling with MSVC.
33
34 set_property(GLOBAL PROPERTY USE_FOLDERS ${WINDOWS_USE_VISUAL_STUDIO_FOLDERS})
35
36 if(NOT WITH_PYTHON_MODULE)
37         set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT blender)
38 endif()
39
40 macro(warn_hardcoded_paths package_name
41         )
42         if(WITH_WINDOWS_FIND_MODULES)
43                 message(WARNING "Using HARDCODED ${package_name} locations")
44         endif()
45 endmacro()
46
47 macro(windows_find_package package_name
48         )
49         if(WITH_WINDOWS_FIND_MODULES)
50                 find_package(${package_name})
51         endif()
52 endmacro()
53
54 macro(find_package_wrapper)
55         if(WITH_WINDOWS_FIND_MODULES)
56                 find_package(${ARGV})
57         endif()
58 endmacro()
59
60 add_definitions(-DWIN32)
61
62 # Needed, otherwise system encoding causes utf-8 encoding to fail in some cases (C4819)
63 add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
64 add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
65
66 # Minimum MSVC Version
67 if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
68         if(MSVC_VERSION EQUAL 1800)
69                 set(_min_ver "18.0.31101")
70                 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${_min_ver})
71                         message(FATAL_ERROR
72                                 "Visual Studio 2013 (Update 4, ${_min_ver}) required, "
73                                 "found (${CMAKE_CXX_COMPILER_VERSION})")
74                 endif()
75         endif()
76         if(MSVC_VERSION EQUAL 1900)
77                 set(_min_ver "19.0.24210")
78                 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${_min_ver})
79                         message(FATAL_ERROR
80                                 "Visual Studio 2015 (Update 3, ${_min_ver}) required, "
81                                 "found (${CMAKE_CXX_COMPILER_VERSION})")
82                 endif()
83         endif()
84 endif()
85 unset(_min_ver)
86
87 # needed for some MSVC installations
88 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
89 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
90 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
91
92 list(APPEND PLATFORM_LINKLIBS
93         ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32
94         advapi32 shfolder shell32 ole32 oleaut32 uuid psapi Dbghelp
95 )
96
97 if(WITH_INPUT_IME)
98         list(APPEND PLATFORM_LINKLIBS imm32)
99 endif()
100
101 add_definitions(
102         -D_CRT_NONSTDC_NO_DEPRECATE
103         -D_CRT_SECURE_NO_DEPRECATE
104         -D_SCL_SECURE_NO_DEPRECATE
105         -D_CONSOLE
106         -D_LIB
107 )
108
109 # MSVC11 needs _ALLOW_KEYWORD_MACROS to build
110 add_definitions(-D_ALLOW_KEYWORD_MACROS)
111
112 # We want to support Vista level ABI
113 add_definitions(-D_WIN32_WINNT=0x600)
114
115 # Make cmake find the msvc redistributables
116 set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP FALSE)
117 set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE)
118 set(CMAKE_INSTALL_OPENMP_LIBRARIES ${WITH_OPENMP})
119 set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
120 include(InstallRequiredSystemLibraries)
121
122 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /nologo /J /Gd /MP /EHsc")
123 set(CMAKE_C_FLAGS     "${CMAKE_C_FLAGS} /nologo /J /Gd /MP")
124
125 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
126 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
127 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
128 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
129 set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MT")
130 set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /MT")
131 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MT")
132 set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MT")
133
134 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO ")
135 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib ")
136
137 # Ignore meaningless for us linker warnings.
138 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /ignore:4049 /ignore:4217 /ignore:4221")
139 set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221")
140
141 if(CMAKE_CL_64)
142         set(PLATFORM_LINKFLAGS "/MACHINE:X64 ${PLATFORM_LINKFLAGS}")
143 else()
144         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
145 endif()
146
147 set(PLATFORM_LINKFLAGS_DEBUG "/IGNORE:4099 /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
148
149 if(NOT DEFINED LIBDIR)
150
151         # Setup 64bit and 64bit windows systems
152         if(CMAKE_CL_64)
153                 message(STATUS "64 bit compiler detected.")
154                 set(LIBDIR_BASE "win64")
155         else()
156                 message(STATUS "32 bit compiler detected.")
157                 set(LIBDIR_BASE "windows")
158         endif()
159         # Can be 1910..1912
160         if(MSVC_VERSION GREATER 1909)
161                 message(STATUS "Visual Studio 2017 detected.")
162                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc14)
163         elseif(MSVC_VERSION EQUAL 1900)
164                 message(STATUS "Visual Studio 2015 detected.")
165                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc14)
166         else()
167                 message(STATUS "Visual Studio 2013 detected.")
168                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc12)
169         endif()
170 else()
171         message(STATUS "Using pre-compiled LIBDIR: ${LIBDIR}")
172 endif()
173 if(NOT EXISTS "${LIBDIR}/")
174         message(FATAL_ERROR "Windows requires pre-compiled libs at: '${LIBDIR}'")
175 endif()
176
177 # Add each of our libraries to our cmake_prefix_path so find_package() could work
178 file(GLOB children RELATIVE ${LIBDIR} ${LIBDIR}/*)
179 foreach(child ${children})
180         if(IS_DIRECTORY ${LIBDIR}/${child})
181                 list(APPEND CMAKE_PREFIX_PATH  ${LIBDIR}/${child})
182         endif()
183 endforeach()
184
185 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
186 set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz_st.lib)
187 set(ZLIB_INCLUDE_DIR ${LIBDIR}/zlib/include)
188 set(ZLIB_LIBRARY ${LIBDIR}/zlib/lib/libz_st.lib)
189 set(ZLIB_DIR ${LIBDIR}/zlib)
190
191 windows_find_package(zlib) # we want to find before finding things that depend on it like png
192 windows_find_package(png)
193
194 if(NOT PNG_FOUND)
195         warn_hardcoded_paths(libpng)
196         set(PNG_PNG_INCLUDE_DIR ${LIBDIR}/png/include)
197         set(PNG_LIBRARIES ${LIBDIR}/png/lib/libpng.lib)
198         set(PNG "${LIBDIR}/png")
199         set(PNG_INCLUDE_DIRS "${PNG}/include")
200         set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
201 endif()
202
203 set(JPEG_NAMES ${JPEG_NAMES} libjpeg)
204 windows_find_package(jpeg REQUIRED)
205 if(NOT JPEG_FOUND)
206         warn_hardcoded_paths(jpeg)
207         set(JPEG_INCLUDE_DIR ${LIBDIR}/jpeg/include)
208         set(JPEG_LIBRARIES ${LIBDIR}/jpeg/lib/libjpeg.lib)
209 endif()
210
211 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
212 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
213
214 set(FREETYPE ${LIBDIR}/freetype)
215 set(FREETYPE_INCLUDE_DIRS
216         ${LIBDIR}/freetype/include
217         ${LIBDIR}/freetype/include/freetype2
218 )
219 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
220 windows_find_package(freetype REQUIRED)
221
222 if(WITH_FFTW3)
223         set(FFTW3 ${LIBDIR}/fftw3)
224         set(FFTW3_LIBRARIES ${FFTW3}/lib/libfftw.lib)
225         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
226         set(FFTW3_LIBPATH ${FFTW3}/lib)
227 endif()
228
229 if(WITH_OPENCOLLADA)
230         set(OPENCOLLADA ${LIBDIR}/opencollada)
231
232         set(OPENCOLLADA_INCLUDE_DIRS
233                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
234                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
235                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
236                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
237                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
238         )
239
240         set(OPENCOLLADA_LIBRARIES
241                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader.lib
242                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework.lib
243                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils.lib
244                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter.lib
245                 ${OPENCOLLADA}/lib/opencollada/MathMLSolver.lib
246                 ${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser.lib
247                 ${OPENCOLLADA}/lib/opencollada/xml.lib
248                 ${OPENCOLLADA}/lib/opencollada/buffer.lib
249                 ${OPENCOLLADA}/lib/opencollada/ftoa.lib
250         )
251
252         if(NOT WITH_LLVM)
253                 list(APPEND OPENCOLLADA_LIBRARIES ${OPENCOLLADA}/lib/opencollada/UTF.lib)
254         endif()
255
256         set(PCRE_LIBRARIES
257                 ${OPENCOLLADA}/lib/opencollada/pcre.lib
258         )
259 endif()
260
261 if(WITH_CODEC_FFMPEG)
262         set(FFMPEG_INCLUDE_DIRS
263                 ${LIBDIR}/ffmpeg/include
264                 ${LIBDIR}/ffmpeg/include/msvc
265         )
266         windows_find_package(FFMPEG)
267         if(NOT FFMPEG_FOUND)
268                 warn_hardcoded_paths(ffmpeg)
269                 set(FFMPEG_LIBRARY_VERSION 57)
270                 set(FFMPEG_LIBRARY_VERSION_AVU 55)
271                 set(FFMPEG_LIBRARIES
272                         ${LIBDIR}/ffmpeg/lib/avcodec.lib
273                         ${LIBDIR}/ffmpeg/lib/avformat.lib
274                         ${LIBDIR}/ffmpeg/lib/avdevice.lib
275                         ${LIBDIR}/ffmpeg/lib/avutil.lib
276                         ${LIBDIR}/ffmpeg/lib/swscale.lib
277                         )
278         endif()
279 endif()
280
281 if(WITH_IMAGE_OPENEXR)
282         set(OPENEXR_ROOT_DIR ${LIBDIR}/openexr)
283         set(OPENEXR_VERSION "2.1")
284         windows_find_package(OPENEXR REQUIRED)
285         if(NOT OPENEXR_FOUND)
286                 warn_hardcoded_paths(OpenEXR)
287                 set(OPENEXR ${LIBDIR}/openexr)
288                 set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
289                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR} ${OPENEXR}/include/OpenEXR)
290                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
291                 set(OPENEXR_LIBRARIES
292                         optimized ${OPENEXR_LIBPATH}/Iex-2_2.lib
293                         optimized ${OPENEXR_LIBPATH}/Half.lib
294                         optimized ${OPENEXR_LIBPATH}/IlmImf-2_2.lib
295                         optimized ${OPENEXR_LIBPATH}/Imath-2_2.lib
296                         optimized ${OPENEXR_LIBPATH}/IlmThread-2_2.lib
297                         debug ${OPENEXR_LIBPATH}/Iex-2_2_d.lib
298                         debug ${OPENEXR_LIBPATH}/Half_d.lib
299                         debug ${OPENEXR_LIBPATH}/IlmImf-2_2_d.lib
300                         debug ${OPENEXR_LIBPATH}/Imath-2_2_d.lib
301                         debug ${OPENEXR_LIBPATH}/IlmThread-2_2_d.lib
302                 )
303         endif()
304 endif()
305
306 if(WITH_IMAGE_TIFF)
307         # Try to find tiff first then complain and set static and maybe wrong paths
308         windows_find_package(TIFF)
309         if(NOT TIFF_FOUND)
310                 warn_hardcoded_paths(libtiff)
311                 set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
312                 set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
313         endif()
314 endif()
315
316 if(WITH_JACK)
317         set(JACK_INCLUDE_DIRS
318                 ${LIBDIR}/jack/include/jack
319                 ${LIBDIR}/jack/include
320         )
321         set(JACK_LIBRARIES optimized ${LIBDIR}/jack/lib/libjack.lib debug ${LIBDIR}/jack/lib/libjack_d.lib)
322 endif()
323
324 if(WITH_PYTHON)
325         set(PYTHON_VERSION 3.6) # CACHE STRING)
326
327         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
328         # Use shared libs for vc2008 and vc2010 until we actually have vc2010 libs
329         set(PYTHON_LIBRARY ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}.lib)
330         unset(_PYTHON_VERSION_NO_DOTS)
331
332         # Shared includes for both vc2008 and vc2010
333         set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/include/python${PYTHON_VERSION})
334
335         # uncached vars
336         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
337         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
338 endif()
339
340 if(WITH_BOOST)
341         if(WITH_CYCLES_OSL)
342                 set(boost_extra_libs wave)
343         endif()
344         if(WITH_INTERNATIONAL)
345                 list(APPEND boost_extra_libs locale)
346         endif()
347         if(WITH_OPENVDB)
348                 list(APPEND boost_extra_libs iostreams)
349         endif()
350         set(Boost_USE_STATIC_RUNTIME ON) # prefix lib
351         set(Boost_USE_MULTITHREADED ON) # suffix -mt
352         set(Boost_USE_STATIC_LIBS ON) # suffix -s
353         if(WITH_WINDOWS_FIND_MODULES)
354                 find_package(Boost COMPONENTS date_time filesystem thread regex system ${boost_extra_libs})
355         endif()
356         if(NOT Boost_FOUND)
357                 warn_hardcoded_paths(BOOST)
358                 set(BOOST ${LIBDIR}/boost)
359                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
360                 if(MSVC12)
361                         set(BOOST_LIBPATH ${BOOST}/lib)
362                         set(BOOST_POSTFIX "vc120-mt-s-1_60.lib")
363                         set(BOOST_DEBUG_POSTFIX "vc120-mt-sgd-1_60.lib")
364                 else()
365                         set(BOOST_LIBPATH ${BOOST}/lib)
366                         set(BOOST_POSTFIX "vc140-mt-s-1_60.lib")
367                         set(BOOST_DEBUG_POSTFIX "vc140-mt-sgd-1_60.lib")
368                 endif()
369                 set(BOOST_LIBRARIES
370                         optimized ${BOOST_LIBPATH}/libboost_date_time-${BOOST_POSTFIX}
371                         optimized ${BOOST_LIBPATH}/libboost_filesystem-${BOOST_POSTFIX}
372                         optimized ${BOOST_LIBPATH}/libboost_regex-${BOOST_POSTFIX}
373                         optimized ${BOOST_LIBPATH}/libboost_system-${BOOST_POSTFIX}
374                         optimized ${BOOST_LIBPATH}/libboost_thread-${BOOST_POSTFIX}
375                         optimized ${BOOST_LIBPATH}/libboost_chrono-${BOOST_POSTFIX}
376                         debug ${BOOST_LIBPATH}/libboost_date_time-${BOOST_DEBUG_POSTFIX}
377                         debug ${BOOST_LIBPATH}/libboost_filesystem-${BOOST_DEBUG_POSTFIX}
378                         debug ${BOOST_LIBPATH}/libboost_regex-${BOOST_DEBUG_POSTFIX}
379                         debug ${BOOST_LIBPATH}/libboost_system-${BOOST_DEBUG_POSTFIX}
380                         debug ${BOOST_LIBPATH}/libboost_thread-${BOOST_DEBUG_POSTFIX}
381                         debug ${BOOST_LIBPATH}/libboost_chrono-${BOOST_DEBUG_POSTFIX}
382                 )
383                 if(WITH_CYCLES_OSL)
384                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
385                                 optimized ${BOOST_LIBPATH}/libboost_wave-${BOOST_POSTFIX}
386                                 debug ${BOOST_LIBPATH}/libboost_wave-${BOOST_DEBUG_POSTFIX})
387                 endif()
388                 if(WITH_INTERNATIONAL)
389                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
390                                 optimized ${BOOST_LIBPATH}/libboost_locale-${BOOST_POSTFIX}
391                                 debug ${BOOST_LIBPATH}/libboost_locale-${BOOST_DEBUG_POSTFIX})
392                 endif()
393         else() # we found boost using find_package
394                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
395                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
396                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
397         endif()
398         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
399 endif()
400
401 if(WITH_OPENIMAGEIO)
402         windows_find_package(OpenImageIO)
403         set(OPENIMAGEIO ${LIBDIR}/openimageio)
404         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
405         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
406         set(OIIO_OPTIMIZED optimized ${OPENIMAGEIO_LIBPATH}/OpenImageIO.lib optimized ${OPENIMAGEIO_LIBPATH}/OpenImageIO_Util.lib)
407         set(OIIO_DEBUG debug ${OPENIMAGEIO_LIBPATH}/OpenImageIO_d.lib debug ${OPENIMAGEIO_LIBPATH}/OpenImageIO_Util_d.lib)
408         set(OPENIMAGEIO_LIBRARIES ${OIIO_OPTIMIZED} ${OIIO_DEBUG})
409         
410         set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0")
411         set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
412         set(OPENIMAGEIO_IDIFF "${OPENIMAGEIO}/bin/idiff.exe")
413         add_definitions(-DOIIO_STATIC_BUILD)
414         add_definitions(-DOIIO_NO_SSE=1)
415 endif()
416
417 if(WITH_LLVM)
418         set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH     "Path to the LLVM installation")
419         file(GLOB LLVM_LIBRARY_OPTIMIZED ${LLVM_ROOT_DIR}/lib/*.lib)
420
421         if(EXISTS ${LLVM_ROOT_DIR}/debug/lib)
422                 foreach(LLVM_OPTIMIZED_LIB ${LLVM_LIBRARY_OPTIMIZED})
423                         get_filename_component(LIBNAME ${LLVM_OPTIMIZED_LIB} ABSOLUTE)
424                         list(APPEND LLVM_LIBS optimized ${LIBNAME})
425                 endforeach(LLVM_OPTIMIZED_LIB)
426
427                 file(GLOB LLVM_LIBRARY_DEBUG ${LLVM_ROOT_DIR}/debug/lib/*.lib)
428
429                 foreach(LLVM_DEBUG_LIB ${LLVM_LIBRARY_DEBUG})
430                         get_filename_component(LIBNAME ${LLVM_DEBUG_LIB} ABSOLUTE)
431                         list(APPEND LLVM_LIBS debug ${LIBNAME})
432                 endforeach(LLVM_DEBUG_LIB)
433
434                 set(LLVM_LIBRARY ${LLVM_LIBS})
435         else()
436                 message(WARNING "LLVM debug libs not present on this system. Using release libs for debug builds.")
437                 set(LLVM_LIBRARY ${LLVM_LIBRARY_OPTIMIZED})
438         endif()
439
440 endif()
441
442 if(WITH_OPENCOLORIO)
443         set(OPENCOLORIO ${LIBDIR}/opencolorio)
444         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
445         set(OPENCOLORIO_LIBPATH ${LIBDIR}/opencolorio/lib)
446         set(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBPATH}/OpenColorIO.lib)
447         set(OPENCOLORIO_DEFINITIONS)
448 endif()
449
450 if(WITH_OPENVDB)
451         set(BLOSC_LIBRARIES optimized ${LIBDIR}/blosc/lib/libblosc.lib debug ${LIBDIR}/blosc/lib/libblosc_d.lib)
452         set(TBB_LIBRARIES optimized ${LIBDIR}/tbb/lib/tbb.lib debug ${LIBDIR}/tbb/lib/tbb_debug.lib)
453         set(TBB_INCLUDE_DIR ${LIBDIR}/tbb/include)
454         set(OPENVDB ${LIBDIR}/openvdb)
455         set(OPENVDB_LIBPATH ${LIBDIR}/openvdb/lib)
456         set(OPENVDB_INCLUDE_DIRS ${OPENVDB}/include ${TBB_INCLUDE_DIR})
457         set(OPENVDB_LIBRARIES optimized ${OPENVDB_LIBPATH}/openvdb.lib debug ${OPENVDB_LIBPATH}/openvdb_d.lib ${TBB_LIBRARIES} ${BLOSC_LIBRARIES})
458         
459 endif()
460
461 if(WITH_ALEMBIC)
462         set(ALEMBIC ${LIBDIR}/alembic)
463         set(ALEMBIC_INCLUDE_DIR ${ALEMBIC}/include)
464         set(ALEMBIC_INCLUDE_DIRS ${ALEMBIC_INCLUDE_DIR})
465         set(ALEMBIC_LIBPATH ${ALEMBIC}/lib)
466         set(ALEMBIC_LIBRARIES optimized ${ALEMBIC}/lib/alembic.lib debug ${ALEMBIC}/lib/alembic_d.lib)
467         set(ALEMBIC_FOUND 1)
468 endif()
469
470 if(WITH_MOD_CLOTH_ELTOPO)
471         set(LAPACK ${LIBDIR}/lapack)
472         # set(LAPACK_INCLUDE_DIR ${LAPACK}/include)
473         set(LAPACK_LIBPATH ${LAPACK}/lib)
474         set(LAPACK_LIBRARIES
475                 ${LIBDIR}/lapack/lib/libf2c.lib
476                 ${LIBDIR}/lapack/lib/clapack_nowrap.lib
477                 ${LIBDIR}/lapack/lib/BLAS_nowrap.lib
478         )
479 endif()
480
481 if(WITH_OPENSUBDIV OR WITH_CYCLES_OPENSUBDIV)
482         set(OPENSUBDIV_INCLUDE_DIR ${LIBDIR}/opensubdiv/include)
483         set(OPENSUBDIV_LIBPATH ${LIBDIR}/opensubdiv/lib)
484         set(OPENSUBDIV_LIBRARIES
485                 optimized ${OPENSUBDIV_LIBPATH}/osdCPU.lib
486                 optimized ${OPENSUBDIV_LIBPATH}/osdGPU.lib
487                 debug ${OPENSUBDIV_LIBPATH}/osdCPU_d.lib
488                 debug ${OPENSUBDIV_LIBPATH}/osdGPU_d.lib
489         )
490         set(OPENSUBDIV_HAS_OPENMP TRUE)
491         set(OPENSUBDIV_HAS_TBB FALSE)
492         set(OPENSUBDIV_HAS_OPENCL TRUE)
493         set(OPENSUBDIV_HAS_CUDA FALSE)
494         set(OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK TRUE)
495         set(OPENSUBDIV_HAS_GLSL_COMPUTE TRUE)
496         windows_find_package(OpenSubdiv)
497 endif()
498
499 if(WITH_SDL)
500         set(SDL ${LIBDIR}/sdl)
501         set(SDL_INCLUDE_DIR ${SDL}/include)
502         set(SDL_LIBPATH ${SDL}/lib)
503         set(SDL_LIBRARY ${SDL_LIBPATH}/SDL2.lib)
504 endif()
505
506 # Audio IO
507 if(WITH_SYSTEM_AUDASPACE)
508         set(AUDASPACE_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
509         set(AUDASPACE_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace.lib)
510         set(AUDASPACE_C_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
511         set(AUDASPACE_C_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace-c.lib)
512         set(AUDASPACE_PY_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
513         set(AUDASPACE_PY_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace-py.lib)
514 endif()
515
516 # used in many places so include globally, like OpenGL
517 blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
518
519 #find signtool
520 set(ProgramFilesX86_NAME "ProgramFiles(x86)") #env dislikes the ( )
521 find_program(SIGNTOOL_EXE signtool
522         HINTS
523                 "$ENV{${ProgramFilesX86_NAME}}/Windows Kits/10/bin/x86/"
524                 "$ENV{ProgramFiles}/Windows Kits/10/bin/x86/"
525                 "$ENV{${ProgramFilesX86_NAME}}/Windows Kits/8.1/bin/x86/"
526                 "$ENV{ProgramFiles}/Windows Kits/8.1/bin/x86/"
527                 "$ENV{${ProgramFilesX86_NAME}}/Windows Kits/8.0/bin/x86/"
528                 "$ENV{ProgramFiles}/Windows Kits/8.0/bin/x86/"
529 )
530 set(WINTAB_INC ${LIBDIR}/wintab/include)
531
532 if(WITH_OPENAL)
533         set(OPENAL ${LIBDIR}/openal)
534         set(OPENALDIR ${LIBDIR}/openal)
535         set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
536         set(OPENAL_LIBPATH ${OPENAL}/lib)
537         if(MSVC)
538                 set(OPENAL_LIBRARY ${OPENAL_LIBPATH}/openal32.lib)
539         else()
540                 set(OPENAL_LIBRARY ${OPENAL_LIBPATH}/wrap_oal.lib)
541         endif()
542         
543 endif()
544
545 if(WITH_CODEC_SNDFILE)
546         set(SNDFILE ${LIBDIR}/sndfile)
547         set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
548         set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
549         set(SNDFILE_LIBRARIES ${SNDFILE_LIBPATH}/libsndfile-1.lib)
550         
551 endif()
552
553 if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
554         add_definitions(-D__SSE__ -D__MMX__)
555 endif()
556
557 if(WITH_CYCLES_OSL)
558         set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
559
560         find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
561         find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
562         find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
563         find_library(OSL_LIB_EXEC_DEBUG NAMES oslexec_d PATHS ${CYCLES_OSL}/lib)
564         find_library(OSL_LIB_COMP_DEBUG NAMES oslcomp_d PATHS ${CYCLES_OSL}/lib)
565         find_library(OSL_LIB_QUERY_DEBUG NAMES oslquery_d PATHS ${CYCLES_OSL}/lib)
566         list(APPEND OSL_LIBRARIES
567                 optimized ${OSL_LIB_COMP}
568                 optimized ${OSL_LIB_EXEC}
569                 optimized ${OSL_LIB_QUERY}
570                 debug ${OSL_LIB_EXEC_DEBUG}
571                 debug ${OSL_LIB_COMP_DEBUG}
572                 debug ${OSL_LIB_QUERY_DEBUG}
573         )
574         find_path(OSL_INCLUDE_DIR OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
575         find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
576
577         if(OSL_INCLUDE_DIR AND OSL_LIBRARIES AND OSL_COMPILER)
578                 set(OSL_FOUND TRUE)
579         else()
580                 message(STATUS "OSL not found")
581                 set(WITH_CYCLES_OSL OFF)
582         endif()
583 endif()