Skip to content

Commit

Permalink
migrated to cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphGL committed Aug 18, 2024
1 parent 7a9b5ee commit f98f918
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 445 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/c.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: test all libraries
run: make test
run: |
cmake . -DCMAKE_BUILD_TYPE=Debug
make
ctest --output-on-failure
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles/
DartConfiguration.tcl
bin/
lib/
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
.cmake

# Prerequisites
*.d

Expand Down
43 changes: 43 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cmake_minimum_required(VERSION 3.15)

project(clibs)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(SANITIZERS -fsanitize=address,undefined)
add_link_options(${SANITIZERS})
add_compile_options(${SANITIZERS})
message(STATUS "Enabled sanitizers with: ${SANITIZERS}")
endif()

# --- Adding libraries ---

add_subdirectory(bstr)
add_subdirectory(vec)
add_subdirectory(flag)

target_link_libraries(flag PRIVATE bstr vec)

# --- Executables ---

add_executable(bstr_test bstr/maintest.c)
target_link_libraries(bstr_test bstr)

add_executable(vec_test vec/maintest.c)
target_link_libraries(vec_test vec)

add_executable(flag_test flag/maintest.c)
target_link_libraries(flag_test flag)

# --- Testing ---

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)

add_test(NAME bstr COMMAND bstr_test)
add_test(NAME vec COMMAND vec_test)
add_test(NAME flag COMMAND flag_test)
endif()
8 changes: 0 additions & 8 deletions Makefile

This file was deleted.

7 changes: 7 additions & 0 deletions bstr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)

project(bstr DESCRIPTION "high level string library")

add_library(bstr STATIC bstr.c)
target_compile_features(bstr PUBLIC c_std_11)

14 changes: 0 additions & 14 deletions bstr/Makefile

This file was deleted.

Binary file added bstr/maintest
Binary file not shown.
5 changes: 5 additions & 0 deletions flag/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.10)

project(flag DESCRIPTION "flag parsing library")

add_library(flag flag.c)
21 changes: 0 additions & 21 deletions flag/Makefile

This file was deleted.

10 changes: 9 additions & 1 deletion flag/flag.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,27 @@ typedef struct flag_parser {
struct vec_vector *remaining;
} flag_Parser;

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

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


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


long *flag_long(flag_Parser *p, char *name, long default_val, char *usage);
float *flag_float(flag_Parser *p, char *name, float default_val, char *usage);
bool *flag_bool(flag_Parser *p, char *name, bool default_val, char *usage);
Expand Down
6 changes: 6 additions & 0 deletions vec/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.10)

project(vec DESCRIPTION "dynamically growable vector structure")

add_library(vec STATIC vector.c)
target_link_libraries(vec PRIVATE m)
18 changes: 0 additions & 18 deletions vec/Makefile

This file was deleted.

Loading

0 comments on commit f98f918

Please sign in to comment.