feat(@desktop/cpp): add conanfile, fruit, gtest

Closes: #4428
Closes: #4429
This commit is contained in:
Patryk Osmaczko 2022-01-18 12:39:21 +01:00 committed by Richard Ramos
parent 08f7320908
commit e98428dd40
6 changed files with 88 additions and 8 deletions

1
.gitignore vendored
View File

@ -49,6 +49,7 @@ install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
.cache/

View File

@ -133,3 +133,8 @@ add_custom_target(run-debug
VERBATIM
USES_TERMINAL
)
include(CTest)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
add_subdirectory(test-cpp)
endif()

View File

@ -10,11 +10,18 @@ Dev Docs: [https://hackmd.io/@status-desktop/B1naRjxh_/https%3A%2F%2Fhackmd.io%2
# CPP app
# CPP App
Buid&test&run:
```
cd build
cmake ..
make
./test-qtapp
conan install .. -s build_type=Release --build=missing
conan build ..
ctest -VV -C Release
./status-desktop
```
Instead of `conan build ..` CMake may be used:
```
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake
cmake --build . --config Release
```

17
conanfile.py Normal file
View File

@ -0,0 +1,17 @@
from conans import ConanFile, CMake
class StatusDesktop(ConanFile):
name = "status-desktop"
settings = "os", "compiler", "build_type", "arch"
requires = "fruit/3.6.0", "gtest/1.11.0"
# cmake_find_package and cmake_find_package_multi should be substituted with CMakeDeps
# as soon as Conan 2.0 is released and all conan-center packages are adapted
generators = "CMakeToolchain", "cmake_find_package", "cmake_find_package_multi"
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

15
test-cpp/CMakeLists.txt Normal file
View File

@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.14)
project(status-desktop-test VERSION 0.1.0 LANGUAGES CXX)
macro(add_gtest TESTNAME SRC)
add_executable(${TESTNAME} ${SRC})
target_link_libraries(${TESTNAME} PRIVATE GTest::gtest GTest::gmock GTest::gtest_main)
add_test(${TESTNAME} ${TESTNAME})
endmacro()
find_package(GTest REQUIRED)
find_package(fruit REQUIRED)
add_gtest(TestDeps testDeps.cpp)
target_link_libraries(TestDeps PRIVATE fruit::fruit)

35
test-cpp/testDeps.cpp Normal file
View File

@ -0,0 +1,35 @@
#include <fruit/fruit.h>
#include <gtest/gtest.h>
namespace
{
class Greeter
{
public:
virtual std::string greet() = 0;
};
fruit::Component<Greeter> getGreeterComponent();
class GreeterImpl : public Greeter
{
public:
INJECT(GreeterImpl()) = default;
std::string greet() override
{
return "Hello, world!";
}
};
fruit::Component<Greeter> getGreeterComponent()
{
return fruit::createComponent().bind<Greeter, GreeterImpl>();
}
} // namespace
TEST(TestDeps, Fruit)
{
auto injector = fruit::Injector<Greeter>{getGreeterComponent};
ASSERT_NE(injector.get<Greeter*>(), nullptr);
}