Cycles: enable /arch:AVX in msvc 11 and later versions for avx kernel
[blender.git] / intern / cycles / CMakeLists.txt
1
2 # Standalone or with Blender
3 if(NOT WITH_BLENDER AND WITH_CYCLES_STANDALONE)
4         set(CYCLES_INSTALL_PATH "")
5 else()
6         set(WITH_CYCLES_BLENDER ON)
7         set(CYCLES_INSTALL_PATH "scripts/addons/cycles")
8 endif()
9
10 # External Libraries
11
12 include(cmake/external_libs.cmake)
13
14 # Build Flags
15 # todo: refactor this code to match scons
16
17 if(WIN32 AND MSVC)
18         # /arch:AVX for VC2012 and above
19         if(NOT MSVC_VERSION LESS 1700)
20                 set(CYCLES_AVX_ARCH_FLAGS "/arch:AVX")
21         elseif(NOT CMAKE_CL_64)
22                 set(CYCLES_AVX_ARCH_FLAGS "/arch:SSE2")
23         endif()
24
25         # there is no /arch:SSE3, but intrinsics are available anyway
26         if(CMAKE_CL_64)
27                 set(CYCLES_SSE2_KERNEL_FLAGS "/fp:fast -D_CRT_SECURE_NO_WARNINGS /Gs-")
28                 set(CYCLES_SSE3_KERNEL_FLAGS "/fp:fast -D_CRT_SECURE_NO_WARNINGS /Gs-")
29                 set(CYCLES_SSE41_KERNEL_FLAGS "/fp:fast -D_CRT_SECURE_NO_WARNINGS /Gs-")
30                 set(CYCLES_AVX_KERNEL_FLAGS "${CYCLES_AVX_ARCH_FLAGS} /fp:fast -D_CRT_SECURE_NO_WARNINGS /Gs-")
31         else()
32                 set(CYCLES_SSE2_KERNEL_FLAGS "/arch:SSE2 /fp:fast -D_CRT_SECURE_NO_WARNINGS /Gs-")
33                 set(CYCLES_SSE3_KERNEL_FLAGS "/arch:SSE2 /fp:fast -D_CRT_SECURE_NO_WARNINGS /Gs-")
34                 set(CYCLES_SSE41_KERNEL_FLAGS "/arch:SSE2 /fp:fast -D_CRT_SECURE_NO_WARNINGS /Gs-")
35                 set(CYCLES_AVX_KERNEL_FLAGS "${CYCLES_AVX_ARCH_FLAGS} /fp:fast -D_CRT_SECURE_NO_WARNINGS /Gs-") 
36         endif()
37
38         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast -D_CRT_SECURE_NO_WARNINGS /Gs-")
39         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ox")
40         set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Ox")
41         set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Ox")
42 elseif(CMAKE_COMPILER_IS_GNUCC)
43         set(CYCLES_SSE2_KERNEL_FLAGS "-ffast-math -msse -msse2 -mfpmath=sse")
44         set(CYCLES_SSE3_KERNEL_FLAGS "-ffast-math -msse -msse2 -msse3 -mssse3 -mfpmath=sse")
45         set(CYCLES_SSE41_KERNEL_FLAGS "-ffast-math -msse -msse2 -msse3 -mssse3 -msse4.1 -mfpmath=sse")
46         set(CYCLES_AVX_KERNEL_FLAGS "-ffast-math -msse -msse2 -msse3 -mssse3 -msse4.1 -mavx -mfpmath=sse")
47         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math")
48 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
49         set(CYCLES_SSE2_KERNEL_FLAGS "-ffast-math -msse -msse2")
50         set(CYCLES_SSE3_KERNEL_FLAGS "-ffast-math -msse -msse2 -msse3 -mssse3")
51         set(CYCLES_SSE41_KERNEL_FLAGS "-ffast-math -msse -msse2 -msse3 -mssse3 -msse4.1")
52         set(CYCLES_AVX_KERNEL_FLAGS "-ffast-math -msse -msse2 -msse3 -mssse3 -msse4.1 -mavx")
53         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math")
54 endif()
55
56 add_definitions(-DWITH_KERNEL_SSE2 -DWITH_KERNEL_SSE3 -DWITH_KERNEL_SSE41 -DWITH_KERNEL_AVX)
57
58 # for OSL
59 if(WIN32 AND MSVC)
60         set(RTTI_DISABLE_FLAGS "/GR- -DBOOST_NO_RTTI -DBOOST_NO_TYPEID")
61 elseif(CMAKE_COMPILER_IS_GNUCC OR (CMAKE_C_COMPILER_ID MATCHES "Clang"))
62         set(RTTI_DISABLE_FLAGS "-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID")
63 endif()
64
65 # Definitions and Includes
66
67 add_definitions(${BOOST_DEFINITIONS} ${OPENIMAGEIO_DEFINITIONS})
68
69 add_definitions(-DCCL_NAMESPACE_BEGIN=namespace\ ccl\ {)
70 add_definitions(-DCCL_NAMESPACE_END=})
71
72 if(WITH_CYCLES_NETWORK)
73         add_definitions(-DWITH_NETWORK)
74 endif()
75
76 if(WITH_CYCLES_STANDALONE_GUI)
77         add_definitions(-DWITH_CYCLES_STANDALONE_GUI)
78 endif()
79
80 if(WITH_CYCLES_PTEX)
81         add_definitions(-DWITH_PTEX)
82 endif()
83
84 if(WITH_CYCLES_OPENSUBDIV)
85         add_definitions(-DWITH_OPENSUBDIV)
86 endif()
87
88 if(WITH_CYCLES_OSL)
89         add_definitions(-DWITH_OSL)
90         add_definitions(-DOSL_STATIC_LIBRARY)
91         include_directories(${OSL_INCLUDES})
92 endif()
93
94 add_definitions(-DWITH_OPENCL)
95 add_definitions(-DWITH_CUDA)
96 add_definitions(-DWITH_MULTI)
97
98 include_directories(
99         SYSTEM
100         ${BOOST_INCLUDE_DIR}
101         ${OPENIMAGEIO_INCLUDE_DIRS}
102         ${OPENIMAGEIO_INCLUDE_DIRS}/OpenImageIO
103         ${OPENEXR_INCLUDE_DIR}
104         ${OPENEXR_INCLUDE_DIRS})
105
106 # Subdirectories
107
108 if(WITH_CYCLES_BLENDER)
109         add_subdirectory(blender)
110 endif()
111
112 if(WITH_CYCLES_STANDALONE OR WITH_CYCLES_NETWORK)
113         add_subdirectory(app)
114 endif()
115
116 add_subdirectory(bvh)
117 add_subdirectory(device)
118 add_subdirectory(doc)
119 add_subdirectory(kernel)
120 add_subdirectory(render)
121 add_subdirectory(subd)
122 add_subdirectory(util)
123
124 if(NOT WITH_BLENDER AND WITH_CYCLES_STANDALONE)
125         delayed_do_install(${CMAKE_BINARY_DIR}/bin)
126 endif()
127