summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: a2fcb3209b0fb8dcb788d138d50c3c221bff624b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# Copyright 2012 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

project(waffle C)
cmake_minimum_required(VERSION 2.8)

# Release version.
set(waffle_version 0.2)

# Library version.
#
# The library version scheme follows the libtool guidelines and is independent
# of the release version. It is appended to libwaffle.so as libwaffle.so.X.X.X.
# See http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html.
set(waffle_so_version "1.0.0")

# ------------------------------------------------------------------------------
# Waffle Options
# ------------------------------------------------------------------------------

# All options here are prefixed with `waffle_`. Most options are cache
# variables set by the user.

# ----------------------------------------------
# Set waffle options
# ----------------------------------------------

option(waffle_build_tests "Build tests" ON)
option(waffle_build_examples "Build examples" ON)

option(waffle_has_glx "Build support for GLX" OFF)
option(waffle_has_wayland "Build support for Wayland" OFF)
option(waffle_has_x11_egl "Build support for X11/EGL" OFF)

set(waffle_install_includedir "${CMAKE_INSTALL_PREFIX}/include"
    CACHE PATH "Directory where header files will be installed")

set(waffle_install_libdir "${CMAKE_INSTALL_PREFIX}/lib"
    CACHE PATH "Directory where libraries will be installed")

set(waffle_install_docdir "${CMAKE_INSTALL_PREFIX}/share/doc/waffle"
    CACHE PATH "Directory where documentation will be installed")

#
# Set internal options.
#

if(waffle_has_wayland OR waffle_has_x11_egl)
    set(waffle_has_egl TRUE)
else(waffle_has_wayland OR waffle_has_x11_egl)
    set(waffle_has_egl FALSE)
endif(waffle_has_wayland OR waffle_has_x11_egl)

if(waffle_has_glx OR waffle_has_x11_egl)
    set(waffle_has_x11 TRUE)
else(waffle_has_glx OR waffle_has_x11_egl)
    set(waffle_has_x11 FALSE)
endif(waffle_has_glx OR waffle_has_x11_egl)

# ----------------------------------------------
# Validate waffle options
# ----------------------------------------------

if(NOT waffle_has_glx
   AND NOT waffle_has_x11_egl)
    message(FATAL_ERROR "Must enable at least one of: waffle_has_glx, waffle_has_x11_egl.")
endif(NOT waffle_has_glx
      AND NOT waffle_has_x11_egl)


# ------------------------------------------------------------------------------
# Find Libraries
# ------------------------------------------------------------------------------

function(waffle_find_library var name)
    find_library("${var}" "${name}")

    if("${var}")
        message(STATUS "Library ${name} found: ${${var}}")
    else("${var}")
        message(STATUS "Library ${name} not found")
    endif("${var}")
endfunction(waffle_find_library)

if(waffle_has_egl)
    waffle_find_library(waffle_EGL_library EGL)
endif(waffle_has_egl)

if(waffle_has_glx)
    waffle_find_library(waffle_GL_library GL)
endif(waffle_has_glx)

if(waffle_has_wayland)
    waffle_find_library(waffle_wayland-client_library wayland-client)
    waffle_find_library(waffle_wayland-egl_library wayland-egl)
endif(waffle_has_wayland)

if(waffle_has_x11)
    waffle_find_library(waffle_X11-xcb_library X11-xcb)
endif(waffle_has_x11)


# ------------------------------------------------------------------------------
# Compiler Flags
# ------------------------------------------------------------------------------

# FIXME: Only enable c99 if compiler supports it.
set(CMAKE_C_FLAGS "--std=c99 -Wall -Werror")

set(CMAKE_C_FLAGS_DEBUG "-g3 -O0 -DDEBUG")

# Produce enough debug info for generating backtraces, but not
# single-stepping.
set(CMAKE_C_FLAGS_RELEASE "-g1 -02 -DNDEBUG")

#
# Define macros WAFFLE_HAS_{PLATFORM}.
#
# Android is not in this list because it uses a separate build system.
#

if(waffle_has_glx)
    add_definitions(-DWAFFLE_HAS_GLX)
endif(waffle_has_glx)

if(waffle_has_wayland)
    add_definitions(-DWAFFLE_HAS_WAYLAND)
endif(waffle_has_wayland)

if(waffle_has_x11_egl)
    add_definitions(-DWAFFLE_HAS_X11_EGL)
endif(waffle_has_x11_egl)

# ------------------------------------------------------------------------------
# Add subdirectories
# ------------------------------------------------------------------------------

include_directories(include src)

add_subdirectory(src)
add_subdirectory(include)

if(waffle_build_tests)
    add_subdirectory(tests)
endif(waffle_build_tests)

if(waffle_build_examples)
    add_subdirectory(examples)
endif(waffle_build_examples)

# ------------------------------------------------------------------------------
# Target: check
# ------------------------------------------------------------------------------

# The unit tests are ran first. If they fail, then no subsequent tests are ran.

if(waffle_build_tests)
    add_custom_target(check
        DEPENDS waffle-unittest gl_basic_test
        COMMAND ${CMAKE_BINARY_DIR}/tests/unittests/waffle-unittest
        COMMAND ${CMAKE_BINARY_DIR}/tests/functional/gl_basic_test
        )
endif(waffle_build_tests)

# ------------------------------------------------------------------------------
# Install: waffle.pc
# ------------------------------------------------------------------------------

configure_file(waffle.pc.in waffle.pc @ONLY)

install(FILES ${CMAKE_BINARY_DIR}/waffle.pc
        DESTINATION ${waffle_install_libdir}/pkgconfig)

# ------------------------------------------------------------------------------
# Print summary
# ------------------------------------------------------------------------------

# CMake is annoyingly silent compared to autoconf. The user wants to know what
# was configured how.

message("-----------------------------------------------")
message("")
message("Waffle configuration summary")
message("")
message("Supported platforms: ")
if(waffle_has_glx)
    message("    glx")
endif(waffle_has_glx)
if(waffle_has_wayland)
    message("    wayland")
endif(waffle_has_wayland)
if(waffle_has_x11_egl)
    message("    x11_egl")
endif(waffle_has_x11_egl)
message("")
message("Libraries:")
if(DEFINED waffle_EGL_library)
    message("    EGL: ${waffle_EGL_library}")
endif(DEFINED waffle_EGL_library)
if(DEFINED waffle_GL_library)
    message("    GL: ${waffle_GL_library}")
endif(DEFINED waffle_GL_library)
if(waffle_has_wayland)
    message("    wayland-client: ${waffle_wayland-client_library}")
    message("    wayland-egl: ${waffle_wayland-egl_library}")
endif(waffle_has_wayland)
if(DEFINED waffle_X11-xcb_library)
    message("    X11-xcb: ${waffle_X11-xcb_library}")
endif(DEFINED waffle_X11-xcb_library)
message("")
message("Build type:")
message("    ${CMAKE_BUILD_TYPE}")
message("")
message("Tools:")
message("    cc: ${CMAKE_C_COMPILER}")
message("    CFLAGS_base: ${CMAKE_C_FLAGS}")
message("    CFLAGS_debug: ${CMAKE_C_FLAGS_DEBUG}")
message("    CFLAGS_release: ${CMAKE_C_FLAGS_RELEASE}")
message("")
message("Install paths:")
message("    includedir: ${waffle_install_libdir}")
message("    libdir: ${waffle_install_libdir}")
message("    docdir: ${waffle_install_docdir}")
message("-----------------------------------------------")