@@ -22,25 +22,104 @@ Requires `warthog-core` as a dependency.
2222
2323# Using warthog
2424
25- Warthog dependencies are setup using git-submodules, use commands below are used to initialise and update respectively:
26- git submodule init
27- git submodule update
25+ It is recommended to use warthog not as a fork, but included in an external repo.
26+ This setup support FetchContent, git submodule and git subtree.
2827
29- All dependencies should be placed in ` /extern ` .
30- If not project forked, we suggest setting the project up as below:
28+ ## CMake
29+
30+ Setup a basic project using the following the commands:
31+
32+ git init
33+ git remote add warthog-core https://github.com/ShortestPathLab/warthog-core.git
34+ git fetch warthog-core
35+ git checkout warthog-core/main cmake/warthog.cmake
36+
37+ Example ` CMakeLists.txt ` :
3138
32- 1 . Copy ` /cmake/submodule.cmake ` to your repo
33- 2 . Submodule or subtree all your warthog dependencies and their dependencies into ` /extern `
34- 3 . In ` /CMakeLists.txt ` , setup as below:
3539```
36- include(cmake/submodule.cmake)
37- warthog_submodule(warthog-[module]) # repeat for each [module]
40+ cmake_minimum_required(VERSION 3.13)
41+
42+ project(App
43+ VERSION 0.0.1
44+ LANGUAGES CXX C)
45+
46+ set(CMAKE_CXX_STANDARD 20)
47+ set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
48+
49+ # warthog modules
50+ include(cmake/warthog.cmake)
51+
52+ warthog_module_declare(warthog-core v0.5.0) # is optional, remove for default of main
53+ warthog_module(warthog-core)
54+
55+ add_executable(app main.cpp)
56+ target_link_libraries(app PUBLIC warthog::core)
3857```
3958
40- With (2) we flatten dependencies to top-level project.
41- With (3) ` warthog_submodule ` will add ` add_subdirectoy ` if your CMake is the top level config.
59+ ## Submodule
60+
61+ Commands for adding a module as a submodules for each repo are found below:
62+
63+ git submodule add https://github.com/ShortestPathLab/warthog-core.git extern/warthog-core
64+ git submodule add https://github.com/ShortestPathLab/warthog-jps.git extern/warthog-jps
65+
66+ To update the version of warthog, for warthog module ` $module ` :
67+
68+ cd extern/$module
69+ git fetch
70+ git checkout|git switch
71+ cd ..
72+ git add $module
73+
74+ This will update the submodule to the checkout commit.
75+ Initialise or update the submodule on other clones with
76+ the following commands:
77+
78+ git submodule init # after clone
79+ git submodule update # after pull
4280
43- An informal project not designed to be a dependency does not require this, and can just ` add_subdirectory ` to all dependencies.
81+ ## Subtree
82+
83+ Subtree will make the module a part of your repo, allowing
84+ for local editing without forking.
85+
86+ The setup for each module:
87+
88+ git subtree -P extern/warthog-core add https://github.com/ShortestPathLab/warthog-core.git main|branch|commit --squash
89+ git subtree -P extern/warthog-jps add https://github.com/ShortestPathLab/warthog-jps.git main|branch|commit --squash
90+
91+ The update commands:
92+
93+ git subtree -P extern/warthog-core pull https://github.com/ShortestPathLab/warthog-core.git main|branch|commit --squash
94+ git subtree -P extern/warthog-jps pull https://github.com/ShortestPathLab/warthog-jps.git main|branch|commit --squash
95+
96+ ## Advance Module Details
97+
98+ File ` /cmake/warthog.cmake ` from warthog core should be copied to user repo and ` include ` in CMake.
99+ Calling ` warthog_submodule(warthog-core) ` will then add ` warthog-core ` to your CMake in the following order:
100+ 1 . ` add_subdirectory(/extern/warthog-core) ` if ` /extern/warthog-core/CMakeLists.txt ` exists (submodule/subtree)
101+ 2 . ` FetchContent_Declare ` then ` FetchContent_MakeAvailable(warthog-core) ` otherwise
102+ 3 . Error if cannot find ` warthog-core ` content
103+
104+ The ` warthog_module ` call only adds a module once, the following calls will be ignored.
105+ The submodule/subtree version only works if called in the top level project by default;
106+ if this method is preferred, then it should be added to the top level ` /extern/ ` , can be overridden
107+ with code ` warthog_module(warthog-core ON) ` .
108+
109+ Declare of warthog-core can be done using the following code:
110+ ```
111+ warthog_module_declare(warthog-core [main|branch|tag|commit])
112+ ```
113+ or:
114+ ```
115+ FetchContent_Declare(warthog-core
116+ GIT_REPOSITORY https://github.com/ShortestPathLab/warthog-core.git
117+ GIT_TAG [main|branch|tag|commit])
118+ ```
119+ This will declare what warthog-core version to fetched.
120+ The ` warthog_module_declare ` version makes it simple, although it only supports known warthog libraries.
121+ The optional second parameter sets the version to pull, by default is ` main ` branch.
122+ This system only support warthog 0.5 or greater.
44123
45124# Resources
46125
0 commit comments