Browse Source

Added SLOP_OPENGL flag that makes OpenGL optional. (You shouldn't want this.)

naelstrof 6 years ago
parent
commit
e9bc4a7e22
2 changed files with 77 additions and 34 deletions
  1. 64
    34
      CMakeLists.txt
  2. 13
    0
      src/slop.cpp

+ 64
- 34
CMakeLists.txt View File

@@ -1,10 +1,19 @@
1 1
 cmake_minimum_required(VERSION 3.1.3)
2 2
 
3 3
 set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)")
4
+
4 5
 if ( NOT CMAKE_INSTALL_PREFIX )
5 6
     set(CMAKE_INSTALL_PREFIX "/usr")
6 7
 endif()
7 8
 
9
+# This should really never be disabled. The pure-X mode of slop is very expensive and buggy.
10
+# It also doesn't work on Wayland. Though if a system is never running a compositor, or
11
+# doesn't have OpenGL, this could remove some linking dependencies I suppose.
12
+set( SLOP_OPENGL TRUE CACHE BOOL "To enable or disable OpenGL support." )
13
+if ( SLOP_OPENGL )
14
+  add_definitions(-DSLOP_OPENGL="True")
15
+endif()
16
+
8 17
 project(slop)
9 18
 
10 19
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/")
@@ -21,24 +30,36 @@ endif()
21 30
 
22 31
 include_directories("${PROJECT_BINARY_DIR}")
23 32
 
24
-add_definitions(-DSLOP_VERSION="v7.3.48")
33
+add_definitions(-DSLOP_VERSION="v7.3.49")
25 34
 
26 35
 # The names have to be unique unfortunately.
27 36
 set(EXECUTABLE_NAME "slop")
28 37
 set(LIBRARY_NAME "slopy")
29 38
 
30
-add_library(${LIBRARY_NAME} SHARED  src/mouse.cpp
31
-                                    src/keyboard.cpp
32
-                                    src/x.cpp
33
-                                    src/slopstates.cpp
34
-                                    src/framebuffer.cpp
35
-                                    src/resource.cpp
36
-                                    src/shader.cpp
37
-                                    src/window.cpp
38
-                                    src/slop.cpp
39
-                                    src/rectangle.cpp
40
-                                    src/xshaperectangle.cpp
41
-                                    src/glrectangle.cpp)
39
+
40
+if ( SLOP_OPENGL )
41
+  add_library(${LIBRARY_NAME} SHARED  src/mouse.cpp
42
+                                      src/keyboard.cpp
43
+                                      src/x.cpp
44
+                                      src/slopstates.cpp
45
+                                      src/resource.cpp
46
+                                      src/slop.cpp
47
+                                      src/rectangle.cpp
48
+                                      src/xshaperectangle.cpp
49
+                                      src/shader.cpp
50
+                                      src/window.cpp
51
+                                      src/framebuffer.cpp
52
+                                      src/glrectangle.cpp)
53
+else()
54
+  add_library(${LIBRARY_NAME} SHARED  src/mouse.cpp
55
+                                      src/keyboard.cpp
56
+                                      src/x.cpp
57
+                                      src/slopstates.cpp
58
+                                      src/resource.cpp
59
+                                      src/slop.cpp
60
+                                      src/rectangle.cpp
61
+                                      src/xshaperectangle.cpp)
62
+endif()
42 63
 
43 64
 set_property(TARGET ${LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
44 65
 set_property(TARGET ${LIBRARY_NAME} PROPERTY CXX_STANDARD 11)
@@ -50,42 +71,51 @@ set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD 11)
50 71
 
51 72
 set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/modules" )
52 73
 
53
-find_package(GLEW REQUIRED)
54 74
 find_package(GLM REQUIRED)
55 75
 find_package(X11 REQUIRED)
56 76
 find_package(XExt REQUIRED)
57
-find_package(GLX REQUIRED)
58
-find_package(OpenGL REQUIRED)
59
-find_package(XRender REQUIRED)
60
-# Ahhhh, finally this eliminates the segfault on preload.
61
-find_package(Threads REQUIRED)
77
+
78
+if ( SLOP_OPENGL )
79
+  find_package(GLEW REQUIRED)
80
+  find_package(OpenGL REQUIRED)
81
+  find_package(GLX REQUIRED)
82
+  find_package(XRender REQUIRED)
83
+  # Ahhhh, finally this eliminates the segfault on preload.
84
+  find_package(Threads REQUIRED)
85
+endif()
62 86
 
63 87
 include_directories(${X11_INCLUDE_DIR}
64
-                    ${GLEW_INCLUDE_DIR}
65 88
                     ${GLM_INCLUDE_DIR}
66
-                    ${XEXT_INCLUDE_DIR}
67
-                    ${GLX_INCLUDE_DIR}
68
-                    ${XRENDER_INCLUDE_DIR}
69
-                    ${OPENGL_INCLUDE_DIR})
89
+                    ${GLX_INCLUDE_DIR})
70 90
 
71 91
 target_link_libraries(${LIBRARY_NAME} ${X11_LIBRARIES}
72
-                                      ${CMAKE_THREAD_LIBS_INIT} 
73 92
                                       ${GLM_LIBRARIES}
74
-                                      ${OPENGL_LIBRARIES}
75
-                                      ${GLX_LIBRARY}
76
-                                      ${XRENDER_LIBRARY}
77
-                                      ${XEXT_LIBRARIES}
78
-                                      ${GLEW_LIBRARIES})
93
+                                      ${XEXT_LIBRARIES})
94
+
95
+if ( SLOP_OPENGL )
96
+  include_directories( ${XEXT_INCLUDE_DIR}
97
+                       ${GLEW_INCLUDE_DIR}
98
+                       ${XRENDER_INCLUDE_DIR}
99
+                       ${OPENGL_INCLUDE_DIR} )
100
+  target_link_libraries(${LIBRARY_NAME} ${OPENGL_LIBRARIES}
101
+                                        ${XRENDER_LIBRARY}
102
+                                        ${CMAKE_THREAD_LIBS_INIT} 
103
+                                        ${GLX_LIBRARY}
104
+                                        ${GLEW_LIBRARIES})
105
+endif()
79 106
 
80 107
 target_link_libraries(${EXECUTABLE_NAME} ${LIBRARY_NAME} )
81 108
 
82
-find_package(ICU COMPONENTS uc)
83
-set( SLOP_UNICODE TRUE CACHE BOOL "To enable or disable unicode support." )
84
-if ( SLOP_UNICODE AND ICU_FOUND )
85
-    # ICU is required for old nvidia drivers to work for whatever reason.
109
+if( CMAKE<3.7 )
110
+  message( WARNING "CMake version is below 3.7, CMake version >= 3.7 is required for unicode support." )
111
+else()
112
+  find_package(ICU COMPONENTS uc)
113
+  set( SLOP_UNICODE TRUE CACHE BOOL "To enable or disable unicode support." )
114
+  if ( SLOP_UNICODE AND ICU_FOUND )
86 115
     add_definitions(-DCXXOPTS_USE_UNICODE)
87 116
     include_directories( ${ICU_INCLUDE_DIR} )
88 117
     target_link_libraries(${EXECUTABLE_NAME} ${ICU_UC_LIBRARIES} )
118
+  endif()
89 119
 endif()
90 120
 
91 121
 install( TARGETS ${EXECUTABLE_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" )

+ 13
- 0
src/slop.cpp View File

@@ -1,5 +1,7 @@
1
+#ifdef SLOP_OPENGL
1 2
 #include <GL/glew.h>
2 3
 #include <GL/gl.h>
4
+#endif
3 5
 
4 6
 #include <chrono>
5 7
 #include <thread>
@@ -13,10 +15,13 @@
13 15
 #include "resource.hpp"
14 16
 #include "keyboard.hpp"
15 17
 
18
+#ifdef SLOP_OPENGL
16 19
 #include "window.hpp"
17 20
 #include "shader.hpp"
18 21
 #include "framebuffer.hpp"
19 22
 #include "glrectangle.hpp"
23
+#endif
24
+
20 25
 #include "xshaperectangle.hpp"
21 26
 #include "slop.hpp"
22 27
 
@@ -27,7 +32,9 @@ Mouse* mouse;
27 32
 Keyboard* keyboard;
28 33
 Resource* resource;
29 34
 
35
+#ifdef SLOP_OPENGL
30 36
 SlopSelection GLSlopSelect( slop::SlopOptions* options, slop::SlopWindow* window );
37
+#endif
31 38
 SlopSelection XShapeSlopSelect( slop::SlopOptions* options );
32 39
 
33 40
 static int TmpXError(Display * d, XErrorEvent * ev) {
@@ -106,6 +113,7 @@ slop::SlopSelection slop::SlopSelect( slop::SlopOptions* options ) {
106 113
         keyboard = new Keyboard( x11 );
107 114
         XSetErrorHandler(ph);
108 115
     }
116
+#ifdef SLOP_OPENGL
109 117
     bool success = false;
110 118
     std::string errorstring = "";
111 119
     SlopWindow* window;
@@ -138,10 +146,13 @@ slop::SlopSelection slop::SlopSelect( slop::SlopOptions* options ) {
138 146
                 std::cerr << errorstring;
139 147
             }
140 148
         }
149
+#endif // SLOP_OPENGL
141 150
         returnval = slop::XShapeSlopSelect( options );
151
+#ifdef SLOP_OPENGL
142 152
     } else {
143 153
         returnval = slop::GLSlopSelect( options, window );
144 154
     }
155
+#endif
145 156
     delete x11;
146 157
     delete slop::resource;
147 158
     if ( deleteOptions ) {
@@ -209,6 +220,7 @@ slop::SlopSelection slop::XShapeSlopSelect( slop::SlopOptions* options ) {
209 220
     return slop::SlopSelection( output.x, output.y, output.z, output.w, selectedWindow, cancelled );
210 221
 }
211 222
 
223
+#ifdef SLOP_OPENGL
212 224
 slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, SlopWindow* window ) {
213 225
     bool cancelled = false;
214 226
     slop::mouse = new slop::Mouse( x11, options->nodecorations, window->window );
@@ -342,6 +354,7 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, SlopWindow*
342 354
     // Finally return the data.
343 355
     return slop::SlopSelection( output.x, output.y, output.z, output.w, selectedWindow, cancelled );
344 356
 }
357
+#endif
345 358
 
346 359
 extern "C" struct slop_options slop_options_default() {
347 360
     struct slop_options options;