Skip to content

Commit

Permalink
RCPP-41 Add Conan support (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
leemaguire authored Mar 22, 2024
1 parent bf3237c commit 4cd8034
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 98 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ jobs:
- uses: ammaraskar/msvc-problem-matcher@master

- name: Configure
run: cmake --preset windows-x64
run: cmake --preset windows-x64 -DENABLE_STATIC=1

- name: Compile
run: cmake --build --preset windows-x64 --config ${{ matrix.configuration }}
Expand Down Expand Up @@ -472,7 +472,7 @@ jobs:
- uses: ammaraskar/msvc-problem-matcher@master

- name: Configure
run: cmake --preset windows-x64
run: cmake --preset windows-x64 -DENABLE_STATIC=1

- name: Compile
run: cmake --build --preset windows-x64 --config ${{ matrix.configuration }}
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/conan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Test Conan integration

on:
push:
branches:
- main
pull_request:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
build_type: [Debug, Release]
linkage_is_dynamic: ["True", "False"]

steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: 'recursive'

- name: Install Conan
id: conan
uses: turtlebrowser/get-conan@main

- name: Conan version
run: echo "${{ steps.conan.outputs.version }}"

- name: Conan profile detect
working-directory: .
run: |
conan profile detect
- name: Update Conan profile
if: matrix.os == 'windows-latest'
run: |
$profilePath = "$env:USERPROFILE\.conan2\profiles\default"
$content = Get-Content -Path $profilePath
$content = $content -replace 'compiler.cppstd=14', 'compiler.cppstd=17'
$content | Set-Content -Path $profilePath
- name: Conan create
working-directory: .
run: |
conan create . -tf="tests" -s build_type=${{ matrix.build_type }} -o shared=${{ matrix.linkage_is_dynamic }} --build=missing
- name: Open a tmate debug session
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
with:
timeout-minutes: 15
40 changes: 20 additions & 20 deletions .github/workflows/vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,26 @@ jobs:
uses: seanmiddleditch/gha-setup-ninja@master

- name: Configure and build (macOS)
working-directory: ./tests/vcpkg
working-directory: ./tests
if: matrix.os == 'macos-latest'
run: |
cmake -GNinja -B build -S . -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=x64-osx
cmake -GNinja -B build -S . -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=x64-osx
cd build
cmake --build . --config ${{matrix.build_type}}
- name: Configure and build (Ubuntu)
working-directory: ./tests/vcpkg
working-directory: ./tests
if: matrix.os == 'ubuntu-latest'
run: |
cmake -GNinja -B build -S . -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=x64-linux
cmake -GNinja -B build -S . -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=x64-linux
cd build
cmake --build . --config ${{matrix.build_type}}
- name: Configure and build (Windows)
working-directory: ./tests/vcpkg
working-directory: ./tests
if: matrix.os == 'windows-latest'
run: |
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=x64-windows-static -DENABLE_STATIC=ON
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=x64-windows-static -DENABLE_STATIC=ON
cd build
cmake --build . --config ${{matrix.build_type}}
Expand All @@ -68,17 +68,17 @@ jobs:
timeout-minutes: 15

- name: Run Application (Unix)
working-directory: ./tests/vcpkg/build
working-directory: ./tests/build
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
run: |
./realm_helloworld
./cpprealm_db_tests
- name: Run Application (Windows)
working-directory: ./tests/vcpkg/build
working-directory: ./tests/build
if: matrix.os == 'windows-latest'
run: |
cd ${{matrix.build_type}}
start realm_helloworld.exe
start cpprealm_db_tests.exe
build-dynamic:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -111,41 +111,41 @@ jobs:
uses: seanmiddleditch/gha-setup-ninja@master

- name: Configure and build (macOS)
working-directory: ./tests/vcpkg
working-directory: ./tests
if: matrix.os == 'macos-latest'
run: |
cmake -GNinja -B build -S . -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=x64-osx-dynamic
cmake -GNinja -B build -S . -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=x64-osx-dynamic
cd build
cmake --build . --config ${{matrix.build_type}}
- name: Configure and build (Ubuntu)
working-directory: ./tests/vcpkg
working-directory: ./tests
if: matrix.os == 'ubuntu-latest'
run: |
cmake -GNinja -B build -S . -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=x64-linux-dynamic
cmake -GNinja -B build -S . -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=x64-linux-dynamic
cd build
cmake --build . --config ${{matrix.build_type}}
- name: Configure and build (Windows)
working-directory: ./tests/vcpkg
working-directory: ./tests
if: matrix.os == 'windows-latest'
run: |
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=x64-windows
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=x64-windows
cd build
cmake --build . --config ${{matrix.build_type}}
- name: Run Application (Unix)
working-directory: ./tests/vcpkg/build
working-directory: ./tests/build
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
run: |
./realm_helloworld
./cpprealm_db_tests
- name: Run Application (Windows)
working-directory: ./tests/vcpkg/build
working-directory: ./tests/build
if: matrix.os == 'windows-latest'
run: |
cd ${{matrix.build_type}}
start realm_helloworld.exe
start cpprealm_db_tests.exe
- name: Open a tmate debug session
if: ${{ failure() }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ X.Y.Z Release notes (YYYY-MM-DD)
* Add compile time checking to prevent misuse of managed property types.
* Add `managed<std::vector<>>::as_results()` to allow the ability to derive a `realm::results<>` collection from a managed vector.
* Allow a `realm::uuid` to be constructed with `std::array<uint8_t, 16>`.
* Add support for integrating `cpprealm` with the Conan package manager.

### Breaking Changes
* None
Expand Down
20 changes: 12 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ target_include_directories(${PROJECT_NAME}
if(NOT APPLE AND NOT WINDOWS_STORE AND NOT ANDROID)
if(VCPKG_TOOLCHAIN)
find_package(libuv CONFIG REQUIRED)
if (BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
set(libuv_target libuv::uv)
else()
set(libuv_target libuv::uv_a)
endif()
elseif(DEFINED USES_CONAN)
find_package(libuv REQUIRED)
set(libuv_target ${libuv_LIBRARIES})
else()
option(REALM_FETCH_MISSING_DEPENDENCIES "Download missing dependencies with CMake's FetchContent where possible" ON)
if(REALM_FETCH_MISSING_DEPENDENCIES)
Expand All @@ -81,10 +84,7 @@ if(NOT APPLE AND NOT WINDOWS_STORE AND NOT ANDROID)
elseif(REALM_FETCH_MISSING_DEPENDENCIES)
message(STATUS "LibUV not found, building from source with FetchContent")
include(FetchContent)
set(libUV_Git_TAG "v1.35.0")
if(MSVC)
set(liUV_Git_TAG "v1.43.0")
endif()
set(libUV_Git_TAG "v1.48.0")
FetchContent_Declare(
libuv
GIT_REPOSITORY https://github.com/libuv/libuv.git
Expand All @@ -104,7 +104,7 @@ endif()
target_link_libraries(cpprealm PUBLIC Realm::ObjectStore)
set(CMAKE_OSX_SYSROOT ${CMAKE_OSX_SYSROOT_PATH})

if (APPLE)
if(APPLE)
target_sources(cpprealm PRIVATE src/cpprealm/internal/apple/network_transport.mm)
elseif(ANDROID)
set(REALM_ANDROID)
Expand All @@ -127,7 +127,12 @@ else()
endif()

if(MSVC AND NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
if(NOT BUILD_SHARED_LIBS)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set_property(TARGET cpprealm PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set_property(TARGET uv_a PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endif()

install(EXPORT "${PROJECT_NAME}Targets"
Expand Down Expand Up @@ -170,7 +175,6 @@ if (BUILD_SHARED_LIBS)
endif()
endif()


if (NOT REALM_CPP_NO_TESTS)
add_subdirectory(tests)
endif()
74 changes: 74 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from conan import ConanFile
from conan.tools.build import check_min_cppstd, can_run
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.scm import Git

class cpprealmRecipe(ConanFile):
name = "cpprealm"
version = "1.0"

# Optional metadata
license = "Apache-2.0"
url = "https://github.com/realm/realm-cpp"
description = "Realm is a mobile database that runs directly inside phones, tablets or wearables."

# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False]}
default_options = {"shared": False}

def is_darwin(self):
return self.settings.os == "Macos" or self.settings.os == "iOS" or self.settings.os == "watchOS"

def validate(self):
check_min_cppstd(self, "17")

def requirements(self):
self.requires(self.tested_reference_str)
if not self.is_darwin() and not self.settings.os == "Emscripten":
self.requires("zlib/1.3")
if not self.is_darwin():
self.requires("openssl/3.2.0")
self.requires("libuv/1.48.0")
if self.settings.os == "Linux":
self.requires("libcurl/8.4.0")
def source(self):
git = Git(self)
git.clone(url="https://github.com/realm/realm-cpp", target=".")
git.folder = "."
git.checkout(commit="507162c8036ff91b5726bdd4d7efbb9d3f5539bc")
git.run("submodule update --init --recursive")

def layout(self):
cmake_layout(self)

def generate(self):
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.variables["USES_CONAN"] = "ON"
tc.variables["REALM_CPP_NO_TESTS"] = "ON"
tc.variables["REALM_CORE_SUBMODULE_BUILD"] = "ON"
tc.variables["REALM_USE_SYSTEM_OPENSSL"] = "ON"
if self.settings.os == "Windows":
self.cpp_info.cxxflags = ["/Zc:preprocessor /bigobj"]
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
cmake = CMake(self)
cmake.install()

def package_info(self):
if self.settings.build_type == "Debug":
self.cpp_info.libs = ["cpprealm-dbg", "realm-object-store-dbg", "realm-parser-dbg", "realm-sync-dbg", "realm-dbg"]
else:
self.cpp_info.libs = ["cpprealm", "realm-object-store", "realm-parser", "realm-sync", "realm"]
if self.is_darwin():
self.cpp_info.frameworks = ["Foundation", "Security", "Compression", "z"]
if self.settings.os == "Windows":
self.cpp_info.system_libs = ["Version"]
2 changes: 2 additions & 0 deletions src/cpprealm/notifications.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ struct notification_token {
m_token = std::move(other.m_token);
m_dictionary = std::move(other.m_dictionary);
m_list = std::move(other.m_list);
m_set = std::move(other.m_set);
m_results = std::move(other.m_results);
m_realm = std::move(other.m_realm);
};
notification_token &operator=(notification_token &&other) {
m_token = std::move(other.m_token);
m_dictionary = std::move(other.m_dictionary);
m_list = std::move(other.m_list);
m_set = std::move(other.m_set);
m_results = std::move(other.m_results);
m_realm = std::move(other.m_realm);
return *this;
Expand Down
Loading

0 comments on commit 4cd8034

Please sign in to comment.