2016-01-06 22:40:53 +00:00
|
|
|
include(ExternalProject)
|
|
|
|
|
2016-03-02 08:21:43 +00:00
|
|
|
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()
|
|
|
|
|
2016-01-07 01:03:27 +00:00
|
|
|
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})
|
2016-03-02 08:21:43 +00:00
|
|
|
message("Downloading core ${core_version} from ${core_url}.")
|
2016-01-07 01:03:27 +00:00
|
|
|
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()
|
2016-01-06 22:40:53 +00:00
|
|
|
|
|
|
|
set(core_library_debug ${core_directory}/librealm-dbg.a)
|
|
|
|
set(core_library_release ${core_directory}/librealm.a)
|
2016-01-07 01:03:27 +00:00
|
|
|
set(core_libraries ${core_library_debug} ${core_library_release})
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
COMMENT "Extracting ${core_tarball_name}"
|
|
|
|
OUTPUT ${core_libraries}
|
2016-02-18 23:28:51 +00:00
|
|
|
DEPENDS ${core_tarball}
|
2016-01-07 01:03:27 +00:00
|
|
|
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})
|
2016-01-06 22:40:53 +00:00
|
|
|
|
2016-01-07 01:03:27 +00:00
|
|
|
add_custom_target(realm-core DEPENDS ${core_libraries})
|
2016-01-06 22:40:53 +00:00
|
|
|
|
|
|
|
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()
|
2016-03-02 08:21:43 +00:00
|
|
|
|
|
|
|
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()
|