0

Suppose I create a C++ CMake project for Windows using CLion that includes a subdirectory named formatter/ containing platform-agnostic classes to act like a Decorator between a HD44780 LCD (or an emulated one running under Windows) and a program that uses it as its display. For example, to implement things like marquees and "smashed decimals" (using a single custom character to render a decimal point and superscript-like digit into a single character).

My quandary: I'm unsure about how to structure the project and its Git repo(s).

  • When working on the formatter library under Windows, I don't want to have anything Arduino-related within sight of the project.

  • When using the formatter library in an Arduino project, I don't want anything Windows-related showing up to confuse it.

  • Even though I'll be doing the bulk of the formatter library's development under Windows, I'd like to someday be able to edit the library's files in the context of either the original Windows project or an Arduino project.

I can tentatively think of two ways:

  1. Create a Windows C++ project with SFML using CLion and CMake, and publish it to Github.

  2. Create another project on Github and add it to the first as a submodule in a subdirectory named formatter/

  3. Check out project #1 using git clone --recursive into a new directory, and use it going forward.

  4. Someday, create my Arduino library project, and add my hd44780-formatter library to its formatter/ subdirectory as a submodule

... or ...

  1. Create a Windows C++ CMake project just like step 1 above

  2. Create a formatter/ subdirectory within it, put the platform-agnostic classes there, and do the bulk of initial development.

  3. someday... create the new Arduino library project on Github, then somehow tell Git, "add only the formatter/ subdirectory of {first-repo} to {second-repo} as a submodule"

In any case, I'm not really sure how to proceed.

I already tried to implement the first scenario. I made it as far as step 3. I checked out my project (containing the Windows project plus empty "formatter/" subdirectory) using --recursive into a new subdirectory, opened it in CLion, then created a few new classes in the "formatter/" subdirectory.

I then launched SmartGit, opened the directory containing the project, and staged the new files from the "formatter/" subdirectory. When I tried to commit them, the following dialog appeared:

enter image description here

The problem is, I think I know what the sentences mean individually... but I don't really understand what they mean collectively, or what action I should take to continue. I'm not sure whether it's telling me to create a branch for repo #2, repo #1, or both... and if both, whether I should give them the same names, different names, or otherwise need to do anything to coordinate the two.

So... just to be clear about what it is that I'm trying to achieve here (assuming I'm going about this the right way)... I'd like to be able to:

  • load the Windows project into CLion (with the formatter classes in a subdirectory created from the second-repo submodule),

  • edit and add classes to the project (including to the formatter/ subdirectory),

  • commit them to the local repo, and

  • push them to their respective Github remote repos so that files in "formatter/" end up getting pushed to the second repo, and everything else gets pushed to the first repo.

For the sake of providing concrete examples, the two Github repos in question are https://github.com/jskubick/vrEmuLcd4win.git and https://github.com/jskubick/hd44780-formatter.git


Update, 7/20/22

I got frustrated & severed the submodule link in vrEmuLcd4win & (semi-temporarily?) replaced it with a normal subdirectory so I can move forward instead of being stalled & sidetracked indefinitely trying to get past this submodule problem :-(

Bitbang3r
  • 6,826
  • 5
  • 27
  • 40
  • "*When working on the formatter library under Windows, I don't want to have anything Arduino-related within sight of the project.*" Could you simply put the Windows stuff in a Windows directory and the Arduino stuff in an Arduino directory and have your build program sort it out? This is much simpler than messing with submodules. – Schwern Jul 19 '22 at 19:20
  • As for the detached HEAD, see https://stackoverflow.com/questions/10228760/how-do-i-fix-a-git-detached-head and many others like it. If you're confused about a detached HEAD, probably don't mess with submodules. Even if you did, probably don't mess with submodules. :) – Schwern Jul 19 '22 at 19:22
  • Could I? In theory, I suppose it's possible. Do I have any idea how to integrate platform-specific Windows and Arduino/PlatformIO code into the same project so they build independently and don't stomp on each other? No, I really don't. Hence, the idea of keeping the platform-agnostic code in one repo, and indirectly pulling it into two other completely separate projects that know nothing about each other's existence. Unfortunately, it looks like Git submodules themselves are a half step short of black magic. I have 3 books on Git, and only ONE of them even mentions that they exist. – Bitbang3r Jul 19 '22 at 23:29
  • "*keeping the platform-agnostic code in one repo, and indirectly pulling it into two other completely separate projects that know nothing about each other's existence*" If you can do this, surely you can put those "completely separate projects" into sub-directories of the platform agnostic code? That's how most Open Source projects do it, there should be plenty of examples out there. And yes, if you try to solve a problem with Git submodules you now have two problems. ;) – Schwern Jul 20 '22 at 00:32
  • For example, [Ruby](https://github.com/ruby/ruby). – Schwern Jul 20 '22 at 00:35

0 Answers0