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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
55 changes: 55 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
cmake_minimum_required(VERSION 3.10)
project(
cvector
VERSION 1.0.0
LANGUAGES C CXX
DESCRIPTION "A simple vector library for C that can store any type."
)

add_library(cvector vec.c)
set_target_properties(cvector PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${PROJECT_VERSION}
PUBLIC_HEADER "vec.h"
)

include(GNUInstallDirs)
target_include_directories(
cvector PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

install(TARGETS cvector
EXPORT cvectorTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(EXPORT cvectorTargets
FILE cvectorTargets.cmake
NAMESPACE cvector::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cvector
)

include(CMakePackageConfigHelpers)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cvectorConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
VERSION ${PROJECT_VERSION}
)

configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/cmake/cvectorConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cvectorConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cvector
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/cvectorConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cvectorConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cvector
)
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,16 @@ Because some compilers don't support the `typeof` operator, which is used for st
| erase `4` items from `vec` at index `3` | `vector_erase(vec, type, 3, 4);` | no (moves elements) |
| remove item at index `3` from `vec` | `vector_remove(vec, type, 3);` | no (moves elements) |
| add `item` to the vector `vec` | `type* temp = vector_add_dst(&vec, type);` | yes |
| insert `item` into `vec` at index `9` | `type* temp = vector_insert_dst(&vec, type, 9);` | yes |
| insert `item` into `vec` at index `9` | `type* temp = vector_insert_dst(&vec, type, 9);` | yes |

# CMake Integration
You can easily use `c-vector` in your [CMake](https://cmake.org) project. Clone the repository and run the following command:
```shell
cmake -Bbuild -GNinja
```
This builds the project in your directory of choice, which is `build/` here, with your build system of choice, which is [Ninja](https://ninja-build.org) here. You can use it with any directory or build system, but the following is a Ninja example:
```shell
ninja build
ninja install
```
You can also specify whether you want to build as a shared or static library, installation directories, etc. using `-D` flags. Consult the CMake documentation for how to do that.
2 changes: 2 additions & 0 deletions cmake/cvectorConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/cvectorTargets.cmake")