Merge pull request #33 from realm/mar/cmake

Add a CMake build system
This commit is contained in:
Mark Rowe 2016-01-20 15:48:53 -08:00
commit 415bfe4d35
39 changed files with 156 additions and 37 deletions

13
.gitignore vendored Normal file
View File

@ -0,0 +1,13 @@
# CMake
.ninja_deps
.ninja_log
CMakeCache.txt
CMakeFiles/
Makefile
build.ninja
cmake_install.cmake
rules.ninja
# Build products
librealm-object-store.dylib
tests/tests

6
.gitmodules vendored Normal file
View File

@ -0,0 +1,6 @@
[submodule "external/pegtl"]
path = external/pegtl
url = https://github.com/ColinH/PEGTL
[submodule "external/catch"]
path = external/catch
url = https://github.com/philsquared/Catch

15
CMake/CompilerFlags.cmake Normal file
View File

@ -0,0 +1,15 @@
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_GENERATOR} STREQUAL "Ninja")
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcolor-diagnostics")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=always")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
endif()
endif()

43
CMake/RealmCore.cmake Normal file
View File

@ -0,0 +1,43 @@
include(ExternalProject)
function(download_realm_core core_version)
set(core_url "https://static.realm.io/downloads/core/realm-core-${core_version}.tar.bz2")
set(core_tarball_name "realm-core-${core_version}.tar.bz2")
set(core_temp_tarball "/tmp/${core_tarball_name}")
set(core_directory_parent "${CMAKE_CURRENT_SOURCE_DIR}${CMAKE_FILES_DIRECTORY}")
set(core_directory "${core_directory_parent}/realm-core-${core_version}")
set(core_tarball "${core_directory_parent}/${core_tarball_name}")
if (NOT EXISTS ${core_tarball})
if (NOT EXISTS ${core_temp_tarball})
message("Downloading core ${core_version} from ${core_url}.")
file(DOWNLOAD ${core_url} ${core_temp_tarball}.tmp SHOW_PROGRESS)
file(RENAME ${core_temp_tarball}.tmp ${core_temp_tarball})
endif()
file(COPY ${core_temp_tarball} DESTINATION ${core_directory_parent})
endif()
set(core_library_debug ${core_directory}/librealm-dbg.a)
set(core_library_release ${core_directory}/librealm.a)
set(core_libraries ${core_library_debug} ${core_library_release})
add_custom_command(
COMMENT "Extracting ${core_tarball_name}"
OUTPUT ${core_libraries}
DEPENDS ${core_temp_tarball}
COMMAND ${CMAKE_COMMAND} -E copy ${core_temp_tarball} ${core_directory_parent}
COMMAND ${CMAKE_COMMAND} -E tar xf ${core_tarball}
COMMAND ${CMAKE_COMMAND} -E remove_directory ${core_directory}
COMMAND ${CMAKE_COMMAND} -E rename core ${core_directory}
COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${core_libraries})
add_custom_target(realm-core DEPENDS ${core_libraries})
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()

14
CMakeLists.txt Normal file
View File

@ -0,0 +1,14 @@
project(realm-object-store)
cmake_minimum_required(VERSION 3.2.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} src external/pegtl)
add_subdirectory(src)
add_subdirectory(tests)

View File

@ -1,6 +1,6 @@
# Realm Object Store # Realm Object Store
Cross-platform code used accross bindings. Binding developers can choose to use some or all the included functionality Cross-platform code used accross bindings. Binding developers can choose to use some or all the included functionality:
- `object_store`/`schema`/`object_schema`/`property` - contains the structures and logic used to setup and modify realm files and their schema. - `object_store`/`schema`/`object_schema`/`property` - contains the structures and logic used to setup and modify realm files and their schema.
- `shared_realm` - wraps the object_store apis to provide transactions, notifications, realm caching, migrations, and other higher level functionality. - `shared_realm` - wraps the object_store apis to provide transactions, notifications, realm caching, migrations, and other higher level functionality.
- `object_accessor`/`results`/`list` - accessor classes, object creation/update pipeline, and helpers for creating platform specific property getters and setters. - `object_accessor`/`results`/`list` - accessor classes, object creation/update pipeline, and helpers for creating platform specific property getters and setters.
@ -8,8 +8,28 @@ Cross-platform code used accross bindings. Binding developers can choose to use
## Building ## Building
TBD The object store's build system currently only suports building for OS X. The object store itself can build for all Apple
platforms when integrated into a binding.
1. Install CMake. You can download an installer for OS X from the [CMake download page], or install via [Homebrew](http://brew.sh):
```
brew install cmake
```
2. Generate build files:
```
cmake .
```
3. Build:
```
make
```
## Testing ## Testing
TBD ```
make run-tests
```

1
external/catch vendored Submodule

@ -0,0 +1 @@
Subproject commit f294c9847272b1b92c5119a6f711e57113b5f231

1
external/pegtl vendored Submodule

@ -0,0 +1 @@
Subproject commit 49a5b0a49e154b362ef9cf1e756dd8673ddd4efe

22
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,22 @@
include_directories(impl)
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})

View File

@ -25,7 +25,6 @@
#include <vector> #include <vector>
namespace realm { namespace realm {
class Property;
class Group; class Group;
struct Property; struct Property;

5
tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,5 @@
include_directories(../external/catch/single_include)
add_executable(tests main.cpp parser.cpp)
target_link_libraries(tests realm-object-store)
add_custom_target(run-tests USES_TERMINAL DEPENDS tests COMMAND ./tests)

2
tests/main.cpp Normal file
View File

@ -0,0 +1,2 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

View File

@ -1,10 +1,8 @@
#include "catch.hpp"
#include "parser.hpp" #include "parser/parser.hpp"
#include <vector> #include <vector>
#include <string> #include <string>
#include <exception>
#include <iostream>
static std::vector<std::string> valid_queries = { static std::vector<std::string> valid_queries = {
// true/false predicates // true/false predicates
@ -131,36 +129,16 @@ static std::vector<std::string> invalid_queries = {
"truepredicate & truepredicate", "truepredicate & truepredicate",
}; };
namespace realm { TEST_CASE("valid queries") {
namespace parser {
bool test_grammar()
{
bool success = true;
for (auto& query : valid_queries) { for (auto& query : valid_queries) {
std::cout << "valid query: " << query << std::endl; INFO("query: " << query);
try { CHECK_NOTHROW(realm::parser::parse(query));
realm::parser::parse(query);
} catch (std::exception &ex) {
std::cout << "FAILURE - " << ex.what() << std::endl;
success = false;
} }
} }
TEST_CASE("invalid queries") {
for (auto& query : invalid_queries) { for (auto& query : invalid_queries) {
std::cout << "invalid query: " << query << std::endl; INFO("query: " << query);
try { CHECK_THROWS(realm::parser::parse(query));
realm::parser::parse(query);
} catch (std::exception &ex) {
// std::cout << "message: " << ex.what() << std::endl;
continue;
}
std::cout << "FAILURE - query should throw an exception" << std::endl;
success = false;
}
return success;
}
} }
} }