diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..c1ef0e8a --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# CMake +.ninja_deps +.ninja_log +CMakeCache.txt +CMakeFiles/ +Makefile +build.ninja +cmake_install.cmake +rules.ninja + +# Build products +librealm-object-store.dylib diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..b7e77b91 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "external/pegtl"] + path = external/pegtl + url = https://github.com/ColinH/PEGTL diff --git a/CMake/CompilerFlags.cmake b/CMake/CompilerFlags.cmake new file mode 100644 index 00000000..a5a6bd36 --- /dev/null +++ b/CMake/CompilerFlags.cmake @@ -0,0 +1,10 @@ +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED on) +set(CMAKE_CXX_EXTENSIONS off) +set(CMAKE_BUILD_TYPE CACHE STRING Debug) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") + +if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" AND ${CMAKE_GENERATOR} STREQUAL "Ninja") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcolor-diagnostics") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics") +endif() diff --git a/CMake/RealmCore.cmake b/CMake/RealmCore.cmake new file mode 100644 index 00000000..45a5beff --- /dev/null +++ b/CMake/RealmCore.cmake @@ -0,0 +1,28 @@ +include(ExternalProject) + +function(download_realm_core realm_core_version) + set(core_url "https://static.realm.io/downloads/core/realm-core-${realm_core_version}.tar.bz2") + set(core_directory "${CMAKE_CURRENT_SOURCE_DIR}${CMAKE_FILES_DIRECTORY}/core-${realm_core_version}") + + set(core_library_debug ${core_directory}/librealm-dbg.a) + set(core_library_release ${core_directory}/librealm.a) + + ExternalProject_Add(realm-core + URL ${core_url} + PREFIX ${CMAKE_CURRENT_SOURCE_DIR}${CMAKE_FILES_DIRECTORY}/realm-core + DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}${CMAKE_FILES_DIRECTORY} + SOURCE_DIR ${core_directory} + BUILD_BYPRODUCTS ${core_library_debug} ${core_library_release} + USES_TERMINAL_DOWNLOAD 1 + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "") + + add_library(realm STATIC IMPORTED) + add_dependencies(realm realm-core) + set_property(TARGET realm PROPERTY IMPORTED_LOCATION_DEBUG ${core_library_debug}) + set_property(TARGET realm PROPERTY IMPORTED_LOCATION_RELEASE ${core_library_release}) + set_property(TARGET realm PROPERTY IMPORTED_LOCATION ${core_library_release}) + + set(REALM_CORE_INCLUDE_DIR ${core_directory}/include PARENT_SCOPE) +endfunction() diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..539960b7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,32 @@ +project(realm-object-store) + +cmake_minimum_required(VERSION 3.4.0) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake") + +include(CompilerFlags) + +include(RealmCore) +download_realm_core(0.95.5) + +include_directories(${REALM_CORE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} impl external/pegtl) + +set(SOURCES + index_set.cpp + list.cpp + object_schema.cpp + object_store.cpp + results.cpp + schema.cpp + shared_realm.cpp + impl/transact_log_handler.cpp + parser/parser.cpp + parser/query_builder.cpp) + +if(APPLE) + include_directories(impl/apple) + list(APPEND SOURCES impl/apple/external_commit_helper.cpp) + find_library(CF_LIBRARY CoreFoundation) +endif() + +add_library(realm-object-store SHARED ${SOURCES}) +target_link_libraries(realm-object-store realm ${CF_LIBRARY}) diff --git a/external/pegtl b/external/pegtl new file mode 160000 index 00000000..49a5b0a4 --- /dev/null +++ b/external/pegtl @@ -0,0 +1 @@ +Subproject commit 49a5b0a49e154b362ef9cf1e756dd8673ddd4efe