From 81731c38f4c04bacd6b1613176b2048dd3ff4150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20M=C3=A5rdbrink?= Date: Sat, 19 Apr 2025 16:09:50 +0200 Subject: [PATCH] Make available for FetchContent --- CMakeLists.txt | 21 +++++++++++++++------ README.md | 23 +++++++++++++++++++++-- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7870719..8361425 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,26 +6,35 @@ set(CMAKE_C_STANDARD_REQUIRED YES) set(CMAKE_C_EXTENSIONS NO) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -include(GNUInstallDirs) + +include(GNUInstallDirs) file(GLOB HTD_SOURCES src/data_structure/*.c ) add_library(htd STATIC ${HTD_SOURCES}) +add_library(htd::htd ALIAS htd) + target_include_directories(htd PUBLIC - ${PROJECT_SOURCE_DIR}/include + $ + $ ) + target_compile_options(htd PRIVATE -Wall -Wextra -Werror -pedantic) -#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=address") -#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") - install(TARGETS htd + EXPORT htdTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) + +install(EXPORT htdTargets + FILE htdTargets.cmake + NAMESPACE htd:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/htd +) + install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/htd FILES_MATCHING PATTERN "*.h" diff --git a/README.md b/README.md index 1f9172d..3e10301 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,24 @@ # Personal library for C +## Installation +This library can easily be installed using CMake and FetchContent. +Add this to your CMakeLists.txt file: + +```cmake +include(FetchContent) + +FetchContent_Declare( + htd + GIT_REPOSITORY https://github.com/hugomardbrink/htd.git + GIT_TAG main +) + +FetchContent_MakeAvailable(htd) + +add_executable(myapp main.c) +target_link_libraries(myapp PRIVATE htd::htd) +``` + ## Features ### Primitives Use shorter more concise names for common C types. @@ -37,14 +56,14 @@ cd build ctest ``` -## Installing +## Local install ```bash cd build make install ``` -## Uninstalling +## Local uninstall ```bash cd build