forked from pekwm/pekwm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
197 lines (162 loc) · 5.96 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
cmake_minimum_required(VERSION 3.5)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake/Modules/")
project(pekwm)
set(pekwm_VERSION_MAJOR 0)
set(pekwm_VERSION_MINOR 2)
set(pekwm_VERSION_PATCH 0)
set(pekwm_VERSION "${pekwm_VERSION_MAJOR}.${pekwm_VERSION_MINOR}.${pekwm_VERSION_PATCH}")
# Check for C++98
set(CMAKE_CXX_STANDARD 98)
include(CheckSymbolExists)
include(CheckCXXCompilerFlag)
include(CheckCXXSourceRuns)
include(CheckIncludeFile)
include(CheckIncludeFileCXX)
include(GNUInstallDirs)
# Look for dependencies
find_package(X11 REQUIRED)
check_include_file_cxx(limits PEKWM_HAVE_LIMITS)
if (NOT PEKWM_HAVE_LIMITS)
check_include_file(sys/limits.h PEKWM_HAVE_SYS_LIMITS_H)
endif (NOT PEKWM_HAVE_LIMITS)
check_include_file(stdint.h PEKWM_HAVE_STDINT_H)
check_include_file_cxx(locale PEKWM_HAVE_LOCALE)
if (NOT PEKWM_HAVE_LOCALE)
check_include_file(locale.h PEKWM_HAVE_LOCALE_H REQUIRED)
endif (NOT PEKWM_HAVE_LOCALE)
check_function_exists(localtime_r PEKWM_HAVE_LOCALTIME_R REQUIRED)
# Add work-around for missing -std=c++98 flag when running the
# check_cxx_source_runs tests
set(orig_CMAKE_CXX_FLAGS ${CMAKE_CXX98_FLAGS})
set(CMAKE_CXX_FLAGS ${CMAKE_CXX98_STANDARD_COMPILE_OPTION})
check_cxx_source_runs("
#include <iostream>
#include <iomanip>
int main() { std::tm tm = {0}; std::cout << std::put_time(&tm, \"%S\"); }
" PEKWM_HAVE_PUT_TIME)
check_cxx_source_runs("
#include <iostream>
#include <string>
int main() { std::to_string(42); }
" PEKWM_HAVE_TO_STRING)
check_cxx_source_runs("
#include <string>
int main() { std::stoi(\"42\"); }
" PEKWM_HAVE_STOI)
check_cxx_source_runs("
#include <string>
int main() { std::stof(\"42.0\"); }
" PEKWM_HAVE_STOF)
set(CMAKE_CXX_FLAGS ${orig_CMAKE_CXX_FLAGS})
# Look for platform specific methods
check_function_exists(setenv PEKWM_HAVE_SETENV)
check_function_exists(unsetenv PEKWM_HAVE_UNSETENV)
check_function_exists(daemon PEKWM_HAVE_DAEMON)
check_function_exists(clock_gettime PEKWM_HAVE_CLOCK_GETTIME)
check_symbol_exists(timersub sys/time.h PEKWM_HAVE_TIMERSUB)
# Look for modern X11 functions
set(CMAKE_REQUIRED_INCLUDES ${X11_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${X11_LIBRARIES})
check_symbol_exists(Xutf8SetWMProperties X11/Xutil.h PEKWM_HAVE_XUTF8)
# Look for platform specific tools
find_program(SED gsed sed
PATHS /usr/sfw/bin /usr/pkg/bin /usr/local/bin /usr/bin /bin
NO_DEFAULT_PATH
REQUIRED)
find_program(SH sh
PATHS /usr/xpg4/bin /usr/pkg/bin /usr/local/bin /usr/bin /bin
NO_DEFAULT_PATH
REQUIRED)
find_program(AWK awk
PATHS /usr/xpg4/bin /usr/pkg/bin /usr/local/bin /usr/bin /bin
NO_DEFAULT_PATH
REQUIRED)
# Optons
option(ENABLE_SHAPE "include support for Xshape" ON)
option(ENABLE_XINERAMA "include support for Xinerama" ON)
option(ENABLE_RANDR "include support for Xrandr" ON)
option(ENABLE_XFT "include support for Xft fonts" ON)
option(ENABLE_IMAGE_JPEG "include support for JPEG images" ON)
option(ENABLE_IMAGE_PNG "include support for PNG images" ON)
option(ENABLE_IMAGE_XPM "include support for XPM images" ON)
option(PEDANTIC "turn on strict compile-time warnings" OFF)
option(TESTS "include tests" OFF)
if (ENABLE_XFT)
find_package(Freetype)
endif (ENABLE_XFT)
if (ENABLE_IMAGE_JPEG)
find_package(JPEG)
endif (ENABLE_IMAGE_JPEG)
if (ENABLE_IMAGE_PNG)
find_package(PNG)
endif (ENABLE_IMAGE_PNG)
# Compilation
if (ENABLE_SHAPE AND X11_Xshape_FOUND)
set(pekwm_FEATURES "${pekwm_FEATURES} XShape")
set(PEKWM_HAVE_SHAPE 1)
endif (ENABLE_SHAPE AND X11_Xshape_FOUND)
if (ENABLE_XINERAMA AND X11_Xinerama_FOUND)
set(pekwm_FEATURES "${pekwm_FEATURES} Xinerama")
set(PEKWM_HAVE_XINERAMA 1)
endif (ENABLE_XINERAMA AND X11_Xinerama_FOUND)
if (ENABLE_XFT AND X11_Xft_FOUND AND FREETYPE_FOUND)
set(pekwm_FEATURES "${pekwm_FEATURES} Xft")
set(PEKWM_HAVE_XFT 1)
endif (ENABLE_XFT AND X11_Xft_FOUND AND FREETYPE_FOUND)
if (ENABLE_IMAGE_JPEG AND JPEG_FOUND)
set(pekwm_FEATURES "${pekwm_FEATURES} image-jpeg")
set(PEKWM_HAVE_IMAGE_JPEG 1)
endif (ENABLE_IMAGE_JPEG AND JPEG_FOUND)
if (ENABLE_IMAGE_PNG AND PNG_FOUND)
set(pekwm_FEATURES "${pekwm_FEATURES} image-png")
set(PEKWM_HAVE_IMAGE_PNG 1)
endif (ENABLE_IMAGE_PNG AND PNG_FOUND)
if (ENABLE_IMAGE_XPM AND X11_Xpm_FOUND)
set(pekwm_FEATURES "${pekwm_FEATURES} image-xpm")
set(PEKWM_HAVE_IMAGE_XPM 1)
endif (ENABLE_IMAGE_XPM AND X11_Xpm_FOUND)
if (ENABLE_RANDR AND X11_Xrandr_FOUND)
set(pekwm_FEATURES "${pekwm_FEATURES} Xrandr")
set(PEKWM_HAVE_XRANDR 1)
endif (ENABLE_RANDR AND X11_Xrandr_FOUND)
if (CMAKE_BUILD_TYPE MATCHES Debug)
set(pekwm_FEATURES "${pekwm_FEATURES} debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
endif (CMAKE_BUILD_TYPE MATCHES Debug)
if (PEDANTIC)
set(pekwm_FEATURES "${pekwm_FEATURES} pedantic")
# -Werror cause the compiler fail with:
# Error: original is defined but not used.
# when throwing some exceptions
if (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -pedantic")
endif ()
check_cxx_compiler_flag("-Wno-variadic-macros" NO_VARIADIC_MACROS)
if (NO_VARIADIC_MACROS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-variadic-macros")
endif (NO_VARIADIC_MACROS)
endif (PEDANTIC)
# check after pedantic check, -Wall -Werror -pedantic will cause this
# to fail if missing/ignored
check_cxx_source_runs("
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored \"-Wdeprecated-declarations\"
int main() { return 0; }
" PEKWM_HAVE_GCC_DIAGNOSTICS_PUSH)
add_definitions(-DVERSION="${pekwm_VERSION}"
-DFEATURES="${pekwm_FEATURES}"
-DBINDIR="${CMAKE_INSTALL_PREFIX}/bin"
-DDATADIR="${CMAKE_INSTALL_PREFIX}/share"
-DSYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}/pekwm")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH True)
# Subdirectories
add_subdirectory(contrib)
add_subdirectory(data)
add_subdirectory(doc)
add_subdirectory(src)
if (TESTS)
enable_testing()
add_subdirectory(test)
endif (TESTS)