macros.cmake 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580
  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) 2006, Blender Foundation
  18. # All rights reserved.
  19. #
  20. # The Original Code is: all of this file.
  21. #
  22. # Contributor(s): Jacques Beaurain.
  23. #
  24. # ***** END GPL LICENSE BLOCK *****
  25. macro(list_insert_after
  26. list_id item_check item_add
  27. )
  28. set(_index)
  29. list(FIND "${list_id}" "${item_check}" _index)
  30. if("${_index}" MATCHES "-1")
  31. message(FATAL_ERROR "'${list_id}' doesn't contain '${item_check}'")
  32. endif()
  33. math(EXPR _index "${_index} + 1")
  34. list(INSERT ${list_id} "${_index}" ${item_add})
  35. unset(_index)
  36. endmacro()
  37. macro(list_insert_before
  38. list_id item_check item_add
  39. )
  40. set(_index)
  41. list(FIND "${list_id}" "${item_check}" _index)
  42. if("${_index}" MATCHES "-1")
  43. message(FATAL_ERROR "'${list_id}' doesn't contain '${item_check}'")
  44. endif()
  45. list(INSERT ${list_id} "${_index}" ${item_add})
  46. unset(_index)
  47. endmacro()
  48. function(list_assert_duplicates
  49. list_id
  50. )
  51. # message(STATUS "list data: ${list_id}")
  52. list(LENGTH list_id _len_before)
  53. list(REMOVE_DUPLICATES list_id)
  54. list(LENGTH list_id _len_after)
  55. # message(STATUS "list size ${_len_before} -> ${_len_after}")
  56. if(NOT _len_before EQUAL _len_after)
  57. message(FATAL_ERROR "duplicate found in list which should not contain duplicates: ${list_id}")
  58. endif()
  59. unset(_len_before)
  60. unset(_len_after)
  61. endfunction()
  62. # foo_bar.spam --> foo_barMySuffix.spam
  63. macro(file_suffix
  64. file_name_new file_name file_suffix
  65. )
  66. get_filename_component(_file_name_PATH ${file_name} PATH)
  67. get_filename_component(_file_name_NAME_WE ${file_name} NAME_WE)
  68. get_filename_component(_file_name_EXT ${file_name} EXT)
  69. set(${file_name_new} "${_file_name_PATH}/${_file_name_NAME_WE}${file_suffix}${_file_name_EXT}")
  70. unset(_file_name_PATH)
  71. unset(_file_name_NAME_WE)
  72. unset(_file_name_EXT)
  73. endmacro()
  74. # useful for adding debug suffix to library lists:
  75. # /somepath/foo.lib --> /somepath/foo_d.lib
  76. macro(file_list_suffix
  77. fp_list_new fp_list fn_suffix
  78. )
  79. # incase of empty list
  80. set(_fp)
  81. set(_fp_suffixed)
  82. set(fp_list_new)
  83. foreach(_fp ${fp_list})
  84. file_suffix(_fp_suffixed "${_fp}" "${fn_suffix}")
  85. list(APPEND "${fp_list_new}" "${_fp_suffixed}")
  86. endforeach()
  87. unset(_fp)
  88. unset(_fp_suffixed)
  89. endmacro()
  90. if(UNIX AND NOT APPLE)
  91. macro(find_package_static)
  92. set(_cmake_find_library_suffixes_back ${CMAKE_FIND_LIBRARY_SUFFIXES})
  93. set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
  94. find_package(${ARGV})
  95. set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
  96. unset(_cmake_find_library_suffixes_back)
  97. endmacro()
  98. macro(find_library_static)
  99. set(_cmake_find_library_suffixes_back ${CMAKE_FIND_LIBRARY_SUFFIXES})
  100. set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
  101. find_library(${ARGV})
  102. set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
  103. unset(_cmake_find_library_suffixes_back)
  104. endmacro()
  105. endif()
  106. function(target_link_libraries_optimized
  107. TARGET
  108. LIBS
  109. )
  110. foreach(_LIB ${LIBS})
  111. target_link_libraries(${TARGET} optimized "${_LIB}")
  112. endforeach()
  113. endfunction()
  114. function(target_link_libraries_debug
  115. TARGET
  116. LIBS
  117. )
  118. foreach(_LIB ${LIBS})
  119. target_link_libraries(${TARGET} debug "${_LIB}")
  120. endforeach()
  121. endfunction()
  122. # Nicer makefiles with -I/1/foo/ instead of -I/1/2/3/../../foo/
  123. # use it instead of include_directories()
  124. function(blender_include_dirs
  125. includes
  126. )
  127. set(_ALL_INCS "")
  128. foreach(_INC ${ARGV})
  129. get_filename_component(_ABS_INC ${_INC} ABSOLUTE)
  130. list(APPEND _ALL_INCS ${_ABS_INC})
  131. # for checking for invalid includes, disable for regular use
  132. ##if(NOT EXISTS "${_ABS_INC}/")
  133. ## message(FATAL_ERROR "Include not found: ${_ABS_INC}/")
  134. ##endif()
  135. endforeach()
  136. include_directories(${_ALL_INCS})
  137. endfunction()
  138. function(blender_include_dirs_sys
  139. includes
  140. )
  141. set(_ALL_INCS "")
  142. foreach(_INC ${ARGV})
  143. get_filename_component(_ABS_INC ${_INC} ABSOLUTE)
  144. list(APPEND _ALL_INCS ${_ABS_INC})
  145. ##if(NOT EXISTS "${_ABS_INC}/")
  146. ## message(FATAL_ERROR "Include not found: ${_ABS_INC}/")
  147. ##endif()
  148. endforeach()
  149. include_directories(SYSTEM ${_ALL_INCS})
  150. endfunction()
  151. function(blender_source_group
  152. sources
  153. )
  154. # Group by location on disk
  155. source_group("Source Files" FILES CMakeLists.txt)
  156. foreach(_SRC ${sources})
  157. get_filename_component(_SRC_EXT ${_SRC} EXT)
  158. if((${_SRC_EXT} MATCHES ".h") OR
  159. (${_SRC_EXT} MATCHES ".hpp") OR
  160. (${_SRC_EXT} MATCHES ".hh"))
  161. set(GROUP_ID "Header Files")
  162. else()
  163. set(GROUP_ID "Source Files")
  164. endif()
  165. source_group("${GROUP_ID}" FILES ${_SRC})
  166. endforeach()
  167. endfunction()
  168. # Support per-target CMake flags
  169. # Read from: CMAKE_C_FLAGS_**** (made upper case) when set.
  170. #
  171. # 'name' should alway match the target name,
  172. # use this macro before add_library or add_executable.
  173. #
  174. # Optionally takes an arg passed to set(), eg PARENT_SCOPE.
  175. macro(add_cc_flags_custom_test
  176. name
  177. )
  178. string(TOUPPER ${name} _name_upper)
  179. if(DEFINED CMAKE_C_FLAGS_${_name_upper})
  180. message(STATUS "Using custom CFLAGS: CMAKE_C_FLAGS_${_name_upper} in \"${CMAKE_CURRENT_SOURCE_DIR}\"")
  181. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${_name_upper}}" ${ARGV1})
  182. endif()
  183. if(DEFINED CMAKE_CXX_FLAGS_${_name_upper})
  184. message(STATUS "Using custom CXXFLAGS: CMAKE_CXX_FLAGS_${_name_upper} in \"${CMAKE_CURRENT_SOURCE_DIR}\"")
  185. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_name_upper}}" ${ARGV1})
  186. endif()
  187. unset(_name_upper)
  188. endmacro()
  189. # only MSVC uses SOURCE_GROUP
  190. function(blender_add_lib__impl
  191. name
  192. sources
  193. includes
  194. includes_sys
  195. )
  196. # message(STATUS "Configuring library ${name}")
  197. # include_directories(${includes})
  198. # include_directories(SYSTEM ${includes_sys})
  199. blender_include_dirs("${includes}")
  200. blender_include_dirs_sys("${includes_sys}")
  201. add_library(${name} ${sources})
  202. # works fine without having the includes
  203. # listed is helpful for IDE's (QtCreator/MSVC)
  204. blender_source_group("${sources}")
  205. list_assert_duplicates("${sources}")
  206. list_assert_duplicates("${includes}")
  207. # Not for system includes because they can resolve to the same path
  208. # list_assert_duplicates("${includes_sys}")
  209. endfunction()
  210. function(blender_add_lib_nolist
  211. name
  212. sources
  213. includes
  214. includes_sys
  215. )
  216. add_cc_flags_custom_test(${name} PARENT_SCOPE)
  217. blender_add_lib__impl(${name} "${sources}" "${includes}" "${includes_sys}")
  218. endfunction()
  219. function(blender_add_lib
  220. name
  221. sources
  222. includes
  223. includes_sys
  224. )
  225. add_cc_flags_custom_test(${name} PARENT_SCOPE)
  226. blender_add_lib__impl(${name} "${sources}" "${includes}" "${includes_sys}")
  227. set_property(GLOBAL APPEND PROPERTY BLENDER_LINK_LIBS ${name})
  228. endfunction()
  229. function(SETUP_LIBDIRS)
  230. # NOTE: For all new libraries, use absolute library paths.
  231. # This should eventually be phased out.
  232. link_directories(${JPEG_LIBPATH} ${PNG_LIBPATH} ${ZLIB_LIBPATH} ${FREETYPE_LIBPATH})
  233. if(WITH_PYTHON) # AND NOT WITH_PYTHON_MODULE # WIN32 needs
  234. link_directories(${PYTHON_LIBPATH})
  235. endif()
  236. if(WITH_SDL AND NOT WITH_SDL_DYNLOAD)
  237. link_directories(${SDL_LIBPATH})
  238. endif()
  239. if(WITH_CODEC_FFMPEG)
  240. link_directories(${FFMPEG_LIBPATH})
  241. endif()
  242. if(WITH_IMAGE_OPENEXR)
  243. link_directories(${OPENEXR_LIBPATH})
  244. endif()
  245. if(WITH_IMAGE_TIFF)
  246. link_directories(${TIFF_LIBPATH})
  247. endif()
  248. if(WITH_BOOST)
  249. link_directories(${BOOST_LIBPATH})
  250. endif()
  251. if(WITH_OPENIMAGEIO)
  252. link_directories(${OPENIMAGEIO_LIBPATH})
  253. endif()
  254. if(WITH_OPENCOLORIO)
  255. link_directories(${OPENCOLORIO_LIBPATH})
  256. endif()
  257. if(WITH_OPENVDB)
  258. link_directories(${OPENVDB_LIBPATH})
  259. endif()
  260. if(WITH_OPENAL)
  261. link_directories(${OPENAL_LIBPATH})
  262. endif()
  263. if(WITH_JACK AND NOT WITH_JACK_DYNLOAD)
  264. link_directories(${JACK_LIBPATH})
  265. endif()
  266. if(WITH_CODEC_SNDFILE)
  267. link_directories(${SNDFILE_LIBPATH})
  268. endif()
  269. if(WITH_FFTW3)
  270. link_directories(${FFTW3_LIBPATH})
  271. endif()
  272. if(WITH_OPENCOLLADA)
  273. link_directories(${OPENCOLLADA_LIBPATH})
  274. ## Never set
  275. # link_directories(${PCRE_LIBPATH})
  276. # link_directories(${EXPAT_LIBPATH})
  277. endif()
  278. if(WITH_LLVM)
  279. link_directories(${LLVM_LIBPATH})
  280. endif()
  281. if(WITH_ALEMBIC)
  282. link_directories(${ALEMBIC_LIBPATH})
  283. link_directories(${HDF5_LIBPATH})
  284. endif()
  285. if(WIN32 AND NOT UNIX)
  286. link_directories(${PTHREADS_LIBPATH})
  287. endif()
  288. endfunction()
  289. function(setup_liblinks
  290. target
  291. )
  292. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}" PARENT_SCOPE)
  293. set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}" PARENT_SCOPE)
  294. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}" PARENT_SCOPE)
  295. set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}" PARENT_SCOPE)
  296. set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}" PARENT_SCOPE)
  297. set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}" PARENT_SCOPE)
  298. target_link_libraries(
  299. ${target}
  300. ${PNG_LIBRARIES}
  301. ${FREETYPE_LIBRARY}
  302. )
  303. # since we are using the local libs for python when compiling msvc projects, we need to add _d when compiling debug versions
  304. if(WITH_PYTHON) # AND NOT WITH_PYTHON_MODULE # WIN32 needs
  305. target_link_libraries(${target} ${PYTHON_LINKFLAGS})
  306. if(WIN32 AND NOT UNIX)
  307. file_list_suffix(PYTHON_LIBRARIES_DEBUG "${PYTHON_LIBRARIES}" "_d")
  308. target_link_libraries_debug(${target} "${PYTHON_LIBRARIES_DEBUG}")
  309. target_link_libraries_optimized(${target} "${PYTHON_LIBRARIES}")
  310. unset(PYTHON_LIBRARIES_DEBUG)
  311. else()
  312. target_link_libraries(${target} ${PYTHON_LIBRARIES})
  313. endif()
  314. endif()
  315. if(WITH_LZO AND WITH_SYSTEM_LZO)
  316. target_link_libraries(${target} ${LZO_LIBRARIES})
  317. endif()
  318. if(WITH_SYSTEM_GLEW)
  319. target_link_libraries(${target} ${BLENDER_GLEW_LIBRARIES})
  320. endif()
  321. if(WITH_BULLET AND WITH_SYSTEM_BULLET)
  322. target_link_libraries(${target} ${BULLET_LIBRARIES})
  323. endif()
  324. if(WITH_AUDASPACE AND WITH_SYSTEM_AUDASPACE)
  325. target_link_libraries(${target} ${AUDASPACE_C_LIBRARIES} ${AUDASPACE_PY_LIBRARIES})
  326. endif()
  327. if(WITH_OPENAL)
  328. target_link_libraries(${target} ${OPENAL_LIBRARY})
  329. endif()
  330. if(WITH_FFTW3)
  331. target_link_libraries(${target} ${FFTW3_LIBRARIES})
  332. endif()
  333. if(WITH_JACK AND NOT WITH_JACK_DYNLOAD)
  334. target_link_libraries(${target} ${JACK_LIBRARIES})
  335. endif()
  336. if(WITH_CODEC_SNDFILE)
  337. target_link_libraries(${target} ${SNDFILE_LIBRARIES})
  338. endif()
  339. if(WITH_SDL AND NOT WITH_SDL_DYNLOAD)
  340. target_link_libraries(${target} ${SDL_LIBRARY})
  341. endif()
  342. if(WITH_CODEC_QUICKTIME)
  343. target_link_libraries(${target} ${QUICKTIME_LIBRARIES})
  344. endif()
  345. if(WITH_IMAGE_TIFF)
  346. target_link_libraries(${target} ${TIFF_LIBRARY})
  347. endif()
  348. if(WITH_OPENIMAGEIO)
  349. target_link_libraries(${target} ${OPENIMAGEIO_LIBRARIES})
  350. endif()
  351. if(WITH_OPENCOLORIO)
  352. target_link_libraries(${target} ${OPENCOLORIO_LIBRARIES})
  353. endif()
  354. if(WITH_OPENSUBDIV OR WITH_CYCLES_OPENSUBDIV)
  355. target_link_libraries(${target} ${OPENSUBDIV_LIBRARIES})
  356. endif()
  357. if(WITH_OPENVDB)
  358. target_link_libraries(${target} ${OPENVDB_LIBRARIES} ${TBB_LIBRARIES})
  359. endif()
  360. if(WITH_CYCLES_OSL)
  361. target_link_libraries(${target} ${OSL_LIBRARIES})
  362. endif()
  363. if(WITH_BOOST)
  364. target_link_libraries(${target} ${BOOST_LIBRARIES})
  365. if(Boost_USE_STATIC_LIBS AND Boost_USE_ICU)
  366. target_link_libraries(${target} ${ICU_LIBRARIES})
  367. endif()
  368. endif()
  369. target_link_libraries(${target} ${JPEG_LIBRARIES})
  370. if(WITH_ALEMBIC)
  371. target_link_libraries(${target} ${ALEMBIC_LIBRARIES} ${HDF5_LIBRARIES})
  372. endif()
  373. if(WITH_IMAGE_OPENEXR)
  374. target_link_libraries(${target} ${OPENEXR_LIBRARIES})
  375. endif()
  376. if(WITH_IMAGE_OPENJPEG AND WITH_SYSTEM_OPENJPEG)
  377. target_link_libraries(${target} ${OPENJPEG_LIBRARIES})
  378. endif()
  379. if(WITH_CODEC_FFMPEG)
  380. target_link_libraries(${target} ${FFMPEG_LIBRARIES})
  381. endif()
  382. if(WITH_OPENCOLLADA)
  383. if(WIN32 AND NOT UNIX)
  384. file_list_suffix(OPENCOLLADA_LIBRARIES_DEBUG "${OPENCOLLADA_LIBRARIES}" "_d")
  385. target_link_libraries_debug(${target} "${OPENCOLLADA_LIBRARIES_DEBUG}")
  386. target_link_libraries_optimized(${target} "${OPENCOLLADA_LIBRARIES}")
  387. unset(OPENCOLLADA_LIBRARIES_DEBUG)
  388. file_list_suffix(PCRE_LIBRARIES_DEBUG "${PCRE_LIBRARIES}" "_d")
  389. target_link_libraries_debug(${target} "${PCRE_LIBRARIES_DEBUG}")
  390. target_link_libraries_optimized(${target} "${PCRE_LIBRARIES}")
  391. unset(PCRE_LIBRARIES_DEBUG)
  392. if(EXPAT_LIB)
  393. file_list_suffix(EXPAT_LIB_DEBUG "${EXPAT_LIB}" "_d")
  394. target_link_libraries_debug(${target} "${EXPAT_LIB_DEBUG}")
  395. target_link_libraries_optimized(${target} "${EXPAT_LIB}")
  396. unset(EXPAT_LIB_DEBUG)
  397. endif()
  398. else()
  399. target_link_libraries(
  400. ${target}
  401. ${OPENCOLLADA_LIBRARIES}
  402. ${PCRE_LIBRARIES}
  403. ${XML2_LIBRARIES}
  404. ${EXPAT_LIB}
  405. )
  406. endif()
  407. endif()
  408. if(WITH_MEM_JEMALLOC)
  409. target_link_libraries(${target} ${JEMALLOC_LIBRARIES})
  410. endif()
  411. if(WITH_MOD_CLOTH_ELTOPO)
  412. target_link_libraries(${target} ${LAPACK_LIBRARIES})
  413. endif()
  414. if(WITH_LLVM)
  415. target_link_libraries(${target} ${LLVM_LIBRARY})
  416. endif()
  417. if(WIN32 AND NOT UNIX)
  418. target_link_libraries(${target} ${PTHREADS_LIBRARIES})
  419. endif()
  420. if(UNIX AND NOT APPLE)
  421. if(WITH_OPENMP_STATIC)
  422. target_link_libraries(${target} ${OpenMP_LIBRARIES})
  423. endif()
  424. if(WITH_INPUT_NDOF)
  425. target_link_libraries(${target} ${NDOF_LIBRARIES})
  426. endif()
  427. endif()
  428. if(WITH_SYSTEM_GLOG)
  429. target_link_libraries(${target} ${GLOG_LIBRARIES})
  430. endif()
  431. if(WITH_SYSTEM_GFLAGS)
  432. target_link_libraries(${target} ${GFLAGS_LIBRARIES})
  433. endif()
  434. # We put CLEW and CUEW here because OPENSUBDIV_LIBRARIES dpeends on them..
  435. if(WITH_CYCLES OR WITH_COMPOSITOR OR WITH_OPENSUBDIV)
  436. target_link_libraries(${target} "extern_clew")
  437. if(WITH_CUDA_DYNLOAD)
  438. target_link_libraries(${target} "extern_cuew")
  439. else()
  440. target_link_libraries(${target} ${CUDA_CUDA_LIBRARY})
  441. endif()
  442. endif()
  443. target_link_libraries(
  444. ${target}
  445. ${ZLIB_LIBRARIES}
  446. )
  447. #system libraries with no dependencies such as platform link libs or opengl should go last
  448. target_link_libraries(${target}
  449. ${BLENDER_GL_LIBRARIES})
  450. #target_link_libraries(${target} ${PLATFORM_LINKLIBS} ${CMAKE_DL_LIBS})
  451. target_link_libraries(${target} ${PLATFORM_LINKLIBS})
  452. endfunction()
  453. function(SETUP_BLENDER_SORTED_LIBS)
  454. get_property(BLENDER_LINK_LIBS GLOBAL PROPERTY BLENDER_LINK_LIBS)
  455. list(APPEND BLENDER_LINK_LIBS
  456. bf_windowmanager
  457. bf_render
  458. )
  459. if(WITH_MOD_FLUID)
  460. list(APPEND BLENDER_LINK_LIBS bf_intern_elbeem)
  461. endif()
  462. if(WITH_CYCLES)
  463. list(APPEND BLENDER_LINK_LIBS
  464. cycles_render
  465. cycles_graph
  466. cycles_bvh
  467. cycles_device
  468. cycles_kernel
  469. cycles_util
  470. cycles_subd)
  471. if(WITH_CYCLES_OSL)
  472. list(APPEND BLENDER_LINK_LIBS cycles_kernel_osl)
  473. endif()
  474. endif()
  475. # Sort libraries
  476. set(BLENDER_SORTED_LIBS
  477. bf_windowmanager
  478. bf_editor_space_api
  479. bf_editor_space_action
  480. bf_editor_space_buttons
  481. bf_editor_space_console
  482. bf_editor_space_file
  483. bf_editor_space_graph
  484. bf_editor_space_image
  485. bf_editor_space_info
  486. bf_editor_space_logic
  487. bf_editor_space_nla
  488. bf_editor_space_node
  489. bf_editor_space_outliner
  490. bf_editor_space_script
  491. bf_editor_space_sequencer
  492. bf_editor_space_text
  493. bf_editor_space_time
  494. bf_editor_space_userpref
  495. bf_editor_space_view3d
  496. bf_editor_space_clip
  497. bf_editor_transform
  498. bf_editor_util
  499. bf_editor_uvedit
  500. bf_editor_curve
  501. bf_editor_gpencil
  502. bf_editor_interface
  503. bf_editor_mesh
  504. bf_editor_metaball
  505. bf_editor_object
  506. bf_editor_armature
  507. bf_editor_physics
  508. bf_editor_render
  509. bf_editor_screen
  510. bf_editor_sculpt_paint
  511. bf_editor_sound
  512. bf_editor_animation
  513. bf_editor_datafiles
  514. bf_editor_mask
  515. bf_editor_io
  516. bf_render
  517. bf_python
  518. bf_python_ext
  519. bf_python_mathutils
  520. bf_python_bmesh
  521. bf_freestyle
  522. bf_ikplugin
  523. bf_modifiers
  524. bf_alembic
  525. bf_bmesh
  526. bf_gpu
  527. bf_blenloader
  528. bf_blenkernel
  529. bf_physics
  530. bf_nodes
  531. bf_rna
  532. bf_imbuf
  533. bf_blenlib
  534. bf_depsgraph
  535. bf_intern_ghost
  536. bf_intern_string
  537. bf_avi
  538. bf_imbuf_cineon
  539. bf_imbuf_openexr
  540. bf_imbuf_openimageio
  541. bf_imbuf_dds
  542. bf_collada
  543. bf_intern_elbeem
  544. bf_intern_memutil
  545. bf_intern_guardedalloc
  546. bf_intern_ctr
  547. bf_intern_utfconv
  548. ge_blen_routines
  549. ge_converter
  550. ge_phys_dummy
  551. ge_phys_bullet
  552. bf_intern_smoke
  553. extern_lzma
  554. extern_curve_fit_nd
  555. ge_logic_ketsji
  556. extern_recastnavigation
  557. ge_logic
  558. ge_rasterizer
  559. ge_oglrasterizer
  560. ge_logic_expressions
  561. ge_scenegraph
  562. ge_logic_network
  563. ge_logic_ngnetwork
  564. ge_logic_loopbacknetwork
  565. bf_intern_moto
  566. extern_openjpeg
  567. ge_videotex
  568. bf_dna
  569. bf_blenfont
  570. bf_blentranslation
  571. bf_intern_audaspace
  572. bf_intern_mikktspace
  573. bf_intern_dualcon
  574. bf_intern_cycles
  575. cycles_render
  576. cycles_graph
  577. cycles_bvh
  578. cycles_device
  579. cycles_kernel
  580. cycles_util
  581. cycles_subd
  582. bf_intern_opencolorio
  583. bf_intern_eigen
  584. extern_rangetree
  585. extern_wcwidth
  586. bf_intern_libmv
  587. extern_sdlew
  588. bf_intern_glew_mx
  589. )
  590. if(NOT WITH_SYSTEM_GLOG)
  591. list(APPEND BLENDER_SORTED_LIBS extern_glog)
  592. endif()
  593. if(NOT WITH_SYSTEM_GFLAGS)
  594. list(APPEND BLENDER_SORTED_LIBS extern_gflags)
  595. endif()
  596. if(WITH_COMPOSITOR)
  597. # added for opencl compositor
  598. list_insert_before(BLENDER_SORTED_LIBS "bf_blenkernel" "bf_compositor")
  599. list_insert_after(BLENDER_SORTED_LIBS "bf_compositor" "bf_intern_opencl")
  600. endif()
  601. if(WITH_LIBMV)
  602. list(APPEND BLENDER_SORTED_LIBS extern_ceres)
  603. endif()
  604. if(WITH_MOD_CLOTH_ELTOPO)
  605. list(APPEND BLENDER_SORTED_LIBS extern_eltopo)
  606. endif()
  607. if(NOT WITH_SYSTEM_LZO)
  608. list(APPEND BLENDER_SORTED_LIBS extern_minilzo)
  609. endif()
  610. if(NOT WITH_SYSTEM_GLEW)
  611. list(APPEND BLENDER_SORTED_LIBS ${BLENDER_GLEW_LIBRARIES})
  612. endif()
  613. if(WITH_BINRELOC)
  614. list(APPEND BLENDER_SORTED_LIBS extern_binreloc)
  615. endif()
  616. if(WITH_CXX_GUARDEDALLOC)
  617. list(APPEND BLENDER_SORTED_LIBS bf_intern_guardedalloc_cpp)
  618. endif()
  619. if(WITH_IK_SOLVER)
  620. list_insert_after(BLENDER_SORTED_LIBS "bf_intern_elbeem" "bf_intern_iksolver")
  621. endif()
  622. if(WITH_IK_ITASC)
  623. list(APPEND BLENDER_SORTED_LIBS bf_intern_itasc)
  624. endif()
  625. if(WITH_CODEC_QUICKTIME)
  626. list(APPEND BLENDER_SORTED_LIBS bf_quicktime)
  627. endif()
  628. if(WITH_MOD_BOOLEAN)
  629. list(APPEND BLENDER_SORTED_LIBS extern_carve)
  630. endif()
  631. if(WITH_GHOST_XDND)
  632. list(APPEND BLENDER_SORTED_LIBS extern_xdnd)
  633. endif()
  634. if(WITH_CYCLES_OSL)
  635. list_insert_after(BLENDER_SORTED_LIBS "cycles_kernel" "cycles_kernel_osl")
  636. endif()
  637. if(WITH_INTERNATIONAL)
  638. list(APPEND BLENDER_SORTED_LIBS bf_intern_locale)
  639. endif()
  640. if(WITH_BULLET)
  641. list_insert_after(BLENDER_SORTED_LIBS "bf_blenkernel" "bf_intern_rigidbody")
  642. endif()
  643. if(WITH_BULLET AND NOT WITH_SYSTEM_BULLET)
  644. list_insert_after(BLENDER_SORTED_LIBS "ge_logic_ngnetwork" "extern_bullet")
  645. endif()
  646. if(WITH_GAMEENGINE_DECKLINK)
  647. list(APPEND BLENDER_SORTED_LIBS bf_intern_decklink)
  648. endif()
  649. if(WIN32)
  650. list(APPEND BLENDER_SORTED_LIBS bf_intern_gpudirect)
  651. endif()
  652. if(WITH_OPENSUBDIV OR WITH_CYCLES_OPENSUBDIV)
  653. list(APPEND BLENDER_SORTED_LIBS bf_intern_opensubdiv)
  654. endif()
  655. if(WITH_OPENVDB)
  656. list(APPEND BLENDER_SORTED_LIBS bf_intern_openvdb)
  657. endif()
  658. foreach(SORTLIB ${BLENDER_SORTED_LIBS})
  659. set(REMLIB ${SORTLIB})
  660. foreach(SEARCHLIB ${BLENDER_LINK_LIBS})
  661. if(${SEARCHLIB} STREQUAL ${SORTLIB})
  662. set(REMLIB "")
  663. endif()
  664. endforeach()
  665. if(REMLIB)
  666. # message(STATUS "Removing library ${REMLIB} from blender linking because: not configured")
  667. list(APPEND REM_MSG ${REMLIB})
  668. list(REMOVE_ITEM BLENDER_SORTED_LIBS ${REMLIB})
  669. endif()
  670. endforeach()
  671. if(REM_MSG)
  672. list(SORT REM_MSG)
  673. message(STATUS "Blender Skipping: (${REM_MSG})")
  674. endif()
  675. set(BLENDER_SORTED_LIBS ${BLENDER_SORTED_LIBS} PARENT_SCOPE)
  676. # for top-level tests
  677. set_property(GLOBAL PROPERTY BLENDER_SORTED_LIBS_PROP ${BLENDER_SORTED_LIBS})
  678. endfunction()
  679. macro(TEST_SSE_SUPPORT
  680. _sse_flags
  681. _sse2_flags)
  682. include(CheckCSourceRuns)
  683. # message(STATUS "Detecting SSE support")
  684. if(CMAKE_COMPILER_IS_GNUCC OR (CMAKE_C_COMPILER_ID MATCHES "Clang"))
  685. set(${_sse_flags} "-msse")
  686. set(${_sse2_flags} "-msse2")
  687. elseif(MSVC)
  688. # x86_64 has this auto enabled
  689. if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
  690. set(${_sse_flags} "")
  691. set(${_sse2_flags} "")
  692. else()
  693. set(${_sse_flags} "/arch:SSE")
  694. set(${_sse2_flags} "/arch:SSE2")
  695. endif()
  696. elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
  697. set(${_sse_flags} "") # icc defaults to -msse
  698. set(${_sse2_flags} "-msse2")
  699. else()
  700. message(WARNING "SSE flags for this compiler: '${CMAKE_C_COMPILER_ID}' not known")
  701. set(${_sse_flags})
  702. set(${_sse2_flags})
  703. endif()
  704. set(CMAKE_REQUIRED_FLAGS "${${_sse_flags}} ${${_sse2_flags}}")
  705. if(NOT DEFINED SUPPORT_SSE_BUILD)
  706. # result cached
  707. check_c_source_runs("
  708. #include <xmmintrin.h>
  709. int main(void) { __m128 v = _mm_setzero_ps(); return 0; }"
  710. SUPPORT_SSE_BUILD)
  711. if(SUPPORT_SSE_BUILD)
  712. message(STATUS "SSE Support: detected.")
  713. else()
  714. message(STATUS "SSE Support: missing.")
  715. endif()
  716. endif()
  717. if(NOT DEFINED SUPPORT_SSE2_BUILD)
  718. # result cached
  719. check_c_source_runs("
  720. #include <emmintrin.h>
  721. int main(void) { __m128d v = _mm_setzero_pd(); return 0; }"
  722. SUPPORT_SSE2_BUILD)
  723. if(SUPPORT_SSE2_BUILD)
  724. message(STATUS "SSE2 Support: detected.")
  725. else()
  726. message(STATUS "SSE2 Support: missing.")
  727. endif()
  728. endif()
  729. unset(CMAKE_REQUIRED_FLAGS)
  730. endmacro()
  731. # Only print message if running CMake first time
  732. macro(message_first_run)
  733. if(FIRST_RUN)
  734. message(${ARGV})
  735. endif()
  736. endmacro()
  737. macro(TEST_UNORDERED_MAP_SUPPORT)
  738. # - Detect unordered_map availability
  739. # Test if a valid implementation of unordered_map exists
  740. # and define the include path
  741. # This module defines
  742. # HAVE_UNORDERED_MAP, whether unordered_map implementation was found
  743. #
  744. # HAVE_STD_UNORDERED_MAP_HEADER, <unordered_map.h> was found
  745. # HAVE_UNORDERED_MAP_IN_STD_NAMESPACE, unordered_map is in namespace std
  746. # HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE, unordered_map is in namespace std::tr1
  747. #
  748. # UNORDERED_MAP_INCLUDE_PREFIX, include path prefix for unordered_map, if found
  749. # UNORDERED_MAP_NAMESPACE, namespace for unordered_map, if found
  750. include(CheckIncludeFileCXX)
  751. # Workaround for newer GCC (6.x+) where C++11 was enabled by default, which lead us
  752. # to a situation when there is <unordered_map> include but which can't be used uless
  753. # C++11 is enabled.
  754. if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "6.0") AND (NOT WITH_CXX11))
  755. set(HAVE_STD_UNORDERED_MAP_HEADER False)
  756. else()
  757. CHECK_INCLUDE_FILE_CXX("unordered_map" HAVE_STD_UNORDERED_MAP_HEADER)
  758. endif()
  759. if(HAVE_STD_UNORDERED_MAP_HEADER)
  760. # Even so we've found unordered_map header file it doesn't
  761. # mean unordered_map and unordered_set will be declared in
  762. # std namespace.
  763. #
  764. # Namely, MSVC 2008 have unordered_map header which declares
  765. # unordered_map class in std::tr1 namespace. In order to support
  766. # this, we do extra check to see which exactly namespace is
  767. # to be used.
  768. include(CheckCXXSourceCompiles)
  769. CHECK_CXX_SOURCE_COMPILES("#include <unordered_map>
  770. int main() {
  771. std::unordered_map<int, int> map;
  772. return 0;
  773. }"
  774. HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
  775. if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
  776. message_first_run(STATUS "Found unordered_map/set in std namespace.")
  777. set(HAVE_UNORDERED_MAP "TRUE")
  778. set(UNORDERED_MAP_INCLUDE_PREFIX "")
  779. set(UNORDERED_MAP_NAMESPACE "std")
  780. else()
  781. CHECK_CXX_SOURCE_COMPILES("#include <unordered_map>
  782. int main() {
  783. std::tr1::unordered_map<int, int> map;
  784. return 0;
  785. }"
  786. HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
  787. if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
  788. message_first_run(STATUS "Found unordered_map/set in std::tr1 namespace.")
  789. set(HAVE_UNORDERED_MAP "TRUE")
  790. set(UNORDERED_MAP_INCLUDE_PREFIX "")
  791. set(UNORDERED_MAP_NAMESPACE "std::tr1")
  792. else()
  793. message_first_run(STATUS "Found <unordered_map> but cannot find either std::unordered_map "
  794. "or std::tr1::unordered_map.")
  795. endif()
  796. endif()
  797. else()
  798. CHECK_INCLUDE_FILE_CXX("tr1/unordered_map" HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
  799. if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
  800. message_first_run(STATUS "Found unordered_map/set in std::tr1 namespace.")
  801. set(HAVE_UNORDERED_MAP "TRUE")
  802. set(UNORDERED_MAP_INCLUDE_PREFIX "tr1")
  803. set(UNORDERED_MAP_NAMESPACE "std::tr1")
  804. else()
  805. message_first_run(STATUS "Unable to find <unordered_map> or <tr1/unordered_map>. ")
  806. endif()
  807. endif()
  808. endmacro()
  809. macro(TEST_SHARED_PTR_SUPPORT)
  810. # This check are coming from Ceres library.
  811. #
  812. # Find shared pointer header and namespace.
  813. #
  814. # This module defines the following variables:
  815. #
  816. # SHARED_PTR_FOUND: TRUE if shared_ptr found.
  817. # SHARED_PTR_TR1_MEMORY_HEADER: True if <tr1/memory> header is to be used
  818. # for the shared_ptr object, otherwise use <memory>.
  819. # SHARED_PTR_TR1_NAMESPACE: TRUE if shared_ptr is defined in std::tr1 namespace,
  820. # otherwise it's assumed to be defined in std namespace.
  821. include(CheckIncludeFileCXX)
  822. include(CheckCXXSourceCompiles)
  823. set(SHARED_PTR_FOUND FALSE)
  824. # Workaround for newer GCC (6.x+) where C++11 was enabled by default, which lead us
  825. # to a situation when there is <unordered_map> include but which can't be used uless
  826. # C++11 is enabled.
  827. if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "6.0") AND (NOT WITH_CXX11))
  828. set(HAVE_STD_MEMORY_HEADER False)
  829. else()
  830. CHECK_INCLUDE_FILE_CXX(memory HAVE_STD_MEMORY_HEADER)
  831. endif()
  832. if(HAVE_STD_MEMORY_HEADER)
  833. # Finding the memory header doesn't mean that shared_ptr is in std
  834. # namespace.
  835. #
  836. # In particular, MSVC 2008 has shared_ptr declared in std::tr1. In
  837. # order to support this, we do an extra check to see which namespace
  838. # should be used.
  839. CHECK_CXX_SOURCE_COMPILES("#include <memory>
  840. int main() {
  841. std::shared_ptr<int> int_ptr;
  842. return 0;
  843. }"
  844. HAVE_SHARED_PTR_IN_STD_NAMESPACE)
  845. if(HAVE_SHARED_PTR_IN_STD_NAMESPACE)
  846. message_first_run("-- Found shared_ptr in std namespace using <memory> header.")
  847. set(SHARED_PTR_FOUND TRUE)
  848. else()
  849. CHECK_CXX_SOURCE_COMPILES("#include <memory>
  850. int main() {
  851. std::tr1::shared_ptr<int> int_ptr;
  852. return 0;
  853. }"
  854. HAVE_SHARED_PTR_IN_TR1_NAMESPACE)
  855. if(HAVE_SHARED_PTR_IN_TR1_NAMESPACE)
  856. message_first_run("-- Found shared_ptr in std::tr1 namespace using <memory> header.")
  857. set(SHARED_PTR_TR1_NAMESPACE TRUE)
  858. set(SHARED_PTR_FOUND TRUE)
  859. endif()
  860. endif()
  861. endif()
  862. if(NOT SHARED_PTR_FOUND)
  863. # Further, gcc defines shared_ptr in std::tr1 namespace and
  864. # <tr1/memory> is to be included for this. And what makes things
  865. # even more tricky is that gcc does have <memory> header, so
  866. # all the checks above wouldn't find shared_ptr.
  867. CHECK_INCLUDE_FILE_CXX("tr1/memory" HAVE_TR1_MEMORY_HEADER)
  868. if(HAVE_TR1_MEMORY_HEADER)
  869. CHECK_CXX_SOURCE_COMPILES("#include <tr1/memory>
  870. int main() {
  871. std::tr1::shared_ptr<int> int_ptr;
  872. return 0;
  873. }"
  874. HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER)
  875. if(HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER)
  876. message_first_run("-- Found shared_ptr in std::tr1 namespace using <tr1/memory> header.")
  877. set(SHARED_PTR_TR1_MEMORY_HEADER TRUE)
  878. set(SHARED_PTR_TR1_NAMESPACE TRUE)
  879. set(SHARED_PTR_FOUND TRUE)
  880. endif()
  881. endif()
  882. endif()
  883. endmacro()
  884. # when we have warnings as errors applied globally this
  885. # needs to be removed for some external libs which we dont maintain.
  886. # utility macro
  887. macro(remove_cc_flag
  888. _flag)
  889. foreach(flag ${ARGV})
  890. string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  891. string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
  892. string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
  893. string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
  894. string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
  895. string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  896. string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
  897. string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
  898. string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
  899. string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
  900. endforeach()
  901. unset(flag)
  902. endmacro()
  903. macro(add_cc_flag
  904. flag)
  905. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
  906. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
  907. endmacro()
  908. macro(remove_strict_flags)
  909. if(CMAKE_COMPILER_IS_GNUCC)
  910. remove_cc_flag(
  911. "-Wstrict-prototypes"
  912. "-Wmissing-prototypes"
  913. "-Wmissing-declarations"
  914. "-Wmissing-format-attribute"
  915. "-Wunused-local-typedefs"
  916. "-Wunused-macros"
  917. "-Wunused-parameter"
  918. "-Wwrite-strings"
  919. "-Wredundant-decls"
  920. "-Wundef"
  921. "-Wshadow"
  922. "-Wdouble-promotion"
  923. "-Wold-style-definition"
  924. "-Werror=[^ ]+"
  925. "-Werror"
  926. )
  927. # negate flags implied by '-Wall'
  928. add_cc_flag("${CC_REMOVE_STRICT_FLAGS}")
  929. endif()
  930. if(CMAKE_C_COMPILER_ID MATCHES "Clang")
  931. remove_cc_flag(
  932. "-Wunused-parameter"
  933. "-Wunused-variable"
  934. "-Werror=[^ ]+"
  935. "-Werror"
  936. )
  937. # negate flags implied by '-Wall'
  938. add_cc_flag("${CC_REMOVE_STRICT_FLAGS}")
  939. endif()
  940. if(MSVC)
  941. # TODO
  942. endif()
  943. endmacro()
  944. macro(remove_extra_strict_flags)
  945. if(CMAKE_COMPILER_IS_GNUCC)
  946. remove_cc_flag(
  947. "-Wunused-parameter"
  948. )
  949. endif()
  950. if(CMAKE_C_COMPILER_ID MATCHES "Clang")
  951. remove_cc_flag(
  952. "-Wunused-parameter"
  953. )
  954. endif()
  955. if(MSVC)
  956. # TODO
  957. endif()
  958. endmacro()
  959. # note, we can only append flags on a single file so we need to negate the options.
  960. # at the moment we cant shut up ffmpeg deprecations, so use this, but will
  961. # probably add more removals here.
  962. macro(remove_strict_flags_file
  963. filenames)
  964. foreach(_SOURCE ${ARGV})
  965. if(CMAKE_COMPILER_IS_GNUCC OR
  966. (CMAKE_C_COMPILER_ID MATCHES "Clang"))
  967. set_source_files_properties(${_SOURCE}
  968. PROPERTIES
  969. COMPILE_FLAGS "${CC_REMOVE_STRICT_FLAGS}"
  970. )
  971. endif()
  972. if(MSVC)
  973. # TODO
  974. endif()
  975. endforeach()
  976. unset(_SOURCE)
  977. endmacro()
  978. # External libs may need 'signed char' to be default.
  979. macro(remove_cc_flag_unsigned_char)
  980. if(CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang|Intel)$")
  981. remove_cc_flag("-funsigned-char")
  982. elseif(MSVC)
  983. remove_cc_flag("/J")
  984. else()
  985. message(WARNING
  986. "Compiler '${CMAKE_C_COMPILER_ID}' failed to disable 'unsigned char' flag."
  987. "Build files need updating."
  988. )
  989. endif()
  990. endmacro()
  991. function(ADD_CHECK_C_COMPILER_FLAG
  992. _CFLAGS
  993. _CACHE_VAR
  994. _FLAG
  995. )
  996. include(CheckCCompilerFlag)
  997. CHECK_C_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
  998. if(${_CACHE_VAR})
  999. # message(STATUS "Using CFLAG: ${_FLAG}")
  1000. set(${_CFLAGS} "${${_CFLAGS}} ${_FLAG}" PARENT_SCOPE)
  1001. else()
  1002. message(STATUS "Unsupported CFLAG: ${_FLAG}")
  1003. endif()
  1004. endfunction()
  1005. function(ADD_CHECK_CXX_COMPILER_FLAG
  1006. _CXXFLAGS
  1007. _CACHE_VAR
  1008. _FLAG
  1009. )
  1010. include(CheckCXXCompilerFlag)
  1011. CHECK_CXX_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
  1012. if(${_CACHE_VAR})
  1013. # message(STATUS "Using CXXFLAG: ${_FLAG}")
  1014. set(${_CXXFLAGS} "${${_CXXFLAGS}} ${_FLAG}" PARENT_SCOPE)
  1015. else()
  1016. message(STATUS "Unsupported CXXFLAG: ${_FLAG}")
  1017. endif()
  1018. endfunction()
  1019. function(get_blender_version)
  1020. # extracts header vars and defines them in the parent scope:
  1021. #
  1022. # - BLENDER_VERSION (major.minor)
  1023. # - BLENDER_VERSION_MAJOR
  1024. # - BLENDER_VERSION_MINOR
  1025. # - BLENDER_SUBVERSION (used for internal versioning mainly)
  1026. # - BLENDER_VERSION_CHAR (a, b, c, ...or empty string)
  1027. # - BLENDER_VERSION_CYCLE (alpha, beta, rc, release)
  1028. # So cmake depends on BKE_blender.h, beware of inf-loops!
  1029. CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender_version.h
  1030. ${CMAKE_BINARY_DIR}/source/blender/blenkernel/BKE_blender_version.h.done)
  1031. file(STRINGS ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender_version.h _contents REGEX "^#define[ \t]+BLENDER_.*$")
  1032. string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION[ \t]+([0-9]+).*" "\\1" _out_version "${_contents}")
  1033. string(REGEX REPLACE ".*#define[ \t]+BLENDER_SUBVERSION[ \t]+([0-9]+).*" "\\1" _out_subversion "${_contents}")
  1034. string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_CHAR[ \t]+([a-z]+).*" "\\1" _out_version_char "${_contents}")
  1035. string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_CYCLE[ \t]+([a-z]+).*" "\\1" _out_version_cycle "${_contents}")
  1036. if(NOT ${_out_version} MATCHES "[0-9]+")
  1037. message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION")
  1038. endif()
  1039. if(NOT ${_out_subversion} MATCHES "[0-9]+")
  1040. message(FATAL_ERROR "Version parsing failed for BLENDER_SUBVERSION")
  1041. endif()
  1042. # clumsy regex, only single char are ok but it could be unset
  1043. string(LENGTH "${_out_version_char}" _out_version_char_len)
  1044. if(NOT _out_version_char_len EQUAL 1)
  1045. set(_out_version_char "")
  1046. elseif(NOT ${_out_version_char} MATCHES "[a-z]+")
  1047. message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_CHAR")
  1048. endif()
  1049. if(NOT ${_out_version_cycle} MATCHES "[a-z]+")
  1050. message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_CYCLE")
  1051. endif()
  1052. math(EXPR _out_version_major "${_out_version} / 100")
  1053. math(EXPR _out_version_minor "${_out_version} % 100")
  1054. # for packaging, alpha to numbers
  1055. string(COMPARE EQUAL "${_out_version_char}" "" _out_version_char_empty)
  1056. if(${_out_version_char_empty})
  1057. set(_out_version_char_index "0")
  1058. else()
  1059. set(_char_ls a b c d e f g h i j k l m n o p q r s t u v w x y z)
  1060. list(FIND _char_ls ${_out_version_char} _out_version_char_index)
  1061. math(EXPR _out_version_char_index "${_out_version_char_index} + 1")
  1062. endif()
  1063. # output vars
  1064. set(BLENDER_VERSION "${_out_version_major}.${_out_version_minor}" PARENT_SCOPE)
  1065. set(BLENDER_VERSION_MAJOR "${_out_version_major}" PARENT_SCOPE)
  1066. set(BLENDER_VERSION_MINOR "${_out_version_minor}" PARENT_SCOPE)
  1067. set(BLENDER_SUBVERSION "${_out_subversion}" PARENT_SCOPE)
  1068. set(BLENDER_VERSION_CHAR "${_out_version_char}" PARENT_SCOPE)
  1069. set(BLENDER_VERSION_CHAR_INDEX "${_out_version_char_index}" PARENT_SCOPE)
  1070. set(BLENDER_VERSION_CYCLE "${_out_version_cycle}" PARENT_SCOPE)
  1071. endfunction()
  1072. # hacks to override initial project settings
  1073. # these macros must be called directly before/after project(Blender)
  1074. macro(blender_project_hack_pre)
  1075. # ------------------
  1076. # GCC -O3 HACK START
  1077. # needed because O3 can cause problems but
  1078. # allow the builder to set O3 manually after.
  1079. if(DEFINED CMAKE_C_FLAGS_RELEASE)
  1080. set(_reset_standard_cflags_rel OFF)
  1081. else()
  1082. set(_reset_standard_cflags_rel ON)
  1083. endif()
  1084. if(DEFINED CMAKE_CXX_FLAGS_RELEASE)
  1085. set(_reset_standard_cxxflags_rel OFF)
  1086. else()
  1087. set(_reset_standard_cxxflags_rel ON)
  1088. endif()
  1089. endmacro()
  1090. macro(blender_project_hack_post)
  1091. # ----------------
  1092. # GCC -O3 HACK END
  1093. if(_reset_standard_cflags_rel)
  1094. string(REGEX REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
  1095. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "" FORCE)
  1096. mark_as_advanced(CMAKE_C_FLAGS_RELEASE)
  1097. endif()
  1098. if(_reset_standard_cxxflags_rel)
  1099. string(REGEX REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
  1100. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "" FORCE)
  1101. mark_as_advanced(CMAKE_CXX_FLAGS_RELEASE)
  1102. endif()
  1103. unset(_reset_standard_cflags_rel)
  1104. unset(_reset_standard_cxxflags_rel)
  1105. # ------------------------------------------------------------------
  1106. # workaround for omission in cmake 2.8.4's GNU.cmake, fixed in 2.8.5
  1107. if(CMAKE_COMPILER_IS_GNUCC)
  1108. if(NOT DARWIN)
  1109. set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ")
  1110. endif()
  1111. endif()
  1112. endmacro()
  1113. # pair of macros to allow libraries to be specify files to install, but to
  1114. # only install them at the end so the directories don't get cleared with
  1115. # the files in them. used by cycles to install addon.
  1116. function(delayed_install
  1117. base
  1118. files
  1119. destination)
  1120. foreach(f ${files})
  1121. if(IS_ABSOLUTE ${f})
  1122. set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_FILES ${f})
  1123. else()
  1124. set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_FILES ${base}/${f})
  1125. endif()
  1126. set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_DESTINATIONS ${destination})
  1127. endforeach()
  1128. endfunction()
  1129. # note this is a function instead of a macro so that ${BUILD_TYPE} in targetdir
  1130. # does not get expanded in calling but is preserved
  1131. function(delayed_do_install
  1132. targetdir)
  1133. get_property(files GLOBAL PROPERTY DELAYED_INSTALL_FILES)
  1134. get_property(destinations GLOBAL PROPERTY DELAYED_INSTALL_DESTINATIONS)
  1135. if(files)
  1136. list(LENGTH files n)
  1137. math(EXPR n "${n}-1")
  1138. foreach(i RANGE ${n})
  1139. list(GET files ${i} f)
  1140. list(GET destinations ${i} d)
  1141. install(FILES ${f} DESTINATION ${targetdir}/${d})
  1142. endforeach()
  1143. endif()
  1144. endfunction()
  1145. function(data_to_c
  1146. file_from file_to
  1147. list_to_add
  1148. )
  1149. list(APPEND ${list_to_add} ${file_to})
  1150. set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
  1151. get_filename_component(_file_to_path ${file_to} PATH)
  1152. add_custom_command(
  1153. OUTPUT ${file_to}
  1154. COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
  1155. COMMAND "$<TARGET_FILE:datatoc>" ${file_from} ${file_to}
  1156. DEPENDS ${file_from} datatoc)
  1157. set_source_files_properties(${file_to} PROPERTIES GENERATED TRUE)
  1158. endfunction()
  1159. # same as above but generates the var name and output automatic.
  1160. function(data_to_c_simple
  1161. file_from
  1162. list_to_add
  1163. )
  1164. # remove ../'s
  1165. get_filename_component(_file_from ${CMAKE_CURRENT_SOURCE_DIR}/${file_from} REALPATH)
  1166. get_filename_component(_file_to ${CMAKE_CURRENT_BINARY_DIR}/${file_from}.c REALPATH)
  1167. list(APPEND ${list_to_add} ${_file_to})
  1168. set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
  1169. get_filename_component(_file_to_path ${_file_to} PATH)
  1170. add_custom_command(
  1171. OUTPUT ${_file_to}
  1172. COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
  1173. COMMAND "$<TARGET_FILE:datatoc>" ${_file_from} ${_file_to}
  1174. DEPENDS ${_file_from} datatoc)
  1175. set_source_files_properties(${_file_to} PROPERTIES GENERATED TRUE)
  1176. endfunction()
  1177. # macro for converting pixmap directory to a png and then a c file
  1178. function(data_to_c_simple_icons
  1179. path_from
  1180. list_to_add
  1181. )
  1182. # Conversion steps
  1183. # path_from -> _file_from -> _file_to
  1184. # foo/*.dat -> foo.png -> foo.png.c
  1185. get_filename_component(_path_from_abs ${path_from} ABSOLUTE)
  1186. # remove ../'s
  1187. get_filename_component(_file_from ${CMAKE_CURRENT_BINARY_DIR}/${path_from}.png REALPATH)
  1188. get_filename_component(_file_to ${CMAKE_CURRENT_BINARY_DIR}/${path_from}.png.c REALPATH)
  1189. list(APPEND ${list_to_add} ${_file_to})
  1190. set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
  1191. get_filename_component(_file_to_path ${_file_to} PATH)
  1192. # ideally we wouldn't glob, but storing all names for all pixmaps is a bit heavy
  1193. file(GLOB _icon_files "${path_from}/*.dat")
  1194. add_custom_command(
  1195. OUTPUT ${_file_from} ${_file_to}
  1196. COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
  1197. #COMMAND python3 ${CMAKE_SOURCE_DIR}/source/blender/datatoc/datatoc_icon.py ${_path_from_abs} ${_file_from}
  1198. COMMAND "$<TARGET_FILE:datatoc_icon>" ${_path_from_abs} ${_file_from}
  1199. COMMAND "$<TARGET_FILE:datatoc>" ${_file_from} ${_file_to}
  1200. DEPENDS
  1201. ${_icon_files}
  1202. datatoc_icon
  1203. datatoc
  1204. # could be an arg but for now we only create icons depending on UI_icons.h
  1205. ${CMAKE_SOURCE_DIR}/source/blender/editors/include/UI_icons.h
  1206. )
  1207. set_source_files_properties(${_file_from} ${_file_to} PROPERTIES GENERATED TRUE)
  1208. endfunction()
  1209. # XXX Not used for now...
  1210. function(svg_to_png
  1211. file_from
  1212. file_to
  1213. dpi
  1214. list_to_add
  1215. )
  1216. # remove ../'s
  1217. get_filename_component(_file_from ${CMAKE_CURRENT_SOURCE_DIR}/${file_from} REALPATH)
  1218. get_filename_component(_file_to ${CMAKE_CURRENT_SOURCE_DIR}/${file_to} REALPATH)
  1219. list(APPEND ${list_to_add} ${_file_to})
  1220. set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
  1221. find_program(INKSCAPE_EXE inkscape)
  1222. mark_as_advanced(INKSCAPE_EXE)
  1223. if(INKSCAPE_EXE)
  1224. if(APPLE)
  1225. # in OS X app bundle, the binary is a shim that doesn't take any
  1226. # command line arguments, replace it with the actual binary
  1227. string(REPLACE "MacOS/Inkscape" "Resources/bin/inkscape" INKSCAPE_REAL_EXE ${INKSCAPE_EXE})
  1228. if(EXISTS "${INKSCAPE_REAL_EXE}")
  1229. set(INKSCAPE_EXE ${INKSCAPE_REAL_EXE})
  1230. endif()
  1231. endif()
  1232. add_custom_command(
  1233. OUTPUT ${_file_to}
  1234. COMMAND ${INKSCAPE_EXE} ${_file_from} --export-dpi=${dpi} --without-gui --export-png=${_file_to}
  1235. DEPENDS ${_file_from} ${INKSCAPE_EXE}
  1236. )
  1237. else()
  1238. message(WARNING "Inkscape not found, could not re-generate ${_file_to} from ${_file_from}!")
  1239. endif()
  1240. endfunction()
  1241. function(msgfmt_simple
  1242. file_from
  1243. list_to_add
  1244. )
  1245. # remove ../'s
  1246. get_filename_component(_file_from_we ${file_from} NAME_WE)
  1247. get_filename_component(_file_from ${file_from} REALPATH)
  1248. get_filename_component(_file_to ${CMAKE_CURRENT_BINARY_DIR}/${_file_from_we}.mo REALPATH)
  1249. list(APPEND ${list_to_add} ${_file_to})
  1250. set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
  1251. get_filename_component(_file_to_path ${_file_to} PATH)
  1252. add_custom_command(
  1253. OUTPUT ${_file_to}
  1254. COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
  1255. COMMAND "$<TARGET_FILE:msgfmt>" ${_file_from} ${_file_to}
  1256. DEPENDS msgfmt ${_file_from})
  1257. set_source_files_properties(${_file_to} PROPERTIES GENERATED TRUE)
  1258. endfunction()
  1259. function(find_python_package
  1260. package
  1261. )
  1262. string(TOUPPER ${package} _upper_package)
  1263. # set but invalid
  1264. if((NOT ${PYTHON_${_upper_package}_PATH} STREQUAL "") AND
  1265. (NOT ${PYTHON_${_upper_package}_PATH} MATCHES NOTFOUND))
  1266. # if(NOT EXISTS "${PYTHON_${_upper_package}_PATH}/${package}")
  1267. # message(WARNING "PYTHON_${_upper_package}_PATH is invalid, ${package} not found in '${PYTHON_${_upper_package}_PATH}' "
  1268. # "WITH_PYTHON_INSTALL_${_upper_package} option will be ignored when installing python")
  1269. # set(WITH_PYTHON_INSTALL${_upper_package} OFF)
  1270. # endif()
  1271. # not set, so initialize
  1272. else()
  1273. string(REPLACE "." ";" _PY_VER_SPLIT "${PYTHON_VERSION}")
  1274. list(GET _PY_VER_SPLIT 0 _PY_VER_MAJOR)
  1275. # re-cache
  1276. unset(PYTHON_${_upper_package}_PATH CACHE)
  1277. find_path(PYTHON_${_upper_package}_PATH
  1278. NAMES
  1279. ${package}
  1280. HINTS
  1281. "${PYTHON_LIBPATH}/python${PYTHON_VERSION}/"
  1282. "${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/"
  1283. PATH_SUFFIXES
  1284. site-packages
  1285. dist-packages
  1286. NO_DEFAULT_PATH
  1287. )
  1288. if(NOT EXISTS "${PYTHON_${_upper_package}_PATH}")
  1289. message(WARNING
  1290. "Python package '${package}' path could not be found in:\n"
  1291. "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/${package}', "
  1292. "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/site-packages/${package}', "
  1293. "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/${package}', "
  1294. "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/${package}', "
  1295. "\n"
  1296. "The 'WITH_PYTHON_INSTALL_${_upper_package}' option will be ignored when installing Python.\n"
  1297. "The build will be usable, only add-ons that depend on this package won't be functional."
  1298. )
  1299. set(WITH_PYTHON_INSTALL_${_upper_package} OFF PARENT_SCOPE)
  1300. else()
  1301. message(STATUS "${package} found at '${PYTHON_${_upper_package}_PATH}'")
  1302. endif()
  1303. endif()
  1304. endfunction()
  1305. # like Python's 'print(dir())'
  1306. function(print_all_vars)
  1307. get_cmake_property(_vars VARIABLES)
  1308. foreach(_var ${_vars})
  1309. message("${_var}=${${_var}}")
  1310. endforeach()
  1311. endfunction()
  1312. macro(openmp_delayload
  1313. projectname
  1314. )
  1315. if(MSVC)
  1316. if(WITH_OPENMP)
  1317. if(MSVC_VERSION EQUAL 1800)
  1318. set(OPENMP_DLL_NAME "vcomp120")
  1319. else()
  1320. set(OPENMP_DLL_NAME "vcomp140")
  1321. endif()
  1322. SET_TARGET_PROPERTIES(${projectname} PROPERTIES LINK_FLAGS_RELEASE "/DELAYLOAD:${OPENMP_DLL_NAME}.dll delayimp.lib")
  1323. SET_TARGET_PROPERTIES(${projectname} PROPERTIES LINK_FLAGS_DEBUG "/DELAYLOAD:${OPENMP_DLL_NAME}d.dll delayimp.lib")
  1324. SET_TARGET_PROPERTIES(${projectname} PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/DELAYLOAD:${OPENMP_DLL_NAME}.dll delayimp.lib")
  1325. SET_TARGET_PROPERTIES(${projectname} PROPERTIES LINK_FLAGS_MINSIZEREL "/DELAYLOAD:${OPENMP_DLL_NAME}.dll delayimp.lib")
  1326. endif(WITH_OPENMP)
  1327. endif(MSVC)
  1328. endmacro()
  1329. MACRO(WINDOWS_SIGN_TARGET target)
  1330. if(WITH_WINDOWS_CODESIGN)
  1331. if(!SIGNTOOL_EXE)
  1332. error("Codesigning is enabled, but signtool is not found")
  1333. else()
  1334. if(WINDOWS_CODESIGN_PFX_PASSWORD)
  1335. set(CODESIGNPASSWORD /p ${WINDOWS_CODESIGN_PFX_PASSWORD})
  1336. else()
  1337. if($ENV{PFXPASSWORD})
  1338. set(CODESIGNPASSWORD /p $ENV{PFXPASSWORD})
  1339. else()
  1340. message(FATAL_ERROR "WITH_WINDOWS_CODESIGN is on but WINDOWS_CODESIGN_PFX_PASSWORD not set, and environment variable PFXPASSWORD not found, unable to sign code.")
  1341. endif()
  1342. endif()
  1343. add_custom_command(TARGET ${target}
  1344. POST_BUILD
  1345. COMMAND ${SIGNTOOL_EXE} sign /f ${WINDOWS_CODESIGN_PFX} ${CODESIGNPASSWORD} $<TARGET_FILE:${target}>
  1346. VERBATIM
  1347. )
  1348. endif()
  1349. endif()
  1350. ENDMACRO()