mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-08-06 13:19:47 +00:00
Add more details
parent
1462dccb90
commit
c25060c871
1 changed files with 14 additions and 1 deletions
15
flat_git.md
15
flat_git.md
|
@ -1,4 +1,16 @@
|
|||
# Introduction
|
||||
## Problem
|
||||
Git offers submodules, a great way to manage your projects in a modular way. The problem with that is well summarized by this [question](http://stackoverflow.com/questions/27379818/git-possible-to-use-same-submodule-working-copy-by-multiple-projects) on StackOverflow. In short, every low-level library from your project is likely to be pulled in more than once, and so you will have multiple copies of each.
|
||||
|
||||
## Solution
|
||||
The solution is also provided on the same [StackOverflow page](http://stackoverflow.com/questions/27379818/git-possible-to-use-same-submodule-working-copy-by-multiple-projects). Git allows you to share a repository and make submodules all point to the same copy on your hard disk. This means that if you modify or update any of the cloned repositories, any repository referencing it will be affected. This might or might not be what you want.
|
||||
|
||||
## About the script
|
||||
All the flat_git script does is automating the process explained the the Solution section. You don't really need to run this script to apply this technique, and you don't need to keep using the script at any point.
|
||||
|
||||
The obvious problem left at this point is that, irrespectively of if you decide to use the flat_git script, if you apply the above technique you will end up with subdirectories in your project that are empty instead of containing the usual submodule. Or maybe the do contain the submodule's working tree. You need to tweak your build system to deal with this.
|
||||
|
||||
A CMake script is provided to deal with this scenario if you are using CMake for your project. See the Example section for a practical example.
|
||||
|
||||
# Usage
|
||||
|
||||
|
@ -7,7 +19,6 @@ In this example let's say you have one CMake project per git repository, for a t
|
|||
|
||||
CMakeLists.txt - everything is just the same as usual, except that you use `add_shared_git_project` instead of the regular `add_subdirectory`.
|
||||
```cmake
|
||||
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
|
||||
project(top_project CXX)
|
||||
include(shared_git_project)
|
||||
add_executable(top_project main.cpp)
|
||||
|
@ -21,12 +32,14 @@ lib/sub_1/CMakeLists.txt
|
|||
include(shared_git_project)
|
||||
add_library(sub_1 lib1.cpp)
|
||||
add_shared_git_pcoject(lib/sub_2)
|
||||
target_include_directories(sub_1 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
```
|
||||
|
||||
lib/sub_2/CMakeLists.txt
|
||||
```cmake
|
||||
project(sub_2)
|
||||
add_library(sub_2 lib2.cpp)
|
||||
target_include_directories(sub_2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
```
|
||||
|
||||
This will clone the main git repository and the sub_1 and sub_2 directories inside the shared/ directory. After doing this you are good to go!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue