Skip to content
Open
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
9 changes: 9 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})
Expand Down
14 changes: 14 additions & 0 deletions src/compat/stdbit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* Author: danct12 <danct12@demodiv.danctnix.org> */

/* 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__ */