ref: 975708bd2c947b0bfdbdc3569212755b925e13cd xrgears/CMakeLists.txt -rw-r--r-- 6.3 KiB View raw
                                                                                
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
cmake_minimum_required(VERSION 3.8)
project(xrgears)

# Yeah it's gross but it's to find the assets. You're welcome to make it better.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/")

add_definitions(-DVK_USE_PLATFORM_WAYLAND_KHR)
add_definitions(-DVK_USE_PLATFORM_XCB_KHR)

# Warnings
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  add_compile_options(-Weverything)

  # disable warnings
  add_compile_options(
    # ignore these
    -Wno-c++98-compat
    -Wno-c++98-compat-pedantic
    -Wno-weak-vtables
    -Wno-c99-extensions

    -Wno-unused-parameter
    -Wno-old-style-cast
    -Wno-padded

    # probably we want to fix these
    -Wno-switch-enum
    -Wno-double-promotion
    -Wno-zero-as-null-pointer-constant
    -Wno-documentation
    -Wno-conversion
    -Wno-shadow-field-in-constructor
    -Wno-shadow
    -Wno-shadow-uncaptured-local
    -Wno-cast-align
    -Wno-pedantic
    -Wno-format-nonliteral
    -Wno-unused-macros
    -Wno-shadow-field
    -Wno-disabled-macro-expansion
    -Wno-covered-switch-default
    -Wno-cast-qual
    -Wno-documentation-unknown-command
    -Wno-missing-field-initializers
    -Wno-reserved-id-macro
    -Wno-missing-variable-declarations
  )
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  add_compile_options(
    -Wall
    -Wextra
    # We want to ignore these
    -Wno-missing-field-initializers
    -Wno-unused-parameter
  )
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(PkgConfig REQUIRED)

pkg_search_module(VULKAN REQUIRED vulkan)
pkg_search_module(OPENHMD REQUIRED openhmd)
pkg_search_module(ASSIMP REQUIRED assimp)
pkg_search_module(XCB REQUIRED xcb)
pkg_search_module(XCB_KEY REQUIRED xcb-keysyms)
pkg_search_module(XCB_RANDR REQUIRED xcb-randr)
pkg_search_module(WAYLAND REQUIRED wayland-client)
pkg_search_module(GBM REQUIRED gbm)
pkg_search_module(DRM REQUIRED libdrm)
pkg_search_module(WAYLAND_SCANNER REQUIRED wayland-scanner)
pkg_search_module(WAYLAND_PROTOCOLS REQUIRED wayland-protocols)
pkg_search_module(GLM REQUIRED glm)

pkg_search_module(X11 REQUIRED x11)

file(GLOB VITAMINK_SRC vitamin-k/*.hpp)

pkg_get_variable(WAYLAND_PROTOCOLS_DATADIR wayland-protocols pkgdatadir)
pkg_get_variable(WAYLAND_SCANNER wayland-scanner wayland_scanner)
message("WAYLAND_SCANNER found: ${WAYLAND_SCANNER}")
message("WAYLAND_PROTOCOLS_DATADIR: ${WAYLAND_PROTOCOLS_DATADIR}")

set(VITAMIN_K_INCLUDES
  ${CMAKE_CURRENT_SOURCE_DIR}/wayland-protocols
  ${CMAKE_CURRENT_SOURCE_DIR}/fonts
  ${OPENHMD_INCLUDE_DIRS}
  ${DRM_INCLUDE_DIRS}
)

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/vitamin-k
    ${VITAMIN_K_INCLUDES}
)

include(CheckIncludeFileCXX)
find_file(VULKAN_INTEL_INCLUDE_FILE
    NAMES
    vulkan/vulkan_intel.h
    HINTS
    # Vulkan include dir?
    )
CHECK_INCLUDE_FILE_CXX(vulkan/vulkan_intel.h HAVE_VULKAN_INTEL)

find_path(GLI_INCLUDE_DIR
    NAMES
    gli/gli.hpp)
if(NOT GLI_INCLUDE_DIR)
    message(FATAL_ERROR "GLI not found. Get a version matching GLM from https://github.com/g-truc/gli")
endif()
include_directories(${GLI_INCLUDE_DIR})

if(VULKAN_INTEL_INCLUDE_FILE)
   add_definitions(-DHAVE_VULKAN_INTEL)
endif()

set(SHADER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/shaders)

file(GLOB_RECURSE SHADER_GLOB
    RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
    ${SHADER_DIR}/*.vert
    ${SHADER_DIR}/*.frag
    ${SHADER_DIR}/*.geom)

# build shaders

find_program(GLSLANG glslangValidator)

if(NOT GLSLANG)
  message(FATAL_ERROR "glslang was not found.")
endif()

set(CUSTOM_OUTPUTS)
foreach(SHADER ${SHADER_GLOB})
    set(OUTFILE "${CMAKE_CURRENT_SOURCE_DIR}/${SHADER}.spv")
    add_custom_command(OUTPUT "${OUTFILE}"
        COMMAND
        "${GLSLANG}" -V -o "${OUTFILE}" "${CMAKE_CURRENT_SOURCE_DIR}/${SHADER}"
        VERBATIM
        WORKING_DIRECTORY "${SHADER_DIR}"
        COMMENT "Compiling ${SHADER} with glslang")
    list(APPEND CUSTOM_OUTPUTS "${OUTFILE}")
endforeach()

# generate wayland protocols
set(WAYLAND_PROTOCOLS_DIR "${CMAKE_CURRENT_BINARY_DIR}/wayland-protocols/")
file(MAKE_DIRECTORY "${WAYLAND_PROTOCOLS_DIR}")

set(PROTOCOL xdg-shell-unstable-v6)
set(PROTOCOL_XML
    "${WAYLAND_PROTOCOLS_DATADIR}/unstable/xdg-shell/${PROTOCOL}.xml")

set(WAYLAND_PROTOCOLS_SRC)
set(OUTFILE "${WAYLAND_PROTOCOLS_DIR}/${PROTOCOL}.c")
list(APPEND WAYLAND_PROTOCOLS_SRC "${OUTFILE}")
add_custom_command(OUTPUT "${OUTFILE}"
    COMMAND
    ${WAYLAND_SCANNER}
    code
    "${PROTOCOL_XML}"
    "${OUTFILE}"
    VERBATIM
    COMMENT "Generating code file with wayland-scanner")


set(OUTFILE "${WAYLAND_PROTOCOLS_DIR}/${PROTOCOL}.h")
list(APPEND WAYLAND_PROTOCOLS_SRC "${OUTFILE}")
add_custom_command(OUTPUT "${OUTFILE}"
    COMMAND
    ${WAYLAND_SCANNER}
    client-header
    "${PROTOCOL_XML}"
    "${OUTFILE}"
    VERBATIM
    COMMENT "Generating client header file with wayland-scanner")

add_library(wayland-protocols ${WAYLAND_PROTOCOLS_SRC})
target_include_directories(wayland-protocols PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")

file(GLOB_RECURSE VITAMINK_SRC vitamin-k/*.hpp)

add_library(vitamin-k INTERFACE)
target_compile_definitions(vitamin-k
    INTERFACE LIBRARY_HEADER_ONLY
)
target_sources(vitamin-k INTERFACE ${VITAMINK_SRC})
target_include_directories(vitamin-k INTERFACE ${VITAMIN_K_INCLUDES})

set(LINT_SOURCES ${VITAMINK_SRC})

set(EXAMPLE_LIBS
    ${VULKAN_LIBRARIES}
    ${OPENHMD_LIBRARIES}
    ${ASSIMP_LIBRARIES}
    ${XCB_LIBRARIES}
    ${XCB_KEY_LIBRARIES}
    ${WAYLAND_LIBRARIES}
    wayland-protocols
    ${GBM_LIBRARIES}
    ${XCB_RANDR_LIBRARIES}
    ${X11_LIBRARIES}
    X11
    ${DRM_LIBRARIES})

# Function for building single example
function(buildExample EXAMPLE_NAME)
    file(GLOB EXAMPLE_SRC examples/${EXAMPLE_NAME}/*.cpp)
    add_executable(${EXAMPLE_NAME} ${EXAMPLE_SRC} ${CUSTOM_OUTPUTS})
    set(LINT_SOURCES ${LINT_SOURCES} ${EXAMPLE_SRC} PARENT_SCOPE)
    target_link_libraries(${EXAMPLE_NAME} ${EXAMPLE_LIBS})
    target_compile_features(${EXAMPLE_NAME} PRIVATE cxx_std_14)
endfunction(buildExample)

# build examples
FILE(GLOB EXAMPLE_DIRS RELATIVE
    ${CMAKE_SOURCE_DIR}/examples
    ${CMAKE_SOURCE_DIR}/examples/*)

# Build all examples
foreach(EXAMPLE ${EXAMPLE_DIRS})
    buildExample(${EXAMPLE})
endforeach(EXAMPLE)

set(IGNORE
    "-build/c++11,"
    "-build/header_guard,"
    "-readability/casting,"
    "-whitespace/line_length,"
    "-whitespace/parens")

add_custom_target(style COMMAND
    python2 ${CMAKE_SOURCE_DIR}/scripts/cpplint.py --headers=hpp --filter="${IGNORE}" ${LINT_SOURCES})