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