Skip to content

Commit

Permalink
test/cmake-generators: using cmake script
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-obx committed Aug 6, 2024
1 parent 471969e commit daed818
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 4 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ jobs:
#- run: make
#- run: make test-depend
#- run: make test
- run: make test-cmake GH_RUNNER_OS=${{ runner.os }}
- if: matrix.os == 'windows-2019'
run: cd test/standalone-cmake && cmake -DMULTI="Visual Studio 16 2019" -P test-generators.cmake
- if: matrix.os == 'ubuntu-22.04'
run: cd test/standalone-cmake && cmake -DSINGLE="Unix Makefiles" -P test-generators.cmake
- if: matrix.os == 'macos-12'
run: cd test/standalone-cmake && cmake -DMULTI="Xcode" -P test-generators.cmake

#- name: Upload artifact
# uses: actions/upload-artifact@v4
Expand Down
6 changes: 3 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ t:cmake:linux-x64:
image:
name: objectboxio/buildenv-core:2024-07-11
script:
- make test-cmake
- cd test/standalone-cmake && cmake -DAUTO=1 -P test-generators.cmake

t:cmake:win-x64:
tags: [ windows ]
script:
- make test-cmake
- cd test/standalone-cmake && cmake -DMULTI="Visual Studio 17 2022" -P test-generators.cmake

t:cmake:mac-x64:
tags: [ mac, x64 ]
script:
- make test-cmake
- cd test/standalone-cmake && cmake -DAUTO=1 -DMULTI="Xcode" -P test-generators.cmake
51 changes: 51 additions & 0 deletions test/standalone-cmake/cpp-tree/CMakeLists.txt
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()
32 changes: 32 additions & 0 deletions test/standalone-cmake/cpp-tree/src/main.cpp
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 test/standalone-cmake/cpp-tree/src/schema/another_monster.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
table AnotherMonster {
id: ulong;
name: string;
hp: short;
mana: short;
}
6 changes: 6 additions & 0 deletions test/standalone-cmake/cpp-tree/src/schema/monster.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
table Monster {
id: ulong;
name: string;
hp: short;
mana: short;
}
5 changes: 5 additions & 0 deletions test/standalone-cmake/cpp-tree/src/schema/person.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
table Person {
id: ulong;
name: string;
age: int;
}
6 changes: 6 additions & 0 deletions test/standalone-cmake/cpp-tree/src/schema/task.fbs
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;
}
75 changes: 75 additions & 0 deletions test/standalone-cmake/test-generators.cmake
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()

0 comments on commit daed818

Please sign in to comment.