-
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
9 changed files
with
190 additions
and
4 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,51 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
project("objectbox-test" CXX) | ||
|
||
include(FetchContent) | ||
FetchContent_Declare( | ||
objectbox | ||
GIT_REPOSITORY https://github.com/objectbox/objectbox-c.git | ||
GIT_TAG v4.0.1 | ||
) | ||
FetchContent_MakeAvailable(objectbox) | ||
|
||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../../cmake) | ||
find_package(ObjectBoxGenerator 4.0.0 REQUIRED) | ||
|
||
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 | ||
) | ||
|
||
option(DO_INSOURCE "" TRUE) | ||
|
||
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 | ||
CXX_STANDARD 17 | ||
) | ||
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,75 @@ | ||
# Specify CMake test projects | ||
set(PROJECTS cpp-flat;cpp-tree) | ||
|
||
# overload execute_process: Exit on cperror code. | ||
function(execute_process) | ||
_execute_process(${ARGV} RESULT_VARIABLE error) | ||
if(error) | ||
message(FATAL_ERROR "") | ||
endif() | ||
endfunction() | ||
|
||
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}) | ||
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) | ||
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() | ||
|
||
foreach(generator ${MULTI}) | ||
configureAndBuild(TRUE ${generator}) | ||
endforeach() | ||
|
||
foreach(generator ${SINGLE}) | ||
configureAndBuild(FALSE ${generator}) | ||
endforeach() | ||
|
||
return() | ||
|
||
# configureAndBuild("Unix Makefiles;Ninja" FALSE) | ||
configureAndBuild("Ninja Multi-Config" TRUE) | ||
return() | ||
|
||
#foreach(SingleGenerators) | ||
#endforeach() | ||
|
||
#foreach(MultiGenerators) | ||
#endforeach() |