-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
155 lines (110 loc) · 4.22 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
# Check versions
message(STATUS "CMake version: ${CMAKE_VERSION}")
cmake_minimum_required(VERSION 3.1)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Set the project name
set(PNAME VoxelRaycaster)
project(${PNAME})
# Set up variables, and find SFML
if (WIN32)
set(SFML_ROOT root CACHE STRING "User specified path")
set(SFML_INCLUDE_DIR ${SFML_ROOT}/include)
endif()
# You're probably going to need to change these paths
if (UNIX)
set(OpenCL_INCLUDE_DIR /usr/include/CL)
set(OpenCL_LIBRARY /usr/lib/x86_64-linux-gnu/libOpenCL.so.1)
endif (UNIX)
set(SFML_COMPONENTS graphics window system network audio)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
find_package(SFML 2.1 COMPONENTS ${SFML_COMPONENTS} REQUIRED)
message(STATUS "SFML found: ${SFML_FOUND}")
# Find OpenCL
find_package( OpenCL REQUIRED )
message(STATUS "OpenCL found: ${OPENCL_FOUND}")
# Find OpenGL
find_package( OpenGL REQUIRED)
message(STATUS "OpenGL found: ${OPENGL_FOUND}")
# Windows requires us to use GLEW to link the GL shit
if (WIN32)
# Find GLEW
find_package(GLEW REQUIRED)
message(STATUS "GLEW found: ${GLEW_FOUND}")
endif()
# beignet only supports EGL and not GLX for the cl_khr_gl_sharing extension
if (UNIX)
# Find X11
find_package(X11 REQUIRED)
message(STATUS "XSS found: ${X11_FOUND}")
# find_package(EGL REQUIRED)
#message(STATUS "EGL found: ${EGL_FOUND}")
endif (UNIX)
# Include the directories for the main program, GL, CL and SFML's headers
include_directories(${SFML_INCLUDE_DIR})
include_directories(${OpenCL_INCLUDE_DIRS})
include_directories(${OpenGL_INCLUDE_DIRS})
if (UNIX)
include_directories(${X11_INCLUDE_DIR})
# include_directories(${EGL_INCLUDE_DIRS})
endif()
include_directories(include)
# Glob all thr sources into their values
file(GLOB_RECURSE SOURCES "src/*.cpp")
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
file(GLOB_RECURSE KERNELS "kernels/*.cl")
file(GLOB_RECURSE SHADERS "shaders/*.vert" "shaders/*.tesc" "shaders/*.tese" "shaders/*.geom" "shaders/*.frag" "shaders/*.comp")
add_executable(${PNAME} ${SOURCES} ${HEADERS} ${KERNELS} ${SHADERS})
# Follow the sub directory structure to add sub-filters in VS
# Gotta do it one by one unfortunately
foreach (source IN ITEMS ${SOURCES})
if (IS_ABSOLUTE "${source}")
get_filename_component(filename ${source} DIRECTORY)
STRING(REGEX REPLACE "/" "\\\\" filename ${filename})
string(REGEX MATCHALL "src(.*)" substrings ${filename})
list(GET substrings 0 substring)
SOURCE_GROUP(${substring} FILES ${source})
endif()
endforeach()
foreach (source IN ITEMS ${HEADERS})
if (IS_ABSOLUTE "${source}")
get_filename_component(filename ${source} DIRECTORY)
STRING(REGEX REPLACE "/" "\\\\" filename ${filename})
string(REGEX MATCHALL "include(.*)" substrings ${filename})
list(GET substrings 0 substring)
SOURCE_GROUP(${substring} FILES ${source})
endif()
endforeach()
foreach (source IN ITEMS ${KERNELS})
if (IS_ABSOLUTE "${source}")
get_filename_component(filename ${source} DIRECTORY)
STRING(REGEX REPLACE "/" "\\\\" filename ${filename})
string(REGEX MATCHALL "kernels(.*)" substrings ${filename})
list(GET substrings 0 substring)
SOURCE_GROUP(${substring} FILES ${source})
endif()
endforeach()
foreach (source IN ITEMS ${SHADERS})
if (IS_ABSOLUTE "${source}")
get_filename_component(filename ${source} DIRECTORY)
STRING(REGEX REPLACE "/" "\\\\" filename ${filename})
string(REGEX MATCHALL "shaders(.*)" substrings ${filename})
list(GET substrings 0 substring)
SOURCE_GROUP(${substring} FILES ${source})
endif()
endforeach()
# Link CL, GL, and SFML
target_link_libraries (${PNAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
target_link_libraries (${PNAME} ${OpenCL_LIBRARY})
target_link_libraries (${PNAME} ${OPENGL_LIBRARIES})
if (UNIX)
target_link_libraries (${PNAME} ${X11_LIBRARIES})
# target_link_libraries (${PNAME} ${EGL_LIBRARIES})
endif()
if (WIN32)
target_link_libraries (${PNAME} ${GLEW_LIBRARIES})
endif()
if (NOT WIN32)
target_link_libraries (${PNAME} -lpthread)
endif()
# Setup to use C++14
set_property(TARGET ${PNAME} PROPERTY CXX_STANDARD 14)