Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for mingw toolchain in Windows #627

Merged
merged 6 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,22 @@ jobs:
run: nuget restore cava_win\cava_win.sln
- name: Run msbuild
run: msbuild /p:Configuration=Debug cava_win\cava_win.sln

build-mingw:
runs-on: windows-latest
strategy:
matrix:
msystem: [ucrt64, clang64]
defaults:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v4
- uses: msys2/setup-msys2@v2
with:
msystem: ${{matrix.msystem}}
pacboy: cc cmake fftw glew ninja SDL2
- name: Run cmake build
run: |
cmake -B bin
cmake --build bin
25 changes: 24 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ if (ANDROID)
target_include_directories(cavacore PRIVATE "${FFTW_DIR}/jni/fftw3/api/")
target_link_directories(cavacore PRIVATE "${FFTW_DIR}/obj/local/${CMAKE_ANDROID_ARCH_ABI}/")
target_link_libraries(cavacore fftw3)
elseif(WIN32)
find_package(FFTW3)
find_package(GLEW)
find_package(SDL2)
find_package(Threads)

add_executable(cava
cava.c
cavacore.c
config.c
input/common.c
input/winscap.c
output/sdl_cava.c
output/sdl_glsl.c
output/terminal_noncurses.c
output/raw.c
output/noritake.c
cava_win/cava/cava.rc
)

target_compile_definitions(cava PRIVATE SDL SDL_GSL NDEBUG)
target_include_directories(cava PRIVATE ${GLEW_INCLUDE_DIRS} ${SDL2_INCLUDE_DIRS})
target_link_libraries(cava PRIVATE pthread shlwapi fftw3 GLEW::GLEW SDL2::SDL2)
else()
add_library(cavacore STATIC cavacore.c)
endif()
endif()
71 changes: 39 additions & 32 deletions cava.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <stdio.h>
#include <stdlib.h>

#ifndef _MSC_VER
#ifndef _WIN32
#include <ctype.h>
#include <dirent.h>
#include <getopt.h>
Expand All @@ -25,14 +25,14 @@
#include <unistd.h>
#endif

#ifdef _MSC_VER
#ifdef _WIN32
#include "input/winscap.h"
#include <windows.h>
#define PATH_MAX 260
#define PACKAGE "cava"
#define VERSION "0.10.4"
#define _CRT_SECURE_NO_WARNINGS 1
#endif // _MSC_VER
#endif // _WIN32

#include <signal.h>
#include <string.h>
Expand Down Expand Up @@ -61,7 +61,7 @@
#include "output/raw.h"
#include "output/terminal_noncurses.h"

#ifndef _MSC_VER
#ifndef _WIN32
#ifdef NCURSES
#include "output/terminal_bcircle.h"
#include "output/terminal_ncurses.h"
Expand All @@ -87,7 +87,7 @@
#define GCC_UNUSED /* nothing */
#endif

#ifdef _MSC_VER
#ifdef _WIN32
char *optarg = NULL;
int optind = 1;

Expand Down Expand Up @@ -154,8 +154,12 @@ void cleanup(void) {
}

// general: handle signals
#ifdef _WIN32
int sig_handler(DWORD sig_no) {
#else
void sig_handler(int sig_no) {
#ifndef _MSC_VER
#endif
#ifndef _WIN32

if (sig_no == SIGUSR1) {
should_reload = 1;
Expand All @@ -170,11 +174,11 @@ void sig_handler(int sig_no) {

cleanup();

#ifdef _MSC_VER
#ifdef _WIN32
if (sig_no == CTRL_C_EVENT || sig_no == CTRL_CLOSE_EVENT) {
sig_no = SIGINT;
} else {
return;
return TRUE;
}
#endif
if (sig_no == SIGINT) {
Expand All @@ -183,6 +187,9 @@ void sig_handler(int sig_no) {

signal(sig_no, SIG_DFL);
raise(sig_no);
#ifdef _WIN32
return TRUE;
#endif
}

#ifdef ALSA
Expand Down Expand Up @@ -246,15 +253,15 @@ float *monstercat_filter(float *bars, int number_of_bars, int waves, double mons
// general: entry point
int main(int argc, char **argv) {

#ifndef _MSC_VER
#ifndef _WIN32
// general: console title
printf("%c]0;%s%c", '\033', PACKAGE, '\007');
#endif // !_MSC_VER
#endif // !_WIN32

// general: handle command-line arguments
char configPath[PATH_MAX];
configPath[0] = '\0';
#ifdef _MSC_VER
#ifdef _WIN32
if (!SetConsoleCtrlHandler(sig_handler, TRUE)) {
fprintf(stderr, "ERROR: Could not set control handler");
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -324,7 +331,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
int inAtty = 0;

output_mode = p.output;
#ifndef _MSC_VER
#ifndef _WIN32
if (output_mode == OUTPUT_NCURSES || output_mode == OUTPUT_NONCURSES) {
// Check if we're running in a tty
if (strncmp(ttyname(0), "/dev/tty", 8) == 0 || strcmp(ttyname(0), "/dev/console") == 0)
Expand Down Expand Up @@ -416,7 +423,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
pthread_mutex_init(&audio.lock, NULL);

switch (p.input) {
#ifndef _MSC_VER
#ifndef _WIN32

#ifdef ALSA
case INPUT_ALSA:
Expand Down Expand Up @@ -501,7 +508,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
break;
#endif
#endif
#ifdef _MSC_VER
#ifdef _WIN32
case INPUT_WINSCAP:
thr_id = pthread_create(&p_thread, NULL, input_winscap, (void *)&audio);
break;
Expand All @@ -512,7 +519,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co

timeout_counter = 0;
while (true) {
#ifdef _MSC_VER
#ifdef _WIN32
Sleep(1);
#else
nanosleep(&timeout_timer, NULL);
Expand Down Expand Up @@ -551,7 +558,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co

int height, lines, width, remainder, fp;
int *dimension_bar, *dimension_value;
#ifdef _MSC_VER
#ifdef _WIN32
HANDLE hFile = NULL;
#endif

Expand Down Expand Up @@ -629,7 +636,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
case OUTPUT_RAW:
case OUTPUT_NORITAKE:
if (strcmp(p.raw_target, "/dev/stdout") != 0) {
#ifndef _MSC_VER
#ifndef _WIN32
int fptest;
// checking if file exists
if (access(p.raw_target, F_OK) != -1) {
Expand Down Expand Up @@ -665,13 +672,13 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
free(pipePath);
#endif
} else {
#ifndef _MSC_VER
#ifndef _WIN32
fp = fileno(stdout);
#else
hFile = GetStdHandle(STD_OUTPUT_HANDLE);
#endif
}
#ifndef _MSC_VER
#ifndef _WIN32
if (fp == -1) {
#else
if (hFile == INVALID_HANDLE_VALUE) {
Expand Down Expand Up @@ -846,12 +853,12 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
framerate_timer.tv_sec = 0;
framerate_timer.tv_nsec = frame_time_msec * 1e6;
}
#ifdef _MSC_VER
#ifdef _WIN32
LARGE_INTEGER frequency; // ticks per second
LARGE_INTEGER t1, t2; // ticks
double elapsedTime;
QueryPerformanceFrequency(&frequency);
#endif // _MSC_VER
#endif // _WIN32

int sleep_counter = 0;
bool silence = false;
Expand All @@ -874,7 +881,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
ch = getch();
#endif

#ifndef _MSC_VER
#ifndef _WIN32
if (output_mode == OUTPUT_NONCURSES)
read(0, &ch, sizeof(ch));
#endif
Expand Down Expand Up @@ -944,7 +951,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co

#ifndef NDEBUG
// clear();
#ifndef _MSC_VER
#ifndef _WIN32
refresh();
#endif
#endif
Expand All @@ -958,7 +965,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
break;
}
}
#ifndef _MSC_VER
#ifndef _WIN32

if (output_mode != OUTPUT_SDL) {
if (p.sleep_timer) {
Expand All @@ -977,7 +984,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
}
}

#endif // !_MSC_VER
#endif // !_WIN32

// process: execute cava
pthread_mutex_lock(&audio.lock);
Expand Down Expand Up @@ -1159,9 +1166,9 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
minvalue); // checking maxvalue 10000
mvprintw(number_of_bars + 3, 0, "max value: %d\n",
maxvalue); // checking maxvalue 10000
#ifndef _MSC_VER
#ifndef _WIN32
(void)x_axis_info;
#endif // !_MSC_VER
#endif // !_WIN32
#endif

// output: draw processed input
Expand All @@ -1172,7 +1179,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
printf("\033[2026l\033\\");
}
int rc;
#ifdef _MSC_VER
#ifdef _WIN32
QueryPerformanceCounter(&t1);
#endif
switch (output_mode) {
Expand Down Expand Up @@ -1216,7 +1223,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
break;
#endif
case OUTPUT_RAW:
#ifndef _MSC_VER
#ifndef _WIN32
rc = print_raw_out(number_of_bars, fp, p.raw_format, p.bit_format,
p.ascii_range, p.bar_delim, p.frame_delim, bars);
#else
Expand All @@ -1225,7 +1232,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
#endif
break;
case OUTPUT_NORITAKE:
#ifndef _MSC_VER
#ifndef _WIN32
rc = print_ntk_out(number_of_bars, fp, p.bit_format, p.bar_width, p.bar_spacing,
p.bar_height, bars);
#else
Expand Down Expand Up @@ -1267,7 +1274,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
exit(EXIT_FAILURE);
}
pthread_mutex_unlock(&audio.lock);
#ifdef _MSC_VER
#ifdef _WIN32
QueryPerformanceCounter(&t2);
elapsedTime = (t2.QuadPart - t1.QuadPart) * 1000.0 / frequency.QuadPart;
int fps_sync_time = frame_time_msec;
Expand All @@ -1279,7 +1286,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
fps_sync_time = (frame_time_msec - (int)elapsedTime) / 2;
#endif
if (output_mode != OUTPUT_SDL && output_mode != OUTPUT_SDL_GLSL) {
#ifdef _MSC_VER
#ifdef _WIN32
Sleep(fps_sync_time);
#else
nanosleep(&framerate_timer, NULL);
Expand Down
Loading