From f19bab76bd3dd9602d9f1e2e9fa8b96c60d9d57a Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Tue, 1 Mar 2016 21:26:02 -0800 Subject: [PATCH] Build both dynamic and static libraries. The dynamic library makes it easy to verify that there are no linker errors when building the object store, while the static library is easier for a binding to consume. This also tweaks how the library targets are defined to ensure that other CMake projects that pull in the libraries automatically get the right include paths and link to the appropriate libraries. --- .gitignore | 3 ++- CMakeLists.txt | 2 +- src/CMakeLists.txt | 19 +++++++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 59c6c914..3ea88b23 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,6 @@ cmake_install.cmake rules.ninja # Build products -src/librealm-object-store.* +src/librealm-object-store.dylib +src/librealm-object-store-static.a tests/tests diff --git a/CMakeLists.txt b/CMakeLists.txt index 286e6ff0..e476b64c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ include(RealmCore) set(REALM_CORE_VERSION "0.100.1" CACHE STRING "") use_realm_core(${REALM_CORE_VERSION}) -include_directories(${REALM_CORE_INCLUDE_DIR} src external/pegtl) +set(PEGTL_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/pegtl) add_subdirectory(src) add_subdirectory(tests) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8f849049..3574147e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,5 +55,20 @@ else() impl/generic/external_commit_helper.hpp) endif() -add_library(realm-object-store SHARED ${SOURCES} ${HEADERS}) -target_link_libraries(realm-object-store realm ${CF_LIBRARY}) +set(INCLUDE_DIRS ${REALM_CORE_INCLUDE_DIR} ${PEGTL_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) + +# An object library to group together the compilation of the source files. +add_library(realm-object-store-objects OBJECT ${SOURCES} ${HEADERS}) +add_dependencies(realm-object-store-objects realm) +set_target_properties(realm-object-store-objects PROPERTIES POSITION_INDEPENDENT_CODE 1) +target_include_directories(realm-object-store-objects PUBLIC ${INCLUDE_DIRS}) + +# A static library, aggregating the prebuilt object files. +add_library(realm-object-store-static STATIC $) +target_include_directories(realm-object-store-static PUBLIC ${INCLUDE_DIRS}) +target_link_libraries(realm-object-store-static PUBLIC realm ${CF_LIBRARY}) + +# A dynamic library, linking together the prebuilt object files. +add_library(realm-object-store SHARED $) +target_include_directories(realm-object-store PUBLIC ${INCLUDE_DIRS}) +target_link_libraries(realm-object-store PRIVATE realm ${CF_LIBRARY})