CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. # Standalone or with Blender
  2. if(NOT WITH_BLENDER AND WITH_CYCLES_STANDALONE)
  3. set(CYCLES_INSTALL_PATH "")
  4. else()
  5. set(WITH_CYCLES_BLENDER ON)
  6. # WINDOWS_PYTHON_DEBUG needs to write into the user addons folder since it will
  7. # be started with --env-system-scripts pointing to the release folder, which will
  8. # lack the cycles addon, and we don't want to write into it.
  9. if(NOT WINDOWS_PYTHON_DEBUG)
  10. set(CYCLES_INSTALL_PATH "scripts/addons/cycles")
  11. else()
  12. set(CYCLES_INSTALL_PATH "$ENV{appdata}/blender foundation/blender/${BLENDER_VERSION}/scripts/addons/cycles")
  13. endif()
  14. endif()
  15. # External Libraries
  16. include(cmake/external_libs.cmake)
  17. include(cmake/macros.cmake)
  18. # Build Flags
  19. # todo: this code could be refactored a bit to avoid duplication
  20. # note: CXX_HAS_SSE is needed in case passing SSE flags fails altogether (gcc-arm)
  21. if(WITH_CYCLES_NATIVE_ONLY)
  22. set(CXX_HAS_SSE FALSE)
  23. set(CXX_HAS_AVX FALSE)
  24. set(CXX_HAS_AVX2 FALSE)
  25. add_definitions(
  26. -DWITH_KERNEL_NATIVE
  27. )
  28. if(NOT MSVC)
  29. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
  30. set(CYCLES_KERNEL_FLAGS "-march=native")
  31. endif()
  32. elseif(NOT WITH_CPU_SSE)
  33. set(CXX_HAS_SSE FALSE)
  34. set(CXX_HAS_AVX FALSE)
  35. set(CXX_HAS_AVX2 FALSE)
  36. elseif(WIN32 AND MSVC AND NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  37. set(CXX_HAS_SSE TRUE)
  38. set(CXX_HAS_AVX TRUE)
  39. set(CXX_HAS_AVX2 TRUE)
  40. # /arch:AVX for VC2012 and above
  41. if(NOT MSVC_VERSION LESS 1700)
  42. set(CYCLES_AVX_ARCH_FLAGS "/arch:AVX")
  43. set(CYCLES_AVX2_ARCH_FLAGS "/arch:AVX /arch:AVX2")
  44. elseif(NOT CMAKE_CL_64)
  45. set(CYCLES_AVX_ARCH_FLAGS "/arch:SSE2")
  46. set(CYCLES_AVX2_ARCH_FLAGS "/arch:SSE2")
  47. endif()
  48. # Unlike GCC/clang we still use fast math, because there is no fine
  49. # grained control and the speedup we get here is too big to ignore.
  50. set(CYCLES_KERNEL_FLAGS "/fp:fast -D_CRT_SECURE_NO_WARNINGS /GS-")
  51. # there is no /arch:SSE3, but intrinsics are available anyway
  52. if(CMAKE_CL_64)
  53. set(CYCLES_SSE2_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS}")
  54. set(CYCLES_SSE3_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS}")
  55. set(CYCLES_SSE41_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS}")
  56. set(CYCLES_AVX_KERNEL_FLAGS "${CYCLES_AVX_ARCH_FLAGS} ${CYCLES_KERNEL_FLAGS}")
  57. set(CYCLES_AVX2_KERNEL_FLAGS "${CYCLES_AVX2_ARCH_FLAGS} ${CYCLES_KERNEL_FLAGS}")
  58. else()
  59. set(CYCLES_SSE2_KERNEL_FLAGS "/arch:SSE2 ${CYCLES_KERNEL_FLAGS}")
  60. set(CYCLES_SSE3_KERNEL_FLAGS "/arch:SSE2 ${CYCLES_KERNEL_FLAGS}")
  61. set(CYCLES_SSE41_KERNEL_FLAGS "/arch:SSE2 ${CYCLES_KERNEL_FLAGS}")
  62. set(CYCLES_AVX_KERNEL_FLAGS "${CYCLES_AVX_ARCH_FLAGS} ${CYCLES_KERNEL_FLAGS}")
  63. set(CYCLES_AVX2_KERNEL_FLAGS "${CYCLES_AVX2_ARCH_FLAGS} ${CYCLES_KERNEL_FLAGS}")
  64. endif()
  65. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CYCLES_KERNEL_FLAGS}")
  66. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ox")
  67. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Ox")
  68. set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Ox")
  69. elseif(CMAKE_COMPILER_IS_GNUCC OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
  70. check_cxx_compiler_flag(-msse CXX_HAS_SSE)
  71. check_cxx_compiler_flag(-mavx CXX_HAS_AVX)
  72. check_cxx_compiler_flag(-mavx2 CXX_HAS_AVX2)
  73. # Assume no signal trapping for better code generation.
  74. set(CYCLES_KERNEL_FLAGS "-fno-trapping-math")
  75. # Avoid overhead of setting errno for NaNs.
  76. set(CYCLES_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -fno-math-errno")
  77. # Let compiler optimize 0.0 - x without worrying about signed zeros.
  78. set(CYCLES_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -fno-signed-zeros")
  79. if(CMAKE_COMPILER_IS_GNUCC)
  80. # Assume no signal trapping for better code generation.
  81. set(CYCLES_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -fno-signaling-nans")
  82. # Assume a fixed rounding mode for better constant folding.
  83. set(CYCLES_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -fno-rounding-math")
  84. endif()
  85. if(CXX_HAS_SSE)
  86. if(CMAKE_COMPILER_IS_GNUCC)
  87. set(CYCLES_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -mfpmath=sse")
  88. endif()
  89. set(CYCLES_SSE2_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -msse -msse2")
  90. set(CYCLES_SSE3_KERNEL_FLAGS "${CYCLES_SSE2_KERNEL_FLAGS} -msse3 -mssse3")
  91. set(CYCLES_SSE41_KERNEL_FLAGS "${CYCLES_SSE3_KERNEL_FLAGS} -msse4.1")
  92. if(CXX_HAS_AVX)
  93. set(CYCLES_AVX_KERNEL_FLAGS "${CYCLES_SSE41_KERNEL_FLAGS} -mavx")
  94. endif()
  95. if(CXX_HAS_AVX2)
  96. set(CYCLES_AVX2_KERNEL_FLAGS "${CYCLES_SSE41_KERNEL_FLAGS} -mavx -mavx2 -mfma -mlzcnt -mbmi -mbmi2 -mf16c")
  97. endif()
  98. endif()
  99. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CYCLES_KERNEL_FLAGS}")
  100. elseif(WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "Intel")
  101. check_cxx_compiler_flag(/QxSSE2 CXX_HAS_SSE)
  102. check_cxx_compiler_flag(/arch:AVX CXX_HAS_AVX)
  103. check_cxx_compiler_flag(/QxCORE-AVX2 CXX_HAS_AVX2)
  104. if(CXX_HAS_SSE)
  105. set(CYCLES_SSE2_KERNEL_FLAGS "/QxSSE2")
  106. set(CYCLES_SSE3_KERNEL_FLAGS "/QxSSSE3")
  107. set(CYCLES_SSE41_KERNEL_FLAGS "/QxSSE4.1")
  108. if(CXX_HAS_AVX)
  109. set(CYCLES_AVX_KERNEL_FLAGS "/arch:AVX")
  110. endif()
  111. if(CXX_HAS_AVX2)
  112. set(CYCLES_AVX2_KERNEL_FLAGS "/QxCORE-AVX2")
  113. endif()
  114. endif()
  115. elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
  116. if(APPLE)
  117. # ICC does not support SSE2 flag on MacOSX
  118. check_cxx_compiler_flag(-xssse3 CXX_HAS_SSE)
  119. else()
  120. check_cxx_compiler_flag(-xsse2 CXX_HAS_SSE)
  121. endif()
  122. check_cxx_compiler_flag(-xavx CXX_HAS_AVX)
  123. check_cxx_compiler_flag(-xcore-avx2 CXX_HAS_AVX2)
  124. if(CXX_HAS_SSE)
  125. if(APPLE)
  126. # ICC does not support SSE2 flag on MacOSX
  127. set(CYCLES_SSE2_KERNEL_FLAGS "-xssse3")
  128. else()
  129. set(CYCLES_SSE2_KERNEL_FLAGS "-xsse2")
  130. endif()
  131. set(CYCLES_SSE3_KERNEL_FLAGS "-xssse3")
  132. set(CYCLES_SSE41_KERNEL_FLAGS "-xsse4.1")
  133. if(CXX_HAS_AVX)
  134. set(CYCLES_AVX_KERNEL_FLAGS "-xavx")
  135. endif()
  136. if(CXX_HAS_AVX2)
  137. set(CYCLES_AVX2_KERNEL_FLAGS "-xcore-avx2")
  138. endif()
  139. endif()
  140. endif()
  141. if(CXX_HAS_SSE)
  142. add_definitions(
  143. -DWITH_KERNEL_SSE2
  144. -DWITH_KERNEL_SSE3
  145. -DWITH_KERNEL_SSE41
  146. )
  147. endif()
  148. if(CXX_HAS_AVX)
  149. add_definitions(-DWITH_KERNEL_AVX)
  150. endif()
  151. if(CXX_HAS_AVX2)
  152. add_definitions(-DWITH_KERNEL_AVX2)
  153. endif()
  154. if(WITH_CYCLES_OSL)
  155. if(WIN32 AND MSVC)
  156. set(RTTI_DISABLE_FLAGS "/GR- -DBOOST_NO_RTTI -DBOOST_NO_TYPEID")
  157. elseif(CMAKE_COMPILER_IS_GNUCC OR (CMAKE_C_COMPILER_ID MATCHES "Clang"))
  158. set(RTTI_DISABLE_FLAGS "-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID")
  159. endif()
  160. endif()
  161. # Definitions and Includes
  162. add_definitions(
  163. ${BOOST_DEFINITIONS}
  164. ${OPENIMAGEIO_DEFINITIONS}
  165. )
  166. add_definitions(
  167. -DCCL_NAMESPACE_BEGIN=namespace\ ccl\ {
  168. -DCCL_NAMESPACE_END=}
  169. )
  170. if(WITH_CYCLES_STANDALONE_GUI)
  171. add_definitions(-DWITH_CYCLES_STANDALONE_GUI)
  172. endif()
  173. if(WITH_CYCLES_PTEX)
  174. add_definitions(-DWITH_PTEX)
  175. endif()
  176. if(WITH_CYCLES_OSL)
  177. add_definitions(-DWITH_OSL)
  178. #osl 1.9.x
  179. add_definitions(-DOSL_STATIC_BUILD)
  180. #pre 1.9
  181. add_definitions(-DOSL_STATIC_LIBRARY)
  182. include_directories(
  183. SYSTEM
  184. ${OSL_INCLUDE_DIR}
  185. )
  186. endif()
  187. if(WITH_CYCLES_EMBREE)
  188. add_definitions(-DWITH_EMBREE)
  189. add_definitions(-DEMBREE_STATIC_LIB)
  190. include_directories(
  191. SYSTEM
  192. ${EMBREE_INCLUDE_DIRS}
  193. )
  194. endif()
  195. if(WITH_OPENSUBDIV)
  196. add_definitions(-DWITH_OPENSUBDIV)
  197. include_directories(
  198. SYSTEM
  199. ${OPENSUBDIV_INCLUDE_DIR}
  200. )
  201. endif()
  202. if(WITH_CYCLES_STANDALONE)
  203. set(WITH_CYCLES_DEVICE_OPENCL TRUE)
  204. set(WITH_CYCLES_DEVICE_CUDA TRUE)
  205. # Experimental and unfinished.
  206. set(WITH_CYCLES_NETWORK FALSE)
  207. endif()
  208. # TODO(sergey): Consider removing it, only causes confusion in interface.
  209. set(WITH_CYCLES_DEVICE_MULTI TRUE)
  210. # Logging capabilities using GLog library.
  211. if(WITH_CYCLES_LOGGING)
  212. add_definitions(-DWITH_CYCLES_LOGGING)
  213. add_definitions(${GLOG_DEFINES})
  214. add_definitions(-DCYCLES_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE})
  215. include_directories(
  216. SYSTEM
  217. ${GLOG_INCLUDE_DIRS}
  218. ${GFLAGS_INCLUDE_DIRS}
  219. )
  220. endif()
  221. # Debugging capabilities (debug passes etc).
  222. if(WITH_CYCLES_DEBUG)
  223. add_definitions(-DWITH_CYCLES_DEBUG)
  224. endif()
  225. if(NOT OPENIMAGEIO_PUGIXML_FOUND)
  226. add_definitions(-DWITH_SYSTEM_PUGIXML)
  227. endif()
  228. include_directories(
  229. SYSTEM
  230. ${BOOST_INCLUDE_DIR}
  231. ${OPENIMAGEIO_INCLUDE_DIRS}
  232. ${OPENIMAGEIO_INCLUDE_DIRS}/OpenImageIO
  233. ${OPENEXR_INCLUDE_DIR}
  234. ${OPENEXR_INCLUDE_DIRS}
  235. ${PUGIXML_INCLUDE_DIR}
  236. )
  237. if(CYCLES_STANDALONE_REPOSITORY)
  238. include_directories(../third_party/atomic)
  239. else()
  240. include_directories(../atomic)
  241. endif()
  242. # Warnings
  243. if(CMAKE_COMPILER_IS_GNUCXX)
  244. ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_cxxflag_float_conversion "-Werror=float-conversion")
  245. ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_cxxflag_double_promotion "-Werror=double-promotion")
  246. ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_no_error_unused_macros "-Wno-error=unused-macros")
  247. unset(_has_cxxflag_float_conversion)
  248. unset(_has_cxxflag_double_promotion)
  249. unset(_has_no_error_unused_macros)
  250. endif()
  251. if(WITH_CYCLES_CUDA_BINARIES AND (NOT WITH_CYCLES_CUBIN_COMPILER))
  252. if(MSVC)
  253. set(MAX_MSVC 1800)
  254. if(${CUDA_VERSION} EQUAL "8.0")
  255. set(MAX_MSVC 1900)
  256. elseif(${CUDA_VERSION} EQUAL "9.0")
  257. set(MAX_MSVC 1910)
  258. elseif(${CUDA_VERSION} EQUAL "9.1")
  259. set(MAX_MSVC 1911)
  260. elseif(${CUDA_VERSION} EQUAL "10.0")
  261. set(MAX_MSVC 1999)
  262. elseif(${CUDA_VERSION} EQUAL "10.1")
  263. set(MAX_MSVC 1999)
  264. endif()
  265. if(NOT MSVC_VERSION LESS ${MAX_MSVC} OR CMAKE_C_COMPILER_ID MATCHES "Clang")
  266. message(STATUS "nvcc not supported for this compiler version, using cycles_cubin_cc instead.")
  267. set(WITH_CYCLES_CUBIN_COMPILER ON)
  268. endif()
  269. unset(MAX_MSVC)
  270. elseif(APPLE)
  271. if(NOT (${XCODE_VERSION} VERSION_LESS 10.0))
  272. message(STATUS "nvcc not supported for this compiler version, using cycles_cubin_cc instead.")
  273. set(WITH_CYCLES_CUBIN_COMPILER ON)
  274. endif()
  275. endif()
  276. endif()
  277. # NVRTC gives wrong rendering result in CUDA 10.0, so we must use NVCC.
  278. if(WITH_CYCLES_CUDA_BINARIES AND WITH_CYCLES_CUBIN_COMPILER)
  279. if(NOT (${CUDA_VERSION} VERSION_LESS 10.0))
  280. message(STATUS "cycles_cubin_cc not supported for CUDA 10.0+, using nvcc instead.")
  281. set(WITH_CYCLES_CUBIN_COMPILER OFF)
  282. endif()
  283. endif()
  284. # Subdirectories
  285. if(WITH_CYCLES_BLENDER)
  286. add_definitions(-DWITH_BLENDER_GUARDEDALLOC)
  287. add_subdirectory(blender)
  288. endif()
  289. if(WITH_CYCLES_NETWORK)
  290. add_definitions(-DWITH_NETWORK)
  291. endif()
  292. if(WITH_OPENCOLORIO)
  293. add_definitions(-DWITH_OCIO)
  294. include_directories(
  295. SYSTEM
  296. ${OPENCOLORIO_INCLUDE_DIRS}
  297. )
  298. endif()
  299. if(WITH_CYCLES_STANDALONE OR WITH_CYCLES_NETWORK OR WITH_CYCLES_CUBIN_COMPILER)
  300. add_subdirectory(app)
  301. endif()
  302. add_subdirectory(bvh)
  303. add_subdirectory(device)
  304. add_subdirectory(doc)
  305. add_subdirectory(graph)
  306. add_subdirectory(kernel)
  307. add_subdirectory(render)
  308. add_subdirectory(subd)
  309. add_subdirectory(util)
  310. # TODO(sergey): Make this to work with standalone repository.
  311. if(WITH_GTESTS)
  312. add_subdirectory(test)
  313. endif()
  314. if(NOT WITH_BLENDER AND WITH_CYCLES_STANDALONE)
  315. delayed_do_install(${CMAKE_BINARY_DIR}/bin)
  316. endif()