From 8c56d1338217ef337b970572ed89ffa23d86c567 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Wed, 2 Mar 2016 00:21:43 -0800 Subject: [PATCH 1/3] Support building on Linux. By default, Linux uses a locally-built version of core that is prepared in an independent working copy of the realm-core git repository. Support is also added for using an existing local build of core on both OS X and Linux . This can be done by running `cmake -DREALM_CORE_VERSION=/path/to/realm-core`. The generated build system will invoke `sh build.sh build` within the given directory prior to building the object store. --- .gitignore | 2 +- CMake/RealmCore.cmake | 92 ++++++++++++++++++++++++++++++++++++++++++- CMakeLists.txt | 3 +- 3 files changed, 94 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7d9b2fa3..59c6c914 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,5 @@ cmake_install.cmake rules.ninja # Build products -librealm-object-store.dylib +src/librealm-object-store.* tests/tests diff --git a/CMake/RealmCore.cmake b/CMake/RealmCore.cmake index fa020932..be602e20 100644 --- a/CMake/RealmCore.cmake +++ b/CMake/RealmCore.cmake @@ -1,5 +1,26 @@ include(ExternalProject) +if(${CMAKE_GENERATOR} STREQUAL "Unix Makefiles") + set(MAKE_EQUAL_MAKE "MAKE=$(MAKE)") +endif() + +if (${CMAKE_VERSION} VERSION_GREATER "3.4.0") + set(USES_TERMINAL_BUILD USES_TERMINAL_BUILD 1) +endif() + +function(use_realm_core version_or_path_to_source) + if("${version_or_path_to_source}" MATCHES "^[0-9]+(\\.[0-9])+") + if(APPLE) + download_realm_core(${version_or_path_to_source}) + else() + clone_and_build_realm_core("v${version_or_path_to_source}") + endif() + else() + build_existing_realm_core(${version_or_path_to_source}) + endif() + set(REALM_CORE_INCLUDE_DIR ${REALM_CORE_INCLUDE_DIR} PARENT_SCOPE) +endfunction() + 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") @@ -10,7 +31,7 @@ function(download_realm_core core_version) if (NOT EXISTS ${core_tarball}) if (NOT EXISTS ${core_temp_tarball}) - message("Downloading core ${core_version} from ${core_url}.") + 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() @@ -40,3 +61,72 @@ function(download_realm_core core_version) set(REALM_CORE_INCLUDE_DIR ${core_directory}/include PARENT_SCOPE) endfunction() + +function(clone_and_build_realm_core branch) + set(core_prefix_directory "${CMAKE_CURRENT_SOURCE_DIR}${CMAKE_FILES_DIRECTORY}/realm-core") + ExternalProject_Add(realm-core + GIT_REPOSITORY "git@github.com:realm/realm-core.git" + GIT_TAG ${branch} + PREFIX ${core_prefix_directory} + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND "" + BUILD_COMMAND ${MAKE_EQUAL_MAKE} sh build.sh build + INSTALL_COMMAND "" + ${USES_TERMINAL_BUILD} + ) + + ExternalProject_Get_Property(realm-core SOURCE_DIR) + set(core_directory ${SOURCE_DIR}) + set(core_library_debug ${core_directory}/src/realm/librealm-dbg${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(core_library_release ${core_directory}/src/realm/librealm${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(core_libraries ${core_library_debug} ${core_library_release}) + + ExternalProject_Add_Step(realm-core ensure-libraries + COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${core_libraries} + OUTPUT ${core_libraries} + DEPENDEES build + ) + + add_library(realm SHARED 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}/src PARENT_SCOPE) +endfunction() + +function(build_existing_realm_core core_directory) + get_filename_component(core_directory ${core_directory} ABSOLUTE) + ExternalProject_Add(realm-core + URL "" + PREFIX ${CMAKE_CURRENT_SOURCE_DIR}${CMAKE_FILES_DIRECTORY}/realm-core + SOURCE_DIR ${core_directory} + BUILD_IN_SOURCE 1 + BUILD_ALWAYS 1 + CONFIGURE_COMMAND "" + BUILD_COMMAND ${MAKE_EQUAL_MAKE} sh build.sh build + INSTALL_COMMAND "" + ${USES_TERMINAL_BUILD} + ) + + set(core_library_debug ${core_directory}/src/realm/librealm-dbg${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(core_library_release ${core_directory}/src/realm/librealm${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(core_libraries ${core_library_debug} ${core_library_release}) + + ExternalProject_Add_Step(realm-core ensure-libraries + COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${core_libraries} + OUTPUT ${core_libraries} + DEPENDEES build + ) + + add_library(realm SHARED 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}/src PARENT_SCOPE) +endfunction() diff --git a/CMakeLists.txt b/CMakeLists.txt index e0441f49..39b30790 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake") include(CompilerFlags) include(RealmCore) -download_realm_core(0.96.2) +set(REALM_CORE_VERSION "0.96.2" CACHE STRING "") +use_realm_core(${REALM_CORE_VERSION}) include_directories(${REALM_CORE_INCLUDE_DIR} src external/pegtl) From ccdc3b07540ece813ed10acc1db0062342b25079 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Wed, 2 Mar 2016 00:21:55 -0800 Subject: [PATCH 2/3] Add info to the README about using a local build of core. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 948a47e6..a641cb36 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,14 @@ platforms when integrated into a binding. make ``` +If you wish to build against a local version of core you can invoke `cmake` like so: + +``` +cmake -DREALM_CORE_VERSION=/path/to/realm-core +``` + +The given core tree will be built as part of the object store build. + ## Testing ``` From 3602cf7588aaf4ea8ef2796ed9a522ec25551440 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Wed, 2 Mar 2016 01:16:11 -0800 Subject: [PATCH 3/3] Factor duplicated logic out into a macro. --- CMake/RealmCore.cmake | 52 ++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/CMake/RealmCore.cmake b/CMake/RealmCore.cmake index be602e20..76072544 100644 --- a/CMake/RealmCore.cmake +++ b/CMake/RealmCore.cmake @@ -62,21 +62,7 @@ function(download_realm_core core_version) set(REALM_CORE_INCLUDE_DIR ${core_directory}/include PARENT_SCOPE) endfunction() -function(clone_and_build_realm_core branch) - set(core_prefix_directory "${CMAKE_CURRENT_SOURCE_DIR}${CMAKE_FILES_DIRECTORY}/realm-core") - ExternalProject_Add(realm-core - GIT_REPOSITORY "git@github.com:realm/realm-core.git" - GIT_TAG ${branch} - PREFIX ${core_prefix_directory} - BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND "" - BUILD_COMMAND ${MAKE_EQUAL_MAKE} sh build.sh build - INSTALL_COMMAND "" - ${USES_TERMINAL_BUILD} - ) - - ExternalProject_Get_Property(realm-core SOURCE_DIR) - set(core_directory ${SOURCE_DIR}) +macro(define_built_realm_core_target core_directory) set(core_library_debug ${core_directory}/src/realm/librealm-dbg${CMAKE_SHARED_LIBRARY_SUFFIX}) set(core_library_release ${core_directory}/src/realm/librealm${CMAKE_SHARED_LIBRARY_SUFFIX}) set(core_libraries ${core_library_debug} ${core_library_release}) @@ -95,6 +81,23 @@ function(clone_and_build_realm_core branch) set_property(TARGET realm PROPERTY IMPORTED_LOCATION ${core_library_release}) set(REALM_CORE_INCLUDE_DIR ${core_directory}/src PARENT_SCOPE) +endmacro() + +function(clone_and_build_realm_core branch) + set(core_prefix_directory "${CMAKE_CURRENT_SOURCE_DIR}${CMAKE_FILES_DIRECTORY}/realm-core") + ExternalProject_Add(realm-core + GIT_REPOSITORY "git@github.com:realm/realm-core.git" + GIT_TAG ${branch} + PREFIX ${core_prefix_directory} + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND "" + BUILD_COMMAND ${MAKE_EQUAL_MAKE} sh build.sh build + INSTALL_COMMAND "" + ${USES_TERMINAL_BUILD} + ) + + ExternalProject_Get_Property(realm-core SOURCE_DIR) + define_built_realm_core_target(${SOURCE_DIR}) endfunction() function(build_existing_realm_core core_directory) @@ -111,22 +114,5 @@ function(build_existing_realm_core core_directory) ${USES_TERMINAL_BUILD} ) - set(core_library_debug ${core_directory}/src/realm/librealm-dbg${CMAKE_SHARED_LIBRARY_SUFFIX}) - set(core_library_release ${core_directory}/src/realm/librealm${CMAKE_SHARED_LIBRARY_SUFFIX}) - set(core_libraries ${core_library_debug} ${core_library_release}) - - ExternalProject_Add_Step(realm-core ensure-libraries - COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${core_libraries} - OUTPUT ${core_libraries} - DEPENDEES build - ) - - add_library(realm SHARED 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}/src PARENT_SCOPE) + define_built_realm_core_target(${core_directory}) endfunction()