@@ -26,45 +26,139 @@ if(UNIX AND NOT APPLE)
2626 find_package (OpenGL REQUIRED )
2727endif ()
2828
29+ option (USE_SYSTEM_LIBS "Use system-installed libraries instead of the bundled versions" $ENV{USE_SYSTEM_LIBS} )
30+
31+ option (USE_SYSTEM_OPENAL "Use system-installed OpenAL-Soft instead of the bundled version" $ENV{USE_SYSTEM_OPENAL} )
32+ option (USE_SYSTEM_BULLET "Use system-installed Bullet3 instead of the bundled version" $ENV{USE_SYSTEM_BULLET} )
33+ option (USE_SYSTEM_GLFW "Use system-installed GLFW instead of the bundled version" $ENV{USE_SYSTEM_GLFW} )
34+
35+ if (USE_SYSTEM_LIBS)
36+ set (USE_SYSTEM_OPENAL ON CACHE BOOL "" FORCE )
37+ set (USE_SYSTEM_BULLET ON CACHE BOOL "" FORCE )
38+ set (USE_SYSTEM_GLFW ON CACHE BOOL "" FORCE )
39+ endif ()
40+
2941# ---- Vendor Libraries ----
3042# ---- GLFW ----
31- set (GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE )
32- set (GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE )
33- set (GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE )
34- set (GLFW_INSTALL OFF CACHE BOOL "" FORCE )
35- set (GLFW_USE_HYBRID_HPG ON CACHE BOOL "" FORCE )
36-
37- if (UNIX AND NOT APPLE AND NOT DEFINED GLFW_BUILD_WAYLAND)
38- find_program (GLFW_WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner )
39- find_package (PkgConfig QUIET )
40-
41- if (PkgConfig_FOUND)
42- pkg_check_modules (GLFW_WAYLAND_DEPS QUIET
43- wayland-client
44- wayland-cursor
45- wayland-egl
46- xkbcommon
47- )
48- endif ()
43+ set (USE_VENDOR_GLFW ON CACHE BOOL "" FORCE )
4944
50- if (GLFW_WAYLAND_SCANNER_EXECUTABLE AND GLFW_WAYLAND_DEPS_FOUND)
51- set (GLFW_BUILD_WAYLAND ON CACHE BOOL "Build support for Wayland" )
45+ if (USE_SYSTEM_GLFW)
46+ find_package (glfw3 QUIET )
47+ if (glfw3_FOUND)
48+ message (STATUS "Using system-installed GLFW: ${glfw3_VERSION} " )
49+ set (USE_VENDOR_GLFW OFF CACHE BOOL "" FORCE )
5250 else ()
53- set (GLFW_BUILD_WAYLAND OFF CACHE BOOL "Build support for Wayland" )
51+ message (STATUS "Using bundled GLFW" )
52+ endif ()
53+ endif ()
54+
55+ if (USE_VENDOR_GLFW)
56+ set (GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE )
57+ set (GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE )
58+ set (GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE )
59+ set (GLFW_INSTALL OFF CACHE BOOL "" FORCE )
60+ set (GLFW_USE_HYBRID_HPG ON CACHE BOOL "" FORCE )
61+
62+ if (UNIX AND NOT APPLE AND NOT DEFINED GLFW_BUILD_WAYLAND)
63+ find_program (GLFW_WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner )
64+ find_package (PkgConfig QUIET )
65+
66+ if (PkgConfig_FOUND)
67+ pkg_check_modules (GLFW_WAYLAND_DEPS QUIET
68+ wayland-client
69+ wayland-cursor
70+ wayland-egl
71+ xkbcommon
72+ )
73+ endif ()
5474
55- if (NOT GLFW_WAYLAND_SCANNER_EXECUTABLE)
56- set (_glfw_wayland_reason "missing wayland-scanner" )
57- elseif (NOT PkgConfig_FOUND)
58- set (_glfw_wayland_reason "pkg-config is unavailable" )
75+ if (GLFW_WAYLAND_SCANNER_EXECUTABLE AND GLFW_WAYLAND_DEPS_FOUND)
76+ set (GLFW_BUILD_WAYLAND ON CACHE BOOL "Build support for Wayland" )
5977 else ()
60- set (_glfw_wayland_reason "missing Wayland development packages" )
78+ set (GLFW_BUILD_WAYLAND OFF CACHE BOOL "Build support for Wayland" )
79+
80+ if (NOT GLFW_WAYLAND_SCANNER_EXECUTABLE)
81+ set (_glfw_wayland_reason "missing wayland-scanner" )
82+ elseif (NOT PkgConfig_FOUND)
83+ set (_glfw_wayland_reason "pkg-config is unavailable" )
84+ else ()
85+ set (_glfw_wayland_reason "missing Wayland development packages" )
86+ endif ()
87+
88+ message (STATUS "Disabling GLFW Wayland (${_glfw_wayland_reason} )" )
6189 endif ()
90+ endif ()
91+ add_subdirectory (vendor/glfw )
92+ endif ()
93+
6294
63- message (STATUS "Disabling GLFW Wayland (${_glfw_wayland_reason} )" )
95+ # ---- BULLET3 ----
96+ set (USE_VENDOR_BULLET ON CACHE BOOL "" FORCE )
97+ if (USE_SYSTEM_BULLET)
98+ find_package (Bullet QUIET )
99+ if (Bullet_FOUND)
100+ message (STATUS "Using system-installed Bullet: ${Bullet_VERSION} " )
101+ set (USE_BUILD_BULLET OFF CACHE BOOL "" FORCE )
102+ else ()
103+ message (STATUS "Using bundled Bullet3" )
64104 endif ()
65105endif ()
66106
67- add_subdirectory (vendor/glfw )
107+ if (USE_VENDOR_BULLET)
108+ set (BUILD_CPU_DEMOS OFF CACHE BOOL "" FORCE )
109+ set (BUILD_OPENGL3_DEMOS OFF CACHE BOOL "" FORCE )
110+ set (BUILD_BULLET2_DEMOS OFF CACHE BOOL "" FORCE )
111+ set (BUILD_EXTRAS OFF CACHE BOOL "" FORCE )
112+ set (BUILD_UNIT_TESTS OFF CACHE BOOL "" FORCE )
113+ set (BUILD_BULLET3 ON CACHE BOOL "" FORCE )
114+ add_subdirectory (vendor/bullet3 )
115+ endif ()
116+
117+ # --- OpenAL-Soft ----
118+ set (USE_VENDOR_OPENAL ON CACHE BOOL "" FORCE )
119+
120+ if (USE_SYSTEM_OPENAL)
121+ find_package (OpenAL QUIET )
122+ if (OpenAL_FOUND)
123+ message (STATUS "Using system-installed OpenAL: ${OpenAL_VERSION} " )
124+ set (USE_VENDOR_OPENAL OFF CACHE BOOL "" FORCE )
125+ else ()
126+ message (STATUS "Using bundled OpenAL-Soft" )
127+ endif ()
128+ endif ()
129+
130+ if (USE_VENDOR_OPENAL)
131+ set (ALSOFT_ENABLE_MODULES OFF CACHE BOOL "" FORCE )
132+ set (LIBTYPE STATIC CACHE STRING "" FORCE )
133+ set (ALSOFT_EMBED_HRTF_DATA ON CACHE BOOL "" FORCE )
134+ set (ALSOFT_EAX ON CACHE BOOL "" FORCE )
135+ set (ALSOFT_EXAMPLES OFF CACHE BOOL "" FORCE )
136+ set (ALSOFT_TESTS OFF CACHE BOOL "" FORCE )
137+ set (ALSOFT_UTILS OFF CACHE BOOL "" FORCE )
138+ set (ALSOFT_INSTALL_CONFIG OFF CACHE BOOL "" FORCE )
139+ set (ALSOFT_INSTALL OFF CACHE BOOL "" FORCE )
140+ if (WIN32 )
141+ set (ALSOFT_BACKEND_WASAPI ON CACHE BOOL "" FORCE )
142+ set (ALSOFT_BACKEND_DSOUND OFF CACHE BOOL "" FORCE )
143+ endif ()
144+ if (UNIX AND NOT APPLE )
145+ find_package (PkgConfig REQUIRED )
146+ pkg_check_modules (PIPEWIRE libpipewire-0.3>=0.3.23 QUIET )
147+ pkg_check_modules (PULSEAUDIO libpulse QUIET )
148+ pkg_check_modules (ALSA alsa QUIET )
149+ if (PIPEWIRE_FOUND)
150+ set (ALSOFT_BACKEND_PIPEWIRE ON CACHE BOOL "" FORCE )
151+ elseif (PULSEAUDIO_FOUND)
152+ set (ALSOFT_BACKEND_PULSEAUDIO ON CACHE BOOL "" FORCE )
153+ elseif (ALSA_FOUND)
154+ set (ALSOFT_BACKEND_ALSA ON CACHE BOOL "" FORCE )
155+ else ()
156+ message (FATAL_ERROR "No suitable audio backend found for OpenAL-Soft. Please install PipeWire, PulseAudio, or ALSA development packages." )
157+ endif ()
158+ endif ()
159+
160+ add_subdirectory (vendor/openal-soft )
161+ endif ()
68162
69163# ---- GLAD ----
70164add_library (glad STATIC
@@ -74,30 +168,6 @@ target_include_directories(glad
74168 PUBLIC vendor/glad/include
75169)
76170
77- # ---- BULLET3 ----
78- set (BUILD_CPU_DEMOS OFF CACHE BOOL "" FORCE )
79- set (BUILD_OPENGL3_DEMOS OFF CACHE BOOL "" FORCE )
80- set (BUILD_BULLET2_DEMOS OFF CACHE BOOL "" FORCE )
81- set (BUILD_EXTRAS OFF CACHE BOOL "" FORCE )
82- set (BUILD_UNIT_TESTS OFF CACHE BOOL "" FORCE )
83- set (BUILD_BULLET3 ON CACHE BOOL "" FORCE )
84- add_subdirectory (vendor/bullet3 )
85-
86- # --- OpenAL-Soft ----
87- set (ALSOFT_ENABLE_MODULES OFF CACHE BOOL "" FORCE )
88- set (LIBTYPE STATIC CACHE STRING "" FORCE )
89- set (ALSOFT_EMBED_HRTF_DATA ON CACHE BOOL "" FORCE )
90- set (ALSOFT_EAX ON CACHE BOOL "" FORCE )
91- set (ALSOFT_EXAMPLES OFF CACHE BOOL "" FORCE )
92- set (ALSOFT_TESTS OFF CACHE BOOL "" FORCE )
93- set (ALSOFT_UTILS OFF CACHE BOOL "" FORCE )
94- set (ALSOFT_INSTALL_CONFIG OFF CACHE BOOL "" FORCE )
95- set (ALSOFT_INSTALL OFF CACHE BOOL "" FORCE )
96- set (ALSOFT_BACKEND_WASAPI ON CACHE BOOL "" FORCE )
97- set (ALSOFT_BACKEND_DSOUND OFF CACHE BOOL "" FORCE )
98-
99- add_subdirectory (vendor/openal-soft )
100-
101171# ---- GLM (Header-only) ----
102172add_library (glm INTERFACE )
103173target_include_directories (glm
@@ -194,17 +264,27 @@ target_link_libraries(${PROJECT_NAME}
194264 BulletCollision
195265 BulletSoftBody
196266 LinearMath
197- OpenAL
198267)
199268
269+ if (USE_SYSTEM_OPENAL AND OpenAL_FOUND)
270+ target_link_libraries (${PROJECT_NAME }
271+ PRIVATE
272+ OpenAL::OpenAL
273+ )
274+ else ()
275+ target_link_libraries (${PROJECT_NAME }
276+ PRIVATE
277+ OpenAL
278+ )
279+ endif ()
280+
200281target_compile_definitions (${PROJECT_NAME }
201282 PRIVATE
202283 $<$<CONFIG :Debug >:COLLISION_DEBUG_DRAW >
203284)
204285
205286set_target_properties (${PROJECT_NAME } PROPERTIES
206- RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR } /bin
207- RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR } /bin
287+ RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR } /bin
208288)
209289
210290install (TARGETS ${PROJECT_NAME }
0 commit comments