aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--CMakeLists.txt66
-rw-r--r--cheesemap.h12
3 files changed, 74 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 5cae1f3..78e7f44 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
+**/build*/
+**/out*/
*.o
*.d
*.json
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..3fb6c3c
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,66 @@
+cmake_minimum_required(VERSION 4.0)
+project(cheesemap
+ VERSION 0.1.0
+ DESCRIPTION "A high-performance HashMap"
+)
+
+if(MSVC)
+ message(FATAL_ERROR "You need to have a GNU compatible compiler")
+endif()
+
+## configuration
+
+set(CM_PANIC_SYM "panic_impl" CACHE STRING "Symbol name of the panic method")
+
+option(CM_ENABLE_EXTENDED_DEBUG "Whether to enable extended debug information" OFF)
+option(CM_ENABLE_UBSAN "Whether to enable undefined behavior sanitizer" OFF)
+option(CM_ENABLE_ASAN "Whether to enable address sanitizer" OFF)
+option(CM_ENABLE_SSE2 "Whether to enable SSE2 usage" OFF)
+
+## source
+
+set(cheesemap_source "${CMAKE_SOURCE_DIR}/cheesemap.c")
+
+## helper functions
+
+function(add_if_enabled target option_name)
+ if(NOT ${option_name})
+ return()
+ endif()
+
+ cmake_parse_arguments(ARG "" "" "COMPILE_OPTIONS;LINK_OPTIONS;DEFINITIONS" ${ARGN})
+
+ if(ARG_COMPILE_OPTIONS)
+ target_compile_options(${target} PRIVATE ${ARG_COMPILE_OPTIONS})
+ endif()
+
+ if(ARG_LINK_OPTIONS)
+ target_link_options(${target} PRIVATE ${ARG_LINK_OPTIONS})
+ endif()
+
+ if(ARG_DEFINITIONS)
+ target_compile_definitions(${target} PRIVATE ${ARG_DEFINITIONS})
+ endif()
+endfunction()
+
+## library target
+
+add_library(cheesemap OBJECT ${cheesemap_source})
+
+set_target_properties(cheesemap PROPERTIES
+ C_STANDARD 11
+ C_STANDARD_REQUIRED ON
+ C_EXTENSIONS ON
+ POSITION_INDEPENDENT_CODE ON
+)
+
+target_include_directories(cheesemap PUBLIC ${CMAKE_SOURCE_DIR})
+target_compile_definitions(cheesemap PRIVATE CM_PANIC_SYM=${CM_PANIC_SYM})
+target_compile_options(cheesemap PRIVATE -Wall -Wextra -Werror)
+
+add_if_enabled(cheesemap CM_ENABLE_EXTENDED_DEBUG COMPILE_OPTIONS -g3)
+add_if_enabled(cheesemap CM_ENABLE_UBSAN COMPILE_OPTIONS -fsanitize=undefined LINK_OPTIONS -fsanitize=undefined)
+add_if_enabled(cheesemap CM_ENABLE_ASAN COMPILE_OPTIONS -fsanitize=address LINK_OPTIONS -fsanitize=address)
+add_if_enabled(cheesemap CM_ENABLE_SSE2 COMPILE_OPTIONS -msse2 DEFINITIONS CM_ENABLE_SSE2=1)
+
+
diff --git a/cheesemap.h b/cheesemap.h
index 73ddc48..e736588 100644
--- a/cheesemap.h
+++ b/cheesemap.h
@@ -13,13 +13,13 @@ extern "C" {
#include <stdbool.h>
#include <stdint.h>
-_Noreturn void CM_OPT_PANIC_NAME(const char* file, uint32_t line,
- const char* fmt, ...);
+_Noreturn void CM_PANIC_SYM(const char* file, uint32_t line, const char* fmt,
+ ...);
-#define cm_assert(cond) \
- do { \
- if (!(cond)) \
- CM_OPT_PANIC_NAME(__FILE__, __LINE__, "cm_assertion failed: %s", #cond); \
+#define cm_assert(cond) \
+ do { \
+ if (!(cond)) \
+ CM_PANIC_SYM(__FILE__, __LINE__, "cm_assertion failed: %s", #cond); \
} while (0)
#ifdef CM_OPT_ENABLE_SSE2