-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
185 lines (159 loc) · 6.52 KB
/
Copy pathCMakeLists.txt
File metadata and controls
185 lines (159 loc) · 6.52 KB
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
179
180
181
182
183
184
185
cmake_minimum_required(VERSION 3.14) # 3.14 for FetchContent
project(totalmixer_cpp CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# --- Dependency Check (Arch Linux) ---
find_package(X11)
find_package(OpenGL REQUIRED)
find_package(Threads REQUIRED)
if (NOT X11_FOUND)
message(FATAL_ERROR "\n\nError: X11 libraries not found.\n\nTo install on Arch Linux:\n sudo pacman -S libx11 libxrandr libxinerama libxcursor libxi\n\n")
endif()
find_library(X11_RANDR_LIB Xrandr)
find_library(X11_INERAMA_LIB Xinerama)
find_library(X11_CURSOR_LIB Xcursor)
find_library(X11_XI_LIB Xi)
if (NOT (X11_RANDR_LIB AND X11_INERAMA_LIB AND X11_CURSOR_LIB AND X11_XI_LIB))
message(FATAL_ERROR "\n\nError: One or more X11 extension libraries not found.\n\nTo install on Arch Linux:\n sudo pacman -S libxrandr libxinerama libxcursor libxi\n\n")
endif()
# --- FetchContent Dependencies ---
include(FetchContent)
# 1. GLFW
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw.git
GIT_TAG 3.4
)
FetchContent_MakeAvailable(glfw)
# 2. Dear ImGui
FetchContent_Declare(
imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG docking # Using docking branch is recommended for modern apps, or master
)
FetchContent_MakeAvailable(imgui)
# Define ImGui Library Target manually since it's just source files
# We include Core + Backends (GLFW + OpenGL3)
set(IMGUI_DIR ${imgui_SOURCE_DIR})
add_library(imgui STATIC
${IMGUI_DIR}/imgui.cpp
${IMGUI_DIR}/imgui_draw.cpp
${IMGUI_DIR}/imgui_tables.cpp
${IMGUI_DIR}/imgui_widgets.cpp
${IMGUI_DIR}/imgui_demo.cpp
${IMGUI_DIR}/misc/cpp/imgui_stdlib.cpp
${IMGUI_DIR}/backends/imgui_impl_glfw.cpp
${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp
)
target_include_directories(imgui PUBLIC
${IMGUI_DIR}
${IMGUI_DIR}/backends
)
target_link_libraries(imgui PUBLIC glfw OpenGL::GL)
# --- ALSA Check ---
find_package(ALSA)
if (NOT ALSA_FOUND)
message(FATAL_ERROR "\n\nError: libasound (ALSA library) not found.\n\nTo install on Arch Linux:\n sudo pacman -S alsa-lib\n\n")
endif()
# --- libsystemd Check ---
find_package(PkgConfig REQUIRED)
pkg_check_modules(SYSTEMD REQUIRED libsystemd)
include_directories(${SYSTEMD_INCLUDE_DIRS})
# --- liblo (OSC) Check ---
pkg_check_modules(LIBLO REQUIRED liblo)
include_directories(${LIBLO_INCLUDE_DIRS})
# --- Targets ---
# 0. Mixer Engine (GUI-free core: ALSA + OSC + mixer domain logic).
# Deliberately links NO ImGui/GLFW/OpenGL so it can back a headless daemon.
add_library(mixer_engine STATIC
src/mixer_engine.cpp
src/alsa_core.cpp
src/osc_server.cpp
src/config_manager.cpp
src/service_checker.cpp
)
target_include_directories(mixer_engine PUBLIC src ${LIBLO_INCLUDE_DIRS} ${SYSTEMD_INCLUDE_DIRS})
target_link_libraries(mixer_engine PUBLIC ${ALSA_LIBRARIES} ${SYSTEMD_LIBRARIES} ${LIBLO_LIBRARIES})
# 1. GUI App (thin frontend over mixer_engine; all mixer logic lives in the engine).
add_executable(totalmixer_gui
src/gui_main.cpp
src/gui_app.cpp
src/bridge_process.cpp
)
target_include_directories(totalmixer_gui PRIVATE src ${LIBLO_INCLUDE_DIRS})
target_link_libraries(totalmixer_gui PRIVATE imgui mixer_engine glfw)
# 2. Headless multicall binary: `totalmixer <command>` (daemon, info). Frontend over
# mixer_engine only, so it links no ImGui/GLFW/OpenGL/X11 and runs on a headless server.
# NOTE: do NOT add src/alsa_core.cpp here; it is already compiled into mixer_engine, and
# listing it again would duplicate the AlsaCore symbols.
add_executable(totalmixer
src/main_multicall.cpp
src/daemon_run.cpp
src/info_run.cpp
)
target_include_directories(totalmixer PRIVATE src)
target_link_libraries(totalmixer PRIVATE mixer_engine Threads::Threads)
# Install Targets
install(TARGETS totalmixer_gui totalmixer
RUNTIME DESTINATION bin
)
# systemd user unit for the daemon. Shipped disabled (opt-in); the user enables it with
# `systemctl --user enable --now totalmixer-daemon.service`.
install(FILES packaging/totalmixer-daemon.service
DESTINATION lib/systemd/user
)
# --- Optional: build the Rust web-remote bridge alongside (dev convenience) ---
# OFF by default. Distribution packages do NOT use this; end users get the bridge via a
# package dependency (see PKGBUILD). This flag is purely for building both from source in a
# side-by-side checkout. Source defaults to the sibling repo; override with -DBRIDGE_SOURCE_DIR.
option(WITH_BRIDGE "Also build the Rust web-remote bridge from source (dev convenience)" OFF)
if(WITH_BRIDGE)
set(BRIDGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../linux-totalmix-web-remote"
CACHE PATH "Path to the linux-totalmix-web-remote source tree")
find_program(CARGO_EXECUTABLE cargo)
if(NOT CARGO_EXECUTABLE)
message(FATAL_ERROR "WITH_BRIDGE=ON requires cargo (Rust). Install rust/cargo, or leave WITH_BRIDGE off and get the bridge from its own package.")
endif()
if(NOT EXISTS "${BRIDGE_SOURCE_DIR}/Cargo.toml")
message(FATAL_ERROR "WITH_BRIDGE=ON: no Cargo.toml at '${BRIDGE_SOURCE_DIR}'. Point -DBRIDGE_SOURCE_DIR=<path> at the linux-totalmix-web-remote checkout.")
endif()
include(ExternalProject)
set(BRIDGE_TARGET_DIR "${CMAKE_CURRENT_BINARY_DIR}/bridge-build")
ExternalProject_Add(bridge
SOURCE_DIR "${BRIDGE_SOURCE_DIR}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ${CARGO_EXECUTABLE} build --release
--manifest-path "${BRIDGE_SOURCE_DIR}/Cargo.toml"
--target-dir "${BRIDGE_TARGET_DIR}"
INSTALL_COMMAND ""
BUILD_ALWAYS 1
USES_TERMINAL_BUILD 1
)
# Cargo writes the release binary here; install it next to totalmixer.
install(PROGRAMS "${BRIDGE_TARGET_DIR}/release/linux-totalmix-web-remote"
DESTINATION bin
)
message(STATUS "WITH_BRIDGE=ON: building bridge from ${BRIDGE_SOURCE_DIR}")
endif()
# Install Desktop Entry and Icon
install(FILES totalmixer.desktop
DESTINATION share/applications
)
install(FILES icon.png
DESTINATION share/icons/hicolor/512x512/apps
RENAME totalmixer.png
)
# Uninstall Target
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY
)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)
endif()