|
1 |
| -cmake_minimum_required(VERSION 3.5) |
| 1 | +cmake_minimum_required(VERSION 3.5) |
2 | 2 | # 3.5: Since CMake 3.27 VERSION < 3.5 produce a deprecation warning.
|
3 | 3 |
|
4 |
| -project(ObjectBoxCRoot) # to be displayed in an IDE when this CMake is opened |
| 4 | +# This CMake file has the following purposes: |
| 5 | +# * Define the ObjectBox library target (target name "objectbox"; or, if the sync variant is used, "objectbox-sync") |
| 6 | +# * Fetch (download) the ObjectBoxGenerator CMake |
| 7 | +# * Unless this CMake is consumed from a user project, add the sub-projects (tests and examples) |
| 8 | +# |
| 9 | +# Options are available via plain (not cached) variables that can be declared before fetching this CMake module: |
| 10 | +# * ObjectBoxGenerator_CMAKE_DISABLE: set to ON to skip CMake integration of ObjectBox Generator |
| 11 | +# * ObjectBoxGenerator_CMAKE_VERSION: override the default version of the ObjectBox Generator CMake. |
| 12 | +# Changes the version to be fetched (git tag or branch). |
| 13 | + |
| 14 | +project(ObjectBoxCRoot) |
5 | 15 |
|
6 | 16 | # Remove Warning (as of CMake >= 3.24):
|
7 | 17 | # "The DOWNLOAD_EXTRACT_TIMESTAMP option was not given.."
|
8 | 18 | # We use the new behaviour (file timestamps from downloaded/extracted archives are updated).
|
9 |
| -if(POLICY CMP0135) |
| 19 | +if (POLICY CMP0135) |
10 | 20 | cmake_policy(SET CMP0135 NEW)
|
11 |
| -endif() |
| 21 | +endif () |
12 | 22 |
|
13 | 23 | if (${CMAKE_VERSION} VERSION_LESS "3.11.0")
|
14 | 24 | message("Please consider upgrading your CMake to a more recent version (v3.11+) to get automatic library download.")
|
@@ -39,7 +49,7 @@ else ()
|
39 | 49 |
|
40 | 50 | function(defineObjectBoxLib VARIANT)
|
41 | 51 | # Configuration updated for each release
|
42 |
| - set(DL_VERSION 4.0.1) |
| 52 | + set(DL_VERSION 4.0.2) |
43 | 53 |
|
44 | 54 | # Platform detection and other setup
|
45 | 55 | set(DL_URL https://github.com/objectbox/objectbox-c/releases/download)
|
@@ -84,8 +94,56 @@ else ()
|
84 | 94 | endif ()
|
85 | 95 | endif ()
|
86 | 96 |
|
87 |
| -# By default we exclude tests and examples. |
88 |
| -# If you want to build them please "make" them explicitly by target name (see targets below) |
89 |
| -add_subdirectory(src-test EXCLUDE_FROM_ALL) # target: objectbox-c-test |
90 |
| -add_subdirectory(src-test-gen EXCLUDE_FROM_ALL) # target: objectbox-c-gen-test |
91 |
| -add_subdirectory(examples EXCLUDE_FROM_ALL) # targets: objectbox-c-examples-tasks-{c,cpp-gen,cpp-gen-sync} |
| 97 | +# ObjectBoxGenerator CMake Downloader |
| 98 | +# ----------------------------------- |
| 99 | +# Make "FindObjectBoxGenerator" available, which is used to download/find and run the ObjectBox Generator. |
| 100 | + |
| 101 | +if (ObjectBoxGenerator_CMAKE_DISABLE) |
| 102 | + message(STATUS "ObjectBox Generator: CMake integration disabled") |
| 103 | +else () |
| 104 | + if(NOT DEFINED ObjectBoxGenerator_CMAKE_VERSION OR ObjectBoxGenerator_CMAKE_VERSION STREQUAL "") |
| 105 | + # The default version is a specific version that "matches" the ObjectBox library version of this repo. |
| 106 | + # Nevertheless, it's often possible to use a newer Generator version as breaking changes are infrequent. |
| 107 | + set(ObjectBoxGenerator_CMAKE_VERSION "v4.0.0-beta") |
| 108 | + endif () |
| 109 | + set(OBX_GEN_DL_URL https://raw.githubusercontent.com/objectbox/objectbox-generator/${ObjectBoxGenerator_CMAKE_VERSION}/cmake/FindObjectBoxGenerator.cmake) |
| 110 | + |
| 111 | + if (${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.18) |
| 112 | + message(STATUS "ObjectBox Generator: fetching version \"${ObjectBoxGenerator_CMAKE_VERSION}\"") |
| 113 | + include(FetchContent) |
| 114 | + FetchContent_Declare(FindObjectBoxGenerator URL ${OBX_GEN_DL_URL} DOWNLOAD_NO_EXTRACT TRUE) |
| 115 | + FetchContent_MakeAvailable(FindObjectBoxGenerator) |
| 116 | + set(OBX_GEN_MODULE_DIR ${findobjectboxgenerator_SOURCE_DIR}) |
| 117 | + else () |
| 118 | + message(STATUS "ObjectBox Generator: fetching version \"${ObjectBoxGenerator_CMAKE_VERSION}\" (using old CMake version)") |
| 119 | + set(OBX_GEN_MODULE_DIR ${CMAKE_CURRENT_LIST_DIR}/cmake) |
| 120 | + file(MAKE_DIRECTORY ${OBX_GEN_MODULE_DIR}) |
| 121 | + if (NOT EXISTS ${OBX_GEN_MODULE_DIR}/FindObjectBoxGenerator.cmake) |
| 122 | + file(DOWNLOAD ${OBX_GEN_DL_URL} ${OBX_GEN_MODULE_DIR}/FindObjectBoxGenerator.cmake |
| 123 | + TLS_VERIFY ON |
| 124 | + STATUS DL_STATUS |
| 125 | + ) |
| 126 | + if (NOT DL_STATUS EQUAL 0) |
| 127 | + message(WARNING "Downloading FindObjectBoxGenerator.cmake from URL ${DL_URL} failed") |
| 128 | + endif () |
| 129 | + endif () |
| 130 | + endif () |
| 131 | + |
| 132 | + if (EXISTS ${OBX_GEN_MODULE_DIR}/FindObjectBoxGenerator.cmake) |
| 133 | + # Enable find_package to locate ObjectBoxGenerator find module. |
| 134 | + list(APPEND CMAKE_MODULE_PATH ${OBX_GEN_MODULE_DIR}) |
| 135 | + get_directory_property(hasParent PARENT_DIRECTORY) |
| 136 | + if (hasParent) |
| 137 | + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE) |
| 138 | + endif () |
| 139 | + endif () |
| 140 | +endif () |
| 141 | + |
| 142 | + |
| 143 | +# If this project is top-level, include public tests and examples. |
| 144 | +# Otherwise, this CMake file is used from a user project, so we do not want to expose these. |
| 145 | +if (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) |
| 146 | + add_subdirectory(src-test) # target: objectbox-c-test |
| 147 | + add_subdirectory(src-test-gen) # target: objectbox-c-gen-test |
| 148 | + add_subdirectory(examples) # targets: objectbox-c-examples-tasks-{c,cpp-{auto}gen,cpp-gen-sync} |
| 149 | +endif () |
0 commit comments