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