forked from jchnkl/xpp
-
Notifications
You must be signed in to change notification settings - Fork 11
/
CMakeLists.txt
199 lines (174 loc) · 5.78 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR)
project(xpp)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
#
# Process dependencies
#
find_package(PkgConfig)
pkg_check_modules(XCBPROTO REQUIRED xcb-proto)
# Store the location of the proto xml files inside XCBPROTO_XCBINCLUDEDIR
pkg_get_variable(XCBPROTO_XCBINCLUDEDIR xcb-proto xcbincludedir)
# Search for a python interpreter, if the user didn't specify any
if(NOT PYTHON_EXECUTABLE)
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
find_package(PythonInterp 3.5 REQUIRED)
else()
find_package(Python3 REQUIRED COMPONENTS Interpreter)
if(Python3_FOUND)
set(PYTHON_EXECUTABLE "${Python3_EXECUTABLE}")
endif()
endif()
endif()
if(NOT PYTHON_EXECUTABLE)
message(FATAL_ERROR "Missing PYTHON_EXECUTABLE")
endif()
find_package(XCB REQUIRED XCB ICCCM EWMH UTIL IMAGE)
set(GEN_SRC "${CMAKE_CURRENT_BINARY_DIR}/generated-sources")
set(XPP_INCLUDE_DIRS
${PROJECT_SOURCE_DIR}/include
${GEN_SRC}/include
${XCB_XCB_INCLUDE_DIR}
${XCB_EWMH_INCLUDE_DIR}
${XCB_ICCCM_INCLUDE_DIR}
${XCB_UTIL_INCLUDE_DIR}
${XCB_IMAGE_INCLUDE_DIR})
set(XPP_LIBRARIES
${XCB_XCB_LIBRARY}
${XCB_EWMH_LIBRARY}
${XCB_ICCCM_LIBRARY}
${XCB_UTIL_LIBRARY}
${XCB_IMAGE_LIBRARY})
#
# Loop through a hardcoded list of python executables to locate the python module "xcbgen"
#
# TODO drop python2 once ubuntu and debian ship python3-xcbgen in their
# maintained distros
foreach(CURRENT_EXECUTABLE ${PYTHON_EXECUTABLE} python3 python python2 python2.7)
message(STATUS "Searching for xcbgen with " ${CURRENT_EXECUTABLE})
execute_process(COMMAND "${CURRENT_EXECUTABLE}" "-c"
"import re,xcbgen;print(re.compile('/xcbgen/__init__.py.*').sub('',xcbgen.__file__))"
RESULT_VARIABLE _xcbgen_status
OUTPUT_VARIABLE _xcbgen_location
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
# When a shell script returns successfully its return code is 0
if(_xcbgen_status EQUAL 0)
set(PYTHON_XCBGEN "${_xcbgen_location}" CACHE STRING "Location of python module: xcbgen ")
message(STATUS "Found xcbgen in " ${PYTHON_XCBGEN})
break()
endif()
endforeach(CURRENT_EXECUTABLE)
if(NOT PYTHON_XCBGEN)
message(FATAL_ERROR "Missing required python module: xcbgen")
endif()
#
# Include XCB libs depending on what protos we build
#
if(NOT XCB_PROTOS)
set(XCB_PROTOS
"bigreq"
"composite"
"damage"
"dpms"
"dri2"
"dri3"
"glx"
"present"
"randr"
"record"
"render"
"res"
"screensaver"
"shape"
"shm"
"sync"
"xc_misc"
"xevie"
"xf86dri"
"xfixes"
"xinerama"
"xinput"
"xkb"
"xprint"
"xproto"
"xselinux"
"xtest"
"xv"
"xvmc")
endif()
if("randr" IN_LIST XCB_PROTOS)
find_package(XCB REQUIRED RANDR)
set(XPP_INCLUDE_DIRS ${XPP_INCLUDE_DIRS} ${XCB_RANDR_INCLUDE_DIR})
set(XPP_LIBRARIES ${XPP_LIBRARIES} ${XCB_RANDR_LIBRARY})
endif()
if("render" IN_LIST XCB_PROTOS)
find_package(XCB REQUIRED RENDER)
set(XPP_INCLUDE_DIRS ${XPP_INCLUDE_DIRS} ${XCB_RENDER_INCLUDE_DIR})
set(XPP_LIBRARIES ${XPP_LIBRARIES} ${XCB_RENDER_LIBRARY})
endif()
if("damage" IN_LIST XCB_PROTOS)
find_package(XCB REQUIRED DAMAGE)
set(XPP_INCLUDE_DIRS ${XPP_INCLUDE_DIRS} ${XCB_DAMAGE_INCLUDE_DIR})
set(XPP_LIBRARIES ${XPP_LIBRARIES} ${XCB_DAMAGE_LIBRARY})
endif()
if("sync" IN_LIST XCB_PROTOS)
find_package(XCB REQUIRED SYNC)
set(XPP_INCLUDE_DIRS ${XPP_INCLUDE_DIRS} ${XCB_SYNC_INCLUDE_DIR})
set(XPP_LIBRARIES ${XPP_LIBRARIES} ${XCB_SYNC_LIBRARY})
endif()
if("composite" IN_LIST XCB_PROTOS)
find_package(XCB REQUIRED COMPOSITE)
set(XPP_INCLUDE_DIRS ${XPP_INCLUDE_DIRS} ${XCB_COMPOSITE_INCLUDE_DIR})
set(XPP_LIBRARIES ${XPP_LIBRARIES} ${XCB_COMPOSITE_LIBRARY})
endif()
if("xkb" IN_LIST XCB_PROTOS)
find_package(XCB REQUIRED XKB)
set(XPP_INCLUDE_DIRS ${XPP_INCLUDE_DIRS} ${XCB_XKB_INCLUDE_DIR})
set(XPP_LIBRARIES ${XPP_LIBRARIES} ${XCB_XKB_LIBRARY})
endif()
set(PROTO_LIST)
file(GLOB PROTO_LIST_RAW RELATIVE ${XCBPROTO_XCBINCLUDEDIR} ${XCBPROTO_XCBINCLUDEDIR}/*.xml)
#
# Filter glob
#
foreach(PROTO_RAW ${PROTO_LIST_RAW})
string(REGEX REPLACE "(^xf86vidmode.xml|^ge.xml|.xml)\$" "" PROTO ${PROTO_RAW})
if(PROTO AND "${PROTO}" IN_LIST XCB_PROTOS)
message(STATUS "${PROJECT_NAME}: including xcb proto ${PROTO_RAW}")
set(PROTO_LIST ${PROTO_LIST} ${PROTO})
endif()
endforeach(PROTO_RAW)
#
# Add commands
#
set(PROTO_HEADER_DIR "${GEN_SRC}/include/xpp/proto")
file(MAKE_DIRECTORY ${PROTO_HEADER_DIR})
set(PROTO_HEADER_FILES "")
foreach(PROTO ${PROTO_LIST})
string(REGEX REPLACE "proto\$" "" PROTO_OUTPUT ${PROTO})
set(OUTPUT_FILE ${PROTO_HEADER_DIR}/${PROTO_OUTPUT}.hpp)
add_custom_command(
OUTPUT ${OUTPUT_FILE}
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/generators/cpp_client.py -p "${PYTHON_XCBGEN}"
${XCBPROTO_XCBINCLUDEDIR}/${PROTO}.xml > ${OUTPUT_FILE})
list(APPEND PROTO_HEADER_FILES ${OUTPUT_FILE})
endforeach(PROTO)
#
# Create project lib and commands
#
file(GLOB_RECURSE HEADER_FILES ${PROJECT_SOURCE_DIR}/include/*.hpp)
add_library(${PROJECT_NAME} STATIC ${HEADER_FILES} ${PROTO_HEADER_FILES})
target_include_directories(${PROJECT_NAME} PUBLIC ${XPP_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${XPP_LIBRARIES})
target_compile_options(${PROJECT_NAME} PRIVATE -std=c++14 -Wall -Wpedantic)
target_compile_options(${PROJECT_NAME} PRIVATE $<$<CONFIG:Debug>:-g3 -DDEBUG>)
target_compile_options(${PROJECT_NAME} PRIVATE $<$<CONFIG:Release>:-O3 -Wno-unused-variable>)
target_compile_options(${PROJECT_NAME} PUBLIC ${XCB_DEFINITIONS})
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
#
# Export lists to the parent scope if there are any
#
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
if(HAS_PARENT)
set(XPP_INCLUDE_DIRS ${XPP_INCLUDE_DIRS} PARENT_SCOPE)
set(XPP_LIBRARIES ${PROJECT_NAME} PARENT_SCOPE)
endif()