CMakeLists.txt 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. cmake_policy(SET CMP0003 NEW)
  2. cmake_policy(SET CMP0005 NEW)
  3. cmake_minimum_required(VERSION 2.8)
  4. list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../..//build_files/cmake/Modules")
  5. set(WITH_GUARDEDALLOC ON)
  6. # -----------------------------------------------------------------------------
  7. # Macros
  8. # stub macro, does nothing
  9. macro(blender_add_lib
  10. name
  11. sources
  12. includes
  13. includes_sys
  14. )
  15. endmacro()
  16. # suffix relative paths so we can use external cmake files
  17. macro(suffix_relpaths
  18. new_files files prefix)
  19. set(${new_files})
  20. foreach(_file ${files})
  21. if(IS_ABSOLUTE _file)
  22. list(APPEND ${new_files} ${_file})
  23. else()
  24. list(APPEND ${new_files} "${prefix}${_file}")
  25. endif()
  26. endforeach()
  27. unset(_file)
  28. endmacro()
  29. macro(data_to_c
  30. file_from file_to
  31. list_to_add)
  32. list(APPEND ${list_to_add} ${file_to})
  33. get_filename_component(_file_to_path ${file_to} PATH)
  34. add_custom_command(
  35. OUTPUT ${file_to}
  36. COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
  37. COMMAND ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/datatoc ${file_from} ${file_to}
  38. DEPENDS ${file_from} datatoc)
  39. unset(_file_to_path)
  40. endmacro()
  41. # -----------------------------------------------------------------------------
  42. # Defines
  43. # set the endian define
  44. if(MSVC)
  45. # for some reason this fails on msvc
  46. add_definitions(-D__LITTLE_ENDIAN__)
  47. else()
  48. include(TestBigEndian)
  49. test_big_endian(_SYSTEM_BIG_ENDIAN)
  50. if(_SYSTEM_BIG_ENDIAN)
  51. add_definitions(-D__BIG_ENDIAN__)
  52. else()
  53. add_definitions(-D__LITTLE_ENDIAN__)
  54. endif()
  55. unset(_SYSTEM_BIG_ENDIAN)
  56. endif()
  57. # -----------------------------------------------------------------------------
  58. # Libraries
  59. if(UNIX AND NOT APPLE)
  60. set(WITH_X11 ON)
  61. endif()
  62. # for now... default to this
  63. add_definitions(-DWITH_GL_PROFILE_COMPAT)
  64. # BLF needs this to ignore GPU library
  65. add_definitions(-DBLF_STANDALONE)
  66. # ghost
  67. include(${CMAKE_SOURCE_DIR}/../CMakeLists.txt)
  68. suffix_relpaths(INC_NEW "${INC}" "../")
  69. suffix_relpaths(SRC_NEW "${SRC}" "../")
  70. include_directories(${INC_NEW})
  71. add_library(ghost_lib ${SRC_NEW})
  72. # string
  73. include(${CMAKE_SOURCE_DIR}/../../string/CMakeLists.txt)
  74. suffix_relpaths(INC_NEW "${INC}" "../../string/")
  75. suffix_relpaths(SRC_NEW "${SRC}" "../../string/")
  76. include_directories(${INC_NEW})
  77. add_library(string_lib ${SRC_NEW})
  78. # guardedalloc
  79. include(${CMAKE_SOURCE_DIR}/../../guardedalloc/CMakeLists.txt)
  80. suffix_relpaths(INC_NEW "${INC}" "../../guardedalloc/")
  81. suffix_relpaths(SRC_NEW "${SRC}" "../../guardedalloc/")
  82. include_directories(${INC_NEW})
  83. add_library(guardedalloc_lib ${SRC_NEW})
  84. # blenfont
  85. include(${CMAKE_SOURCE_DIR}/../../../source/blender/blenfont/CMakeLists.txt)
  86. suffix_relpaths(INC_NEW "${INC}" "../../../source/blender/blenfont/")
  87. suffix_relpaths(SRC_NEW "${SRC}" "../../../source/blender/blenfont/")
  88. include_directories(${INC_NEW})
  89. add_library(blenfont_lib ${SRC_NEW})
  90. # wcwidth
  91. include(${CMAKE_SOURCE_DIR}/../../../extern/wcwidth/CMakeLists.txt)
  92. suffix_relpaths(INC_NEW "${INC}" "../../../extern/wcwidth/")
  93. suffix_relpaths(SRC_NEW "${SRC}" "../../../extern/wcwidth/")
  94. include_directories(${INC_NEW})
  95. add_library(wcwidth_lib ${SRC_NEW})
  96. # glew-mx
  97. include(${CMAKE_SOURCE_DIR}/../../../intern/glew-mx/CMakeLists.txt)
  98. suffix_relpaths(INC_NEW "${INC}" "../../../intern/glew-mx/")
  99. suffix_relpaths(SRC_NEW "${SRC}" "../../../intern/glew-mx/")
  100. include_directories(${INC_NEW})
  101. add_library(glewmx_lib ${SRC_NEW})
  102. # grr, blenfont needs BLI
  103. include_directories(
  104. "../../../source/blender/blenlib"
  105. )
  106. add_library(bli_lib
  107. "../../../source/blender/blenlib/intern/fileops.c"
  108. "../../../source/blender/blenlib/intern/gsqueue.c"
  109. "../../../source/blender/blenlib/intern/rct.c"
  110. "../../../source/blender/blenlib/intern/string.c"
  111. "../../../source/blender/blenlib/intern/string_utf8.c"
  112. "../../../source/blender/blenlib/intern/listbase.c"
  113. "../../../source/blender/blenlib/intern/math_color.c"
  114. "../../../source/blender/blenlib/intern/storage.c"
  115. "../../../source/blender/blenlib/intern/task.c"
  116. "../../../source/blender/blenlib/intern/threads.c"
  117. "../../../source/blender/blenlib/intern/time.c"
  118. "../../../source/blender/blenlib/intern/path_util.c"
  119. "../../../source/blender/blenlib/intern/BLI_dynstr.c"
  120. "../../../source/blender/blenlib/intern/BLI_linklist.c"
  121. "../../../source/blender/blenlib/intern/BLI_memarena.c"
  122. "../../../source/blender/blenlib/intern/BLI_mempool.c"
  123. "../../../source/blender/blenlib/intern/system.c"
  124. )
  125. set(PLATFORM_CGLAGS)
  126. find_package(OpenGL REQUIRED)
  127. find_package(Freetype REQUIRED)
  128. find_package(ZLIB REQUIRED)
  129. include_directories(${CMAKE_SOURCE_DIR}/../)
  130. include_directories(${OPENGL_INCLUDE_DIR})
  131. include_directories(${FREETYPE_INCLUDE_DIRS})
  132. include_directories(${CMAKE_SOURCE_DIR}/../../../source/blender/blenfont)
  133. if(CMAKE_COMPILER_IS_GNUCC)
  134. set(PLATFORM_CFLAGS "-funsigned-char")
  135. endif()
  136. if(UNIX AND NOT APPLE)
  137. find_package(X11 REQUIRED)
  138. find_package(GLEW)
  139. if(NOT GLEW_FOUND)
  140. message(FATAL_ERROR "GLEW is required to build blender, install it or disable WITH_SYSTEM_GLEW")
  141. endif()
  142. set(PLATFORM_LINKLIBS
  143. ${X11_X11_LIB}
  144. ${X11_Xinput_LIB}
  145. ${GLEW_LIBRARY}
  146. -lpthread
  147. )
  148. else()
  149. # set(GLEW_LIBRARY "") # unused
  150. set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
  151. endif()
  152. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
  153. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
  154. # -----------------------------------------------------------------------------
  155. # Executables
  156. # DataToC
  157. add_executable(datatoc
  158. ${CMAKE_SOURCE_DIR}/../../../source/blender/datatoc/datatoc.c)
  159. # Gears (C)
  160. add_executable(gears_c
  161. ${CMAKE_SOURCE_DIR}/gears/GHOST_C-Test.c)
  162. target_link_libraries(gears_c
  163. ghost_lib
  164. glewmx_lib
  165. string_lib
  166. ${OPENGL_gl_LIBRARY}
  167. ${CMAKE_DL_LIBS}
  168. ${PLATFORM_LINKLIBS}
  169. )
  170. # Gears (C++)
  171. add_executable(gears_cpp
  172. ${CMAKE_SOURCE_DIR}/gears/GHOST_Test.cpp)
  173. target_link_libraries(gears_cpp
  174. ghost_lib
  175. glewmx_lib
  176. string_lib
  177. ${OPENGL_gl_LIBRARY}
  178. ${CMAKE_DL_LIBS}
  179. ${PLATFORM_LINKLIBS}
  180. )
  181. # MultiTest (C)
  182. set(data_to_c_files)
  183. data_to_c(${CMAKE_SOURCE_DIR}/../../../release/datafiles/bfont.ttf
  184. ${CMAKE_CURRENT_BINARY_DIR}/bfont.ttf.c data_to_c_files)
  185. add_executable(multitest_c
  186. ${CMAKE_SOURCE_DIR}/multitest/Basic.c
  187. ${CMAKE_SOURCE_DIR}/multitest/EventToBuf.c
  188. ${CMAKE_SOURCE_DIR}/multitest/MultiTest.c
  189. ${CMAKE_SOURCE_DIR}/multitest/ScrollBar.c
  190. ${CMAKE_SOURCE_DIR}/multitest/Util.c
  191. ${CMAKE_SOURCE_DIR}/multitest/WindowData.c
  192. ${CMAKE_SOURCE_DIR}/multitest/stubs.c
  193. ${data_to_c_files}
  194. )
  195. target_link_libraries(multitest_c
  196. blenfont_lib
  197. bli_lib
  198. ghost_lib
  199. glewmx_lib
  200. string_lib
  201. guardedalloc_lib
  202. wcwidth_lib
  203. ${OPENGL_gl_LIBRARY}
  204. ${FREETYPE_LIBRARY}
  205. ${ZLIB_LIBRARIES}
  206. ${CMAKE_DL_LIBS}
  207. ${PLATFORM_LINKLIBS}
  208. )