Skip to content

Commit

Permalink
(DOCSP-26811): Remove cpprealm git submodule, use FetchContent instead (
Browse files Browse the repository at this point in the history
#2348)

Co-authored-by: Chris Bush <chris.bush@10gen.com>
  • Loading branch information
dacharyc and cbush committed Dec 1, 2022
1 parent 475fa23 commit ba11b09
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 39 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

2 changes: 1 addition & 1 deletion examples/cpp/.gitignore
Expand Up @@ -10,4 +10,4 @@ compile_commands.json
CTestTestfile.cmake
_deps
build/

build.*
11 changes: 7 additions & 4 deletions examples/cpp/CMakeLists.txt
Expand Up @@ -2,9 +2,7 @@ cmake_minimum_required(VERSION 3.15)

project(examples)

set(CMAKE_CXX_STANDARD 20)

add_subdirectory(realm-cpp)
set(CMAKE_CXX_STANDARD 17)

Include(FetchContent)

Expand All @@ -13,8 +11,13 @@ FetchContent_Declare(
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.0.1 # or a later release
)
FetchContent_Declare(
cpprealm
GIT_REPOSITORY https://github.com/realm/realm-cpp.git
GIT_TAG f4f89d1c75d4c762a679f57d2e9f26e87ec1215b
)

FetchContent_MakeAvailable(Catch2)
FetchContent_MakeAvailable(Catch2 cpprealm)

add_executable(examples examples.cpp)
target_link_libraries(examples PRIVATE Catch2::Catch2WithMain)
Expand Down
49 changes: 19 additions & 30 deletions examples/cpp/README.md
Expand Up @@ -12,15 +12,6 @@ If you just want to run the tests, go to **Run the Tests**.

## First-time Setup

This project uses the Realm CPP SDK as a git submodule. You must ensure
your machine has access to the version of the submodule used in the project.
To pull in the submodule and its dependencies, from this `/examples/cpp`
directory:

```shell
git submodule update --init --recursive
```

The project uses [CMake](https://cmake.org/) to create build files (Makefile, .xcodeproj...) for the
project. To check if you have CMake installed:

Expand Down Expand Up @@ -78,41 +69,39 @@ To run the tests, from the `build` directory:

## Update the Realm SDK Version

Enter the submodule directory:
CMakeLists.txt has a FetchContent block that pulls in the realm-cpp repository
code as a dependency, and compiles it:

```shell
cd realm-cpp
FetchContent_Declare(
cpprealm
GIT_REPOSITORY https://github.com/realm/realm-cpp.git
GIT_TAG f4f89d1c75d4c762a679f57d2e9f26e87ec1215b
)
```

You're now in a remote of `realm-cpp`. Use regular `git` commands to fetch
the version of the repository that you want to use.
To change the version of the SDK we use in the build, change the value
of the `GIT_TAG`. While in early Alpha, this is a commit hash, but it could
be a version tag once the SDK starts doing tagged releases. For more
information, refer to the
[FetchContent Module docs](https://cmake.org/cmake/help/latest/module/FetchContent.html).

Alternately, if you don't want to get a specific version of the `realm-cpp`
repo, but just want to update it to the latest commit, you can:

```shell
git submodule update --remote
```
For best results, delete everything in the `build` folder. Then create
a new Makefile and build the project again before running the tests.

Then, when you `cd` back out of the `realm-cpp` directory and check the
git status, you should see:
From `/examples/cpp/build`, run `cmake` to create a Makefile by reading the
`CMakeLists.txt` in the parent directory.

```shell
modified: realm-cpp (new commits, modified content)
cmake ../
```

Add and commit these changes like you would any other changes. This preserves
the HEAD of the submodule.

To use the updated repository in the CPP examples project:
You can `ls` to see that a Makefile has been generated. Then, build the app:

```shell
git submodule update --init --recursive
make
```

For best results, delete everything in the `build` folder and then build
the project again before running the tests.

## Add a New Test File

To add a new test file, create a file with a `.cpp` extension in `examples/cpp/`.
Expand Down
1 change: 0 additions & 1 deletion examples/cpp/realm-cpp
Submodule realm-cpp deleted from f13f5e

0 comments on commit ba11b09

Please sign in to comment.