-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test/cmake-generators: using cmake script
- Loading branch information
Showing
11 changed files
with
223 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
option(DO_INSOURCE "Generate files in-source" FALSE) | ||
option(NO_PREBUILT "Use pre-built generator" FALSE) | ||
include(FetchContent) | ||
FetchContent_Declare( | ||
objectbox | ||
GIT_REPOSITORY https://github.com/objectbox/objectbox-c.git | ||
GIT_TAG v4.0.1 | ||
) | ||
FetchContent_MakeAvailable(objectbox) | ||
|
||
# Use find module from source tree. | ||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake) | ||
|
||
# Use pre-built ObjectBox Generator. | ||
if(NOT NO_PREBUILT) | ||
set(ObjectBoxGenerator_ROOT ${CMAKE_CURRENT_LIST_DIR}/../..) | ||
endif() | ||
|
||
find_package(ObjectBoxGenerator 4.0.0 REQUIRED) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
project("objectbox-test" CXX) | ||
|
||
include(../common.cmake) | ||
|
||
add_executable("objectbox-test" | ||
"src/main.cpp" | ||
) | ||
target_link_libraries("objectbox-test" objectbox) | ||
|
||
set_target_properties("objectbox-test" PROPERTIES | ||
CXX_STANDARD 14 | ||
CXX_STANDARD_REQUIRED YES | ||
) | ||
|
||
if (DO_INSOURCE) | ||
add_obx_schema( | ||
TARGET | ||
objectbox-test | ||
SCHEMA_FILES | ||
src/schema/person.fbs | ||
src/schema/task.fbs | ||
src/schema/monster.fbs | ||
src/schema/another_monster.fbs | ||
INSOURCE | ||
) | ||
else() | ||
add_obx_schema( | ||
TARGET | ||
objectbox-test | ||
SCHEMA_FILES | ||
src/schema/person.fbs | ||
src/schema/task.fbs | ||
src/schema/monster.fbs | ||
src/schema/another_monster.fbs | ||
) | ||
target_include_directories(objectbox-test PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
#define OBX_CPP_FILE | ||
|
||
|
||
#include "objectbox.hpp" | ||
|
||
#include "schema/objectbox-model.h" | ||
#include "schema/task.obx.hpp" | ||
|
||
int main(int argc, char* args[]) | ||
{ | ||
// create_obx_model() provided by objectbox-model.h | ||
// obx interface contents provided by objectbox.hpp | ||
obx::Store store(create_obx_model()); | ||
obx::Box<Task> box(store); | ||
|
||
Task my_task{}; | ||
my_task.text = "Buy milk"; | ||
obx_id id = box.put(my_task); // Create | ||
|
||
std::unique_ptr<Task> task = box.get(id); // Read | ||
if (task) { | ||
task->text += " & some bread"; | ||
box.put(*task); // Update | ||
} | ||
|
||
printf("Your task has ID=%llu, text=%s\n", | ||
id, | ||
box.get(id)->text.c_str()); | ||
|
||
return 0; | ||
} |
6 changes: 6 additions & 0 deletions
6
test/standalone-cmake/cpp-tree/src/schema/another_monster.fbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
table AnotherMonster { | ||
id: ulong; | ||
name: string; | ||
hp: short; | ||
mana: short; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
table Monster { | ||
id: ulong; | ||
name: string; | ||
hp: short; | ||
mana: short; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
table Person { | ||
id: ulong; | ||
name: string; | ||
age: int; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
table Task { | ||
id: ulong; | ||
text: string; | ||
date_created: ulong; | ||
date_finished: ulong; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# CMake script to test cmake find module with different CMake generators/toolchains. | ||
# | ||
# Usage: cmake | ||
# [ -DAUTO=1 ] | ||
# [ -DSINGLE="gen1;gen2;..." ] | ||
# [ -DMULTI="gen1;gen2" ] | ||
# [ -DNO_PREBUILT=1 ] | ||
# -P test-cmake-generators.cmake | ||
# | ||
# If AUTO is 1, Ninja/Make tools will be auto-detected. | ||
# MULTI specifies Multi-Config Generators such as "Xcode". (Release and Debug builds will be built) | ||
# SINGLE specifies Single-Config Generators. | ||
# NO_PREBUILT enforces not to look for local prebuilt generators but always download. | ||
# | ||
# Common to all CMake test projects: | ||
# Boilerplate code for fetching objectbox but using current source-tree find module available from "common.cmake". | ||
# Check for DO_INSOURCE to run add_obx_schema with INSOURCE. | ||
|
||
# Declare CMake test project directories which should be tested. | ||
set(PROJECTS cpp-flat) #;cpp-tree) | ||
|
||
if(NO_PREBUILT) | ||
set(extraFlags "-DNO_PREBUILT=1") | ||
endif() | ||
|
||
# overload execute_process: Exit on cperror code. | ||
function(execute_process) | ||
_execute_process(${ARGV} RESULT_VARIABLE error) | ||
if(error) | ||
message(FATAL_ERROR "") | ||
endif() | ||
endfunction() | ||
|
||
# configureAndBuild all PROJECTS using two variants: default and insource. | ||
# If multi is true, build Release and Debug configurations. | ||
# generator is passed as is to cmake via -G . | ||
function(configureAndBuild multi generator) | ||
string(REPLACE " " "_" generatorLabel ${generator}) | ||
foreach(project ${PROJECTS}) | ||
set(srcdir ${CMAKE_CURRENT_LIST_DIR}/${project}) | ||
foreach(insource TRUE;FALSE) | ||
if (insource) | ||
set(variant "insource") | ||
set(configureFlags "-DDO_INSOURCE=TRUE") | ||
else() | ||
set(variant "default") | ||
set(configureFlags) | ||
endif() | ||
set(builddir ${CMAKE_CURRENT_LIST_DIR}/build/${generatorLabel}/${project}/${variant}) | ||
# Remove all auto-generated files from sources | ||
file(GLOB_RECURSE auto_generated "*/objectbox-model.*" "*/*.obx.*") | ||
list(FILTER auto_generated EXCLUDE REGEX "/build/") | ||
if (auto_generated) | ||
file(REMOVE ${auto_generated}) | ||
endif() | ||
message(STATUS "-------------------------------------------------------") | ||
message(STATUS "**** Test Generator: ${generator} with test project '${project}' and variant '${variant}'.") | ||
message(STATUS "-------------------------------------------------------") | ||
execute_process(COMMAND ${CMAKE_COMMAND} -S ${srcdir} -B ${builddir} -G ${generator} ${configureFlags} ${extraFlags}) | ||
if (multi) | ||
execute_process(COMMAND ${CMAKE_COMMAND} --build ${builddir} --config Release) | ||
execute_process(COMMAND ${CMAKE_COMMAND} --build ${builddir} --config Debug) | ||
else() | ||
execute_process(COMMAND ${CMAKE_COMMAND} --build ${builddir}) | ||
endif() | ||
endforeach() | ||
endforeach() | ||
endfunction() | ||
|
||
if (AUTO) | ||
# Auto-detect Generators on Path | ||
find_program(NINJA ninja) | ||
if(NINJA) | ||
list(APPEND SINGLE "Ninja") | ||
list(APPEND MULTI "Ninja Multi-Config") | ||
endif() | ||
find_program(MAKE make) | ||
if(MAKE) | ||
list(APPEND SINGLE "Unix Makefiles") | ||
endif() | ||
endif() | ||
|
||
# Run Multi-Config Generators | ||
foreach(generator ${MULTI}) | ||
configureAndBuild(TRUE ${generator}) | ||
endforeach() | ||
|
||
# Run Single-Config Generators | ||
foreach(generator ${SINGLE}) | ||
configureAndBuild(FALSE ${generator}) | ||
endforeach() |