e1475966d47e4b720fc7eb8b18d270c3e71be0f8
[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
83 # ghost
84 include(${CMAKE_SOURCE_DIR}/../CMakeLists.txt)
85 suffix_relpaths(INC_NEW "${INC}" "../")
86 suffix_relpaths(SRC_NEW "${SRC}" "../")
87 include_directories(${INC_NEW})
88 add_library(ghost_lib ${SRC_NEW})
89
90 # string
91 include(${CMAKE_SOURCE_DIR}/../../string/CMakeLists.txt)
92 suffix_relpaths(INC_NEW "${INC}" "../../string/")
93 suffix_relpaths(SRC_NEW "${SRC}" "../../string/")
94 include_directories(${INC_NEW})
95 add_library(string_lib ${SRC_NEW})
96
97 # guardedalloc
98 include(${CMAKE_SOURCE_DIR}/../../guardedalloc/CMakeLists.txt)
99 suffix_relpaths(INC_NEW "${INC}" "../../guardedalloc/")
100 suffix_relpaths(SRC_NEW "${SRC}" "../../guardedalloc/")
101 include_directories(${INC_NEW})
102 add_library(guardedalloc_lib ${SRC_NEW})
103
104 # blenfont 
105 include(${CMAKE_SOURCE_DIR}/../../../source/blender/blenfont/CMakeLists.txt)
106 suffix_relpaths(INC_NEW "${INC}" "../../../source/blender/blenfont/")
107 suffix_relpaths(SRC_NEW "${SRC}" "../../../source/blender/blenfont/")
108 include_directories(${INC_NEW})
109 add_library(blenfont_lib ${SRC_NEW})
110
111 # wcwidth
112 include(${CMAKE_SOURCE_DIR}/../../../extern/wcwidth/CMakeLists.txt)
113 suffix_relpaths(INC_NEW "${INC}" "../../../extern/wcwidth/")
114 suffix_relpaths(SRC_NEW "${SRC}" "../../../extern/wcwidth/")
115 include_directories(${INC_NEW})
116 add_library(wcwidth_lib ${SRC_NEW})
117
118 # glew-mx
119 include(${CMAKE_SOURCE_DIR}/../../../intern/glew-mx/CMakeLists.txt)
120 suffix_relpaths(INC_NEW "${INC}" "../../../intern/glew-mx/")
121 suffix_relpaths(SRC_NEW "${SRC}" "../../../intern/glew-mx/")
122 include_directories(${INC_NEW})
123 add_library(glewmx_lib ${SRC_NEW})
124
125 # grr, blenfont needs BLI
126 include_directories(
127                 "../../../source/blender/blenlib"
128                 )
129 add_library(bli_lib 
130                 "../../../source/blender/blenlib/intern/fileops.c"
131                 "../../../source/blender/blenlib/intern/gsqueue.c"
132                 "../../../source/blender/blenlib/intern/rct.c"
133                 "../../../source/blender/blenlib/intern/string.c"
134                 "../../../source/blender/blenlib/intern/string_utf8.c"
135                 "../../../source/blender/blenlib/intern/listbase.c"
136                 "../../../source/blender/blenlib/intern/math_color.c"
137                 "../../../source/blender/blenlib/intern/storage.c"
138                 "../../../source/blender/blenlib/intern/task.c"
139                 "../../../source/blender/blenlib/intern/threads.c"
140                 "../../../source/blender/blenlib/intern/time.c"
141                 "../../../source/blender/blenlib/intern/path_util.c"
142                 "../../../source/blender/blenlib/intern/BLI_dynstr.c"
143                 "../../../source/blender/blenlib/intern/BLI_linklist.c"
144                 "../../../source/blender/blenlib/intern/BLI_memarena.c"
145                 "../../../source/blender/blenlib/intern/BLI_mempool.c"
146                 "../../../source/blender/blenlib/intern/system.c"
147                 )
148
149 set(PLATFORM_CGLAGS)
150
151 find_package(OpenGL REQUIRED)
152
153 find_package(Freetype REQUIRED)
154
155 find_package(ZLIB REQUIRED)
156
157 include_directories(${CMAKE_SOURCE_DIR}/../)
158 include_directories(${OPENGL_INCLUDE_DIR})
159 include_directories(${FREETYPE_INCLUDE_DIRS})
160 include_directories(${CMAKE_SOURCE_DIR}/../../../source/blender/blenfont)
161
162 if(CMAKE_COMPILER_IS_GNUCC)
163         set(PLATFORM_CFLAGS "-funsigned-char")
164 endif()
165
166 if(UNIX AND NOT APPLE)
167         find_package(X11 REQUIRED)
168         find_package(GLEW)
169
170         if(NOT GLEW_FOUND)
171                 message(FATAL_ERROR "GLEW is required to build blender, install it or disable WITH_SYSTEM_GLEW")
172         endif()
173
174         set(PLATFORM_LINKLIBS
175                 ${X11_X11_LIB}
176                 ${X11_Xinput_LIB}
177                 ${GLEW_LIBRARY}
178                 -lpthread
179         )
180 else()
181         # set(GLEW_LIBRARY "")  # unused
182         set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
183 endif()
184
185 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
186 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
187
188 # -----------------------------------------------------------------------------
189 # Executables
190
191 # DataToC
192 add_executable(datatoc
193                 ${CMAKE_SOURCE_DIR}/../../../source/blender/datatoc/datatoc.c)
194
195 # Gears (C)
196 add_executable(gears_c
197                 ${CMAKE_SOURCE_DIR}/gears/GHOST_C-Test.c)
198
199 target_link_libraries(gears_c
200                 ghost_lib
201                 glewmx_lib
202                 string_lib
203                 ${OPENGL_gl_LIBRARY}
204                 ${OPENGL_glu_LIBRARY}
205                 ${PLATFORM_LINKLIBS}
206                 )
207
208
209 # Gears (C++)
210 add_executable(gears_cpp
211                 ${CMAKE_SOURCE_DIR}/gears/GHOST_Test.cpp)
212
213 target_link_libraries(gears_cpp
214                 ghost_lib
215                 glewmx_lib
216                 string_lib
217                 ${OPENGL_gl_LIBRARY}
218                 ${OPENGL_glu_LIBRARY}
219                 ${PLATFORM_LINKLIBS}
220                 )
221
222
223 # MultiTest (C)
224 set(data_to_c_files)
225 data_to_c(${CMAKE_SOURCE_DIR}/../../../release/datafiles/bfont.ttf
226           ${CMAKE_CURRENT_BINARY_DIR}/bfont.ttf.c data_to_c_files)
227
228 add_executable(multitest_c
229         ${CMAKE_SOURCE_DIR}/multitest/Basic.c
230         ${CMAKE_SOURCE_DIR}/multitest/EventToBuf.c
231         ${CMAKE_SOURCE_DIR}/multitest/MultiTest.c
232         ${CMAKE_SOURCE_DIR}/multitest/ScrollBar.c
233         ${CMAKE_SOURCE_DIR}/multitest/Util.c
234         ${CMAKE_SOURCE_DIR}/multitest/WindowData.c
235         ${CMAKE_SOURCE_DIR}/multitest/stubs.c
236         ${data_to_c_files}
237 )
238
239
240 target_link_libraries(multitest_c
241                 blenfont_lib
242                 bli_lib
243                 ghost_lib
244                 glewmx_lib
245                 string_lib
246                 guardedalloc_lib
247                 wcwidth_lib
248                 ${OPENGL_gl_LIBRARY}
249                 ${OPENGL_glu_LIBRARY}
250                 ${FREETYPE_LIBRARY}
251                 ${ZLIB_LIBRARIES}
252                 ${PLATFORM_LINKLIBS}
253                 )