-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
178 lines (135 loc) · 5.27 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
cmake_minimum_required(VERSION 3.1)
project(pixelflood)
include(CMakeDependentOption)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (ANDROID_NATIVE_API_LEVEL)
include(AndroidNdkModules)
android_ndk_import_module_native_app_glue()
find_library(log-lib log)
list(APPEND my_SOURCES android.cpp)
list(APPEND my_LIBRARIES ${log-lib} android EGL GLESv1_CM native_app_glue)
set(FREETYPE_SRC_DIR "" CACHE PATH "Path to freetype source")
if (FREETYPE_SRC_DIR)
add_subdirectory(${FREETYPE_SRC_DIR} freetype)
set(FREETYPE_INCLUDE_DIRS ${FREETYPE_SRC_DIR}/include)
set(FREETYPE_LIBRARIES freetype)
set(FREETYPE_FOUND ON)
endif()
set(NETWORK EPOLL)
else()
include(FindFreetype)
find_package(Threads REQUIRED)
find_package(OpenGL)
find_package(glfw3 3.1)
find_package(GLEW)
find_package(Boost COMPONENTS system)
find_path(ASIO_INCLUDE_DIR NAMES asio.hpp)
list(APPEND my_SOURCES main.cpp options.cpp options.hpp)
list(APPEND my_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
if (glfw3_FOUND)
list(APPEND DISPLAY_OPTIONS GLFW)
endif()
if ("${CMAKE_SYSTEM}" MATCHES "Linux")
list(APPEND DISPLAY_OPTIONS FBDEV)
list(APPEND NETWORK_OPTIONS EPOLL)
endif()
if (Boost_FOUND)
list(APPEND NETWORK_OPTIONS BOOST_ASIO)
endif()
if (NOT "${ASIO_INCLUDE_DIR}" MATCHES "ASIO_INCLUDE_DIR-NOTFOUND")
list(APPEND NETWORK_OPTIONS ASIO_STANDALONE)
endif()
list(GET DISPLAY_OPTIONS 0 DEFAULT_DISPLAY)
list(GET NETWORK_OPTIONS 0 DEFAULT_NETWORK)
set(DISPLAY ${DEFAULT_DISPLAY} CACHE STRING "Library to display buffer")
set_property(CACHE DISPLAY PROPERTY STRINGS ${DISPLAY_OPTIONS})
set(NETWORK ${DEFAULT_NETWORK} CACHE STRING "API to run server")
set_property(CACHE NETWORK PROPERTY STRINGS ${NETWORK_OPTIONS})
endif()
list(APPEND my_SOURCES canvas.hpp version.h)
cmake_dependent_option(USE_FREETYPE "Use FreeType to draw text" ON "FREETYPE_FOUND" OFF)
if (NETWORK MATCHES "BOOST_ASIO")
add_definitions(-DUSE_BOOST_ASIO)
list(APPEND my_INCLUDES ${Boost_INCLUDE_DIRS})
list(APPEND my_LIBRARIES ${Boost_LIBRARIES})
list(APPEND my_SOURCES network_asio.cpp network_asio.hpp)
endif()
if (NETWORK MATCHES "ASIO_STANDALONE")
list(APPEND my_INCLUDES ${ASIO_INCLUDE_DIR})
list(APPEND my_SOURCES network_asio.cpp network_asio.hpp)
endif()
if (NETWORK MATCHES "EPOLL")
set(USE_EPOLL ON)
add_definitions(-DUSE_NETWORK_EPOLL)
list(APPEND my_SOURCES network_epoll.cpp network_epoll.hpp)
endif()
cmake_dependent_option(USE_EDGE_TRIGGERED_EPOLL "Use edge triggered epoll" OFF "USE_EPOLL" OFF)
if (USE_EDGE_TRIGGERED_EPOLL)
add_definitions(-DUSE_EDGE_TRIGGERED_EPOLL)
endif()
cmake_dependent_option(USE_ONESHOT_EPOLL "Use oneshot epoll (required for multithreading)" ON "USE_EPOLL" OFF)
if (USE_ONESHOT_EPOLL)
add_definitions(-DUSE_ONESHOT_EPOLL)
endif()
if (DISPLAY MATCHES "GLFW")
set(USE_GLFW ON)
add_definitions(-DUSE_GLFW)
list(APPEND my_INCLUDES ${OPENGL_INCLUDE_DIR})
list(APPEND my_LIBRARIES ${OPENGL_gl_LIBRARY})
if ("${GLFW3_LIBRARY}" STREQUAL "")
list(APPEND my_LIBRARIES glfw)
else()
list(APPEND my_INCLUDES ${GLFW3_INCLUDE_DIR})
list(APPEND my_LIBRARIES ${GLFW3_LIBRARY})
endif()
list(APPEND my_SOURCES display_glfw.cpp display_glfw.hpp)
endif()
cmake_dependent_option(USE_GLEW "Use GLEW to load extension for zero copy" ON "USE_GLFW; GLEW_FOUND" OFF)
if (USE_GLEW)
add_definitions(-DUSE_GLEW)
list(APPEND my_INCLUDES ${GLEW_INCLUDE_DIR})
list(APPEND my_LIBRARIES ${GLEW_LIBRARIES})
endif()
if (DISPLAY MATCHES "FBDEV")
add_definitions(-DUSE_FBDEV)
list(APPEND my_SOURCES display_fbdev.cpp display_fbdev.hpp)
endif()
if (USE_FREETYPE)
# like https://github.com/wjakob/nanogui/blob/f9c3b7a/CMakeLists.txt
file(GLOB resources "${CMAKE_CURRENT_SOURCE_DIR}/*.ttf")
string (REGEX REPLACE "([^\\]|^);" "\\1," resources_string "${resources}")
string (REGEX REPLACE "[\\](.)" "\\1" resources_string "${resources_string}")
set(bin2c_cmdline
-DOUTPUT_C=resources.cpp
-DOUTPUT_H=resources.h
"-DINPUT_FILES=${resources_string}"
-P "${CMAKE_CURRENT_SOURCE_DIR}/bin2c.cmake")
add_custom_command(
OUTPUT resources.cpp resources.h
COMMAND ${CMAKE_COMMAND} ARGS ${bin2c_cmdline}
DEPENDS ${resources}
COMMENT "Running bin2c"
PRE_BUILD VERBATIM)
list(APPEND my_SOURCES resources.cpp)
list(APPEND my_INCLUDES ${CMAKE_CURRENT_BINARY_DIR})
add_definitions(-DUSE_FREETYPE)
list(APPEND my_INCLUDES ${FREETYPE_INCLUDE_DIRS})
list(APPEND my_LIBRARIES ${FREETYPE_LIBRARIES})
list(APPEND my_SOURCES text.cpp text.hpp)
endif()
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-implicit-fallthrough")
endif()
if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows") # no console window
set(my_LIBRARIES ${my_LIBRARIES} ws2_32 mswsock) # networking
endif()
include_directories(${my_INCLUDES})
if (ANDROID_NATIVE_API_LEVEL)
add_library(pixelflood SHARED ${my_SOURCES})
else()
add_executable(pixelflood ${my_SOURCES})
endif()
target_link_libraries(pixelflood ${my_LIBRARIES})