From ba11b099cf8ede8c11357400bf2e026207639e87 Mon Sep 17 00:00:00 2001 From: Dachary Date: Thu, 1 Dec 2022 17:05:34 -0500 Subject: [PATCH] (DOCSP-26811): Remove cpprealm git submodule, use FetchContent instead (#2348) Co-authored-by: Chris Bush --- .gitmodules | 3 --- examples/cpp/.gitignore | 2 +- examples/cpp/CMakeLists.txt | 11 ++++++--- examples/cpp/README.md | 49 ++++++++++++++----------------------- examples/cpp/realm-cpp | 1 - 5 files changed, 27 insertions(+), 39 deletions(-) delete mode 100644 .gitmodules delete mode 160000 examples/cpp/realm-cpp diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 885632cf53..0000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "examples/cpp/realm-cpp"] - path = examples/cpp/realm-cpp - url = git@github.com:realm/realm-cpp.git diff --git a/examples/cpp/.gitignore b/examples/cpp/.gitignore index 554b2d8b40..0eb3a48987 100644 --- a/examples/cpp/.gitignore +++ b/examples/cpp/.gitignore @@ -10,4 +10,4 @@ compile_commands.json CTestTestfile.cmake _deps build/ - +build.* diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index 4e2a7e0b80..a5d1394a10 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -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) @@ -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) diff --git a/examples/cpp/README.md b/examples/cpp/README.md index 35d4601dcd..45c743ee34 100644 --- a/examples/cpp/README.md +++ b/examples/cpp/README.md @@ -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: @@ -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/`. diff --git a/examples/cpp/realm-cpp b/examples/cpp/realm-cpp deleted file mode 160000 index f13f5e54cb..0000000000 --- a/examples/cpp/realm-cpp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f13f5e54cb13ba22874b3339a9db288ae0feaedd