From 2958f6c034ec6101210d5db42500998035af4aba Mon Sep 17 00:00:00 2001 From: Cliff Foster Date: Thu, 29 Feb 2024 19:47:35 -0800 Subject: [PATCH] Make lib git ignore more permissive, add documentation. --- lib/.gitignore | 10 ++++---- lib/README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++- lib/libidi | 1 + 3 files changed, 69 insertions(+), 5 deletions(-) create mode 160000 lib/libidi diff --git a/lib/.gitignore b/lib/.gitignore index 3099a57..7fc9283 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -1,5 +1,7 @@ # Do not edit this file, it can/will be replaced by template updates. -* -!libraries.cmake -!README.mod -!.gitignore +# All subdirectories are ignored by default. If you specifically want to enable +# a subdirectory for commiting, add it as an exception _after_ the */* rule. +*/* + +# add subfolders that you need to track as such +#!some-folder/* diff --git a/lib/README.md b/lib/README.md index 1bc347d..417729d 100644 --- a/lib/README.md +++ b/lib/README.md @@ -1,3 +1,64 @@ # External Libraries -Folders in here should ideally be linked to sub modules. +There are two primary ways of adding external libraries in this framework. The preferred method is using the `idi_add_first_party_dependency()` and `idi_add_third_party_dependency()` CMake functions available in the framework. The second, less preferred but still acceptable way is to add git submodules directly. + +## CMake Dependency Management + +The framework contains two functions that wrap CMake's `FetchContent` facilities and are designed to integrate git repository dependencies. + +``` +idi_add_first_party_dependency( + + + + [DOWNLOAD_ONLY] + [DEP_OPTIONS args...] +) + +idi_add_third_party_dependency( + + + + [DOWNLOAD_ONLY] + [DEP_OPTIONS args...] +) +``` + +Both functions are identical in signature, but with slight differences in that `idi_add_third_party_dependency()` will place dependencies in `lib/.third-party` instead of directly in `lib/` and `idi_add_first_party_dependency()` will _not_ replace files if the configuration is wiped out, but warn instead about untracked/modified files and mismatching git checkout information. + +The value of `` should be the same as the underlying CMake `project()` name to make sure that if multiple dependencies use it, it has a higher chance of matching and preventing duplicate dependencies. + +`` and `` are the same as those in CMake's `GIT_REPOSITORY` and `GIT_TAG` options passed to `FetchContent_Declare` (and derive from `ExternalProject_Add()`). + +`DOWNLOAD_ONLY` is optional and will only download the contents of the git repository and not try to add them to the project. This is useful if the repository doesn't support CMake out of the box or uses a different build system. + +`DEP_OPTIONS` are a series of strings to set options for the dependency, they are the same as calling `set(name value)` before `add_subdirectory()` is called. They are dependent on the options specified by the underlying dependency, and are written as `"OPTION_NAME OPTION_VALUE"`, such as `"SPDLOG_NO_EXCEPTIONS OFF"` would set `spdlog` to not use exceptions. + + +### CMake Variables + +`IDICMAKE_EXTERNAL_LIB_DIR` points to the root library folder + +`IDICMAKE_EXTERNAL_THIRD_PARTY_LIB_DIR` points to the third party library directory. + +`IDI_SYNC_DEPENDENCIES` can be set globally to `true` and on a clean reconfiguration of the project it will sync **all** dependency folders to the configured checkout. This can be potentially destructive if you are making changes to dependencies. + + +### Examples: + +``` +# Add third party dependency and set options +idi_add_third_party_dependency(spdlog https://github.com/gabime/spdlog.git v1.12.0 DEP_OPTIONS "SPDLOG_NO_EXCEPTIONS ON") + +# Add first party dependency +idi_add_first_party_dependency(idi https://gitlab.idi-systems.com/idi/libidi.git master) + +# Add third party dependency and specify a custom CMake target for a project that doesn't use CMake +idi_add_third_party_dependency(asio https://github.com/chriskohlhoff/asio.git asio-1-29-0 DOWNLOAD_ONLY) +add_library(asio INTERFACE) +target_include_directories(asio SYSTEM INTERFACE ${IDICMAKE_EXTERNAL_THIRD_PARTY_LIB_DIR}/asio/asio/include) +``` + +# Git Submodules + +Use git submodules as you would in any other project. Ideally follow the same pattern for folder placement, with third party libraries being placed in the `lib/.third-party` folder. diff --git a/lib/libidi b/lib/libidi new file mode 160000 index 0000000..61c6960 --- /dev/null +++ b/lib/libidi @@ -0,0 +1 @@ +Subproject commit 61c696045d7bd04f4e4ef5392f40f24502351cd1