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