Skip to content

Commit 5a4ba02

Browse files
committed
build: update CMake versions and language standards
The `typeof` keyword used by this library only became available in the C23 standard. Previously, it was available as a gnu and clang extension. Also, updated the example to use rand() instead of random(). This is an older function, but is more portable.
1 parent e7743f7 commit 5a4ba02

4 files changed

Lines changed: 18 additions & 11 deletions

File tree

CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
cmake_minimum_required(VERSION 3.5)
2-
project(hashmap VERSION 2.0.0 LANGUAGES C)
1+
cmake_minimum_required(VERSION 3.16)
2+
project(hashmap VERSION 2.1.0 LANGUAGES C)
33

4-
set(CMAKE_C_STANDARD 11)
4+
if(NOT DEFINED CMAKE_C_STANDARD)
5+
set(CMAKE_C_STANDARD 23)
6+
set(CMAKE_C_EXTENSIONS OFF)
7+
endif()
58

69
##############################################
710
# Build options
@@ -36,7 +39,7 @@ target_include_directories(hashmap
3639
${CMAKE_CURRENT_SOURCE_DIR}/src
3740
)
3841
target_compile_options(hashmap
39-
PRIVATE $<$<C_COMPILER_ID:GNU>:-Wall -Werror>
42+
PRIVATE -Wall -Werror
4043
)
4144

4245
##############################################

examples/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5)
2-
31
# Hashmap example
42
add_executable(hashmap_example hashmap_example.c)
53
target_compile_options(hashmap_example PRIVATE -Wall -Werror)

examples/hashmap_example.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ struct blob *blob_load(void)
3838
if ((b = malloc(sizeof(*b))) == NULL) {
3939
return NULL;
4040
}
41-
snprintf(b->key, sizeof(b->key), "%02lx", random() % 100);
42-
b->data_len = random() % 10;
43-
memset(b->data, random(), b->data_len);
41+
snprintf(b->key, sizeof(b->key), "%02x", rand() % 100);
42+
b->data_len = rand() % 10;
43+
memset(b->data, rand(), b->data_len);
4444

4545
return b;
4646
}

tests/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
cmake_minimum_required(VERSION 3.19)
22
project(hashmap_test)
33

4-
set(CMAKE_C_STANDARD 11)
5-
set(CMAKE_CXX_STANDARD 20)
4+
if(NOT DEFINED CMAKE_C_STANDARD)
5+
set(CMAKE_C_STANDARD 23)
6+
set(CMAKE_C_EXTENSIONS OFF)
7+
endif()
8+
9+
if(NOT DEFINED CMAKE_CXX_STANDARD)
10+
set(CMAKE_CXX_STANDARD 20)
11+
endif()
612

713
include(FetchContent)
814

0 commit comments

Comments
 (0)