Skip to content

Commit f98f918

Browse files
committed
migrated to cmake
1 parent 7a9b5ee commit f98f918

File tree

13 files changed

+91
-445
lines changed

13 files changed

+91
-445
lines changed

.github/workflows/c.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v4
1616
- name: test all libraries
17-
run: make test
17+
run: |
18+
cmake . -DCMAKE_BUILD_TYPE=Debug
19+
make
20+
ctest --output-on-failure

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
CMakeLists.txt.user
2+
CMakeCache.txt
3+
CMakeFiles/
4+
DartConfiguration.tcl
5+
bin/
6+
lib/
7+
CMakeScripts
8+
Testing
9+
Makefile
10+
cmake_install.cmake
11+
install_manifest.txt
12+
compile_commands.json
13+
CTestTestfile.cmake
14+
_deps
15+
CMakeUserPresets.json
16+
.cmake
17+
118
# Prerequisites
219
*.d
320

CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
3+
project(clibs)
4+
5+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
6+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
7+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
8+
9+
if(CMAKE_BUILD_TYPE STREQUAL Debug)
10+
set(SANITIZERS -fsanitize=address,undefined)
11+
add_link_options(${SANITIZERS})
12+
add_compile_options(${SANITIZERS})
13+
message(STATUS "Enabled sanitizers with: ${SANITIZERS}")
14+
endif()
15+
16+
# --- Adding libraries ---
17+
18+
add_subdirectory(bstr)
19+
add_subdirectory(vec)
20+
add_subdirectory(flag)
21+
22+
target_link_libraries(flag PRIVATE bstr vec)
23+
24+
# --- Executables ---
25+
26+
add_executable(bstr_test bstr/maintest.c)
27+
target_link_libraries(bstr_test bstr)
28+
29+
add_executable(vec_test vec/maintest.c)
30+
target_link_libraries(vec_test vec)
31+
32+
add_executable(flag_test flag/maintest.c)
33+
target_link_libraries(flag_test flag)
34+
35+
# --- Testing ---
36+
37+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
38+
include(CTest)
39+
40+
add_test(NAME bstr COMMAND bstr_test)
41+
add_test(NAME vec COMMAND vec_test)
42+
add_test(NAME flag COMMAND flag_test)
43+
endif()

Makefile

Lines changed: 0 additions & 8 deletions
This file was deleted.

bstr/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
3+
project(bstr DESCRIPTION "high level string library")
4+
5+
add_library(bstr STATIC bstr.c)
6+
target_compile_features(bstr PUBLIC c_std_11)
7+

bstr/Makefile

Lines changed: 0 additions & 14 deletions
This file was deleted.

bstr/maintest

176 KB
Binary file not shown.

flag/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
project(flag DESCRIPTION "flag parsing library")
4+
5+
add_library(flag flag.c)

flag/Makefile

Lines changed: 0 additions & 21 deletions
This file was deleted.

flag/flag.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,27 @@ typedef struct flag_parser {
1111
struct vec_vector *remaining;
1212
} flag_Parser;
1313

14+
// Initializes parser.
15+
// Parser should later be freed with `flag_free`.
1416
flag_Parser flag_new(int argc, char *argv[]);
1517
void flag_free(flag_Parser *p);
1618

19+
// Parses flags that have been setup by the `flag_<type>` functions.
20+
// This function should only be called after the setup has done.
1721
void flag_parse(flag_Parser *p);
22+
// Returns true if flags have been parsed.
1823
bool flag_parsed(flag_Parser *p);
24+
// Returns the number of flags that have been configured.
1925
size_t flag_nflags(flag_Parser *p);
26+
// Prints all the flags that have been setup for the parser.
2027
void flag_print_flags(flag_Parser *p);
2128

2229

30+
// Returns the number of remaining args after flags have been handled.
2331
size_t flag_nargs(flag_Parser *p);
32+
// Retrieves remaining args after flags have been handled by index starting from 0.
2433
char *flag_arg(flag_Parser *p, size_t idx);
2534

26-
2735
long *flag_long(flag_Parser *p, char *name, long default_val, char *usage);
2836
float *flag_float(flag_Parser *p, char *name, float default_val, char *usage);
2937
bool *flag_bool(flag_Parser *p, char *name, bool default_val, char *usage);

0 commit comments

Comments
 (0)