-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
151 lines (122 loc) · 4.26 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
cmake_minimum_required(VERSION 3.30)
project(Test)
set(TARGET_NAME asiotest)
# This is the name of the driver according to SteamVR
set(DRIVER_NAME "driver_${TARGET_NAME}")
file(GLOB_RECURSE CLIENT_SRC ${CMAKE_SOURCE_DIR}/src/*.cpp
${CMAKE_SOURCE_DIR}/src/*.hpp)
file(GLOB_RECURSE SERVER_SRC ${CMAKE_SOURCE_DIR}/src/*.cpp
${CMAKE_SOURCE_DIR}/src/*.hpp)
file(GLOB_RECURSE DRIVER_SRC
${CMAKE_SOURCE_DIR}/src/*.cpp
${CMAKE_SOURCE_DIR}/src/*.hpp
${CMAKE_SOURCE_DIR}/src/*.h
)
list(FILTER CLIENT_SRC EXCLUDE REGEX ${CMAKE_SOURCE_DIR}/src/server)
list(FILTER CLIENT_SRC EXCLUDE REGEX ${CMAKE_SOURCE_DIR}/src/driver)
list(FILTER DRIVER_SRC EXCLUDE REGEX ${CMAKE_SOURCE_DIR}/src/client)
list(FILTER DRIVER_SRC EXCLUDE REGEX ${CMAKE_SOURCE_DIR}/src/server)
set(THREADS_PREFER_PTHREAD_FLAD ON)
set(BUILD_SHARED ON)
find_package(Threads REQUIRED)
find_package(OpenGL REQUIRED)
find_package(X11 REQUIRED)
find_package(PNG REQUIRED)
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost REQUIRED system)
set(OPENVR_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/openvr)
# If not set, determine the platform architecture
if(NOT PLATFORM)
if(CMAKE_SIZEOF_VOID_P MATCHES 8)
set(PLATFORM 64)
else()
set(PLATFORM 32)
endif()
endif()
message(STATUS "Compilation set for ${PLATFORM}bits architectures.")
# OpenVR compatibility checking
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
add_definitions(-DLINUX -DPOSIX)
set(ARCH_TARGET linux64)
if(${PLATFORM} MATCHES 32)
message(WARNING "OpenVR x86 binaries not provided on GNU/Linux.")
endif()
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_MACOSX_RPATH 0)
add_definitions(-DOSX -DPOSIX)
set(ARCH_TARGET osx32)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_definitions(-D_WIN32)
set(ARCH_TARGET win${PLATFORM})
# Binaries path for thirdparties are not generics so we try to guess their suffixes.
set(WINDOWS_PATH_SUFFIXES win${PLATFORM} Win${PLATFORM} x${PLATFORM})
endif()
find_library(OPENVR_LIBRARIES
NAMES
openvr_api
PATHS
${OPENVR_LIB_DIR}/bin
${OPENVR_LIB_DIR}/lib
PATH_SUFFIXES
osx${PLATFORM}
linux${PLATFORM}
win${PLATFORM}
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
set(OPENVR_INCLUDE_DIR ${OPENVR_LIB_DIR}/headers)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(USED_LIBS
Threads::Threads
OpenGL::OpenGL
OpenGL::GL
OpenGL::GLX
${X11_LIBRARIES}
PNG::PNG
${Boost_LIBRARIES}
)
# ---------------------------- client --------------------------------
add_executable(client ${CLIENT_SRC})
target_include_directories(client PUBLIC
"${CMAKE_CURRENT_LIST_DIR}/olcPixelGameEngine/"
"${CMAKE_CURRENT_LIST_DIR}/olcPixelGameEngine/utilities/"
"${CMAKE_CURRENT_LIST_DIR}/olcPixelGameEngine/extensions/"
"${CMAKE_SOURCE_DIR}/src/common"
${PNG_INCLUDE_DIR}
)
target_link_libraries(client PUBLIC ${USED_LIBS})
# target_compile_options(client PRIVATE "-Werror" "-Wall" "-Wextra")
# ---------------------------- driver --------------------------------
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/output)
add_library(${DRIVER_NAME} SHARED ${DRIVER_SRC})
# This is so we can build directly to "<binary_dir>/<target_name>/<platform>/<arch>/<driver_name>.<dll/so>"
set_target_properties(${DRIVER_NAME} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}/bin/${ARCH_TARGET}
LIBRARY_OUTPUT_DIRECTORY
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}/bin/${ARCH_TARGET}
RUNTIME_OUTPUT_DIRECTORY
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}/bin/${ARCH_TARGET}
)
set_target_properties(${DRIVER_NAME} PROPERTIES PREFIX "")
target_include_directories(${DRIVER_NAME} PUBLIC
"${CMAKE_CURRENT_LIST_DIR}/olcPixelGameEngine/"
"${CMAKE_CURRENT_LIST_DIR}/olcPixelGameEngine/utilities/"
"${CMAKE_CURRENT_LIST_DIR}/olcPixelGameEngine/extensions/"
"${CMAKE_SOURCE_DIR}/src/common"
${PNG_INCLUDE_DIR}
${OPENVR_INCLUDE_DIR}
)
target_link_libraries(${DRIVER_NAME} PUBLIC
${OPENVR_LIBRARIES}
${USED_LIBS}
)
# target_compile_options(server PRIVATE "-Werror" "-Wall" "-Wextra")
# Copy driver assets to output folder
add_custom_command(
TARGET ${DRIVER_NAME}
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_NAME}
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}
)