diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..076140e --- /dev/null +++ b/CMakeLists.txt @@ -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(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 +) diff --git a/README.md b/README.md index db5bdfb..c596918 100644 --- a/README.md +++ b/README.md @@ -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 | \ No newline at end of file +| 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. diff --git a/cmake/cvectorConfig.cmake.in b/cmake/cvectorConfig.cmake.in new file mode 100644 index 0000000..dbb100b --- /dev/null +++ b/cmake/cvectorConfig.cmake.in @@ -0,0 +1,2 @@ +@PACKAGE_INIT@ +include("${CMAKE_CURRENT_LIST_DIR}/cvectorTargets.cmake")