From d712a3acbaf2eabba33fcb8a7e59a42a79a535a2 Mon Sep 17 00:00:00 2001 From: danct12 Date: Mon, 11 May 2026 12:13:44 +0000 Subject: [PATCH] Add fallback for missing stdbit.h Some libc does not provide stdbit.h. But the compiler does support the functions in it. This should allow libxm to build on MinGW with GCC 16. --- src/CMakeLists.txt | 9 +++++++++ src/compat/stdbit.h | 14 ++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/compat/stdbit.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d12074b..69d7229 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,8 @@ project(libxm LANGUAGES C) set(CMAKE_C_STANDARD 23) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) +include(CheckIncludeFile) + add_library(xm_common INTERFACE) if(CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang)$") target_compile_options(xm_common INTERFACE @@ -29,6 +31,13 @@ find_library(MATH_LIBRARY m REQUIRED) target_include_directories(xm SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(xm PRIVATE xm_common ${MATH_LIBRARY}) +# Check if stdbit.h is available +check_include_file(stdbit.h HAVE_STDBIT_H) + +if (NOT HAVE_STDBIT_H) + target_include_directories(xm SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/compat) +endif() + function(option_and_define name description default_value) option(${name} ${description} ${default_value}) if(${name}) diff --git a/src/compat/stdbit.h b/src/compat/stdbit.h new file mode 100644 index 0000000..fb3baad --- /dev/null +++ b/src/compat/stdbit.h @@ -0,0 +1,14 @@ +/* Author: danct12 */ + +/* This program is free software. It comes without any warranty, to the + * extent permitted by applicable law. You can redistribute it and/or + * modify it under the terms of the Do What The Fuck You Want To Public + * License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/wtfpl/COPYING for more details. */ + +#ifndef __FALLBACK_STDBIT_H__ +#define __FALLBACK_STDBIT_H__ + +#define stdc_count_ones __builtin_stdc_count_ones + +#endif /* __FALLBACK_STDBIT_H__ */