feat(@desktop/cpp): add conanfile, fruit, gtest
Closes: #4428 Closes: #4429
This commit is contained in:
parent
08f7320908
commit
e98428dd40
|
@ -49,6 +49,7 @@ install_manifest.txt
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
CTestTestfile.cmake
|
CTestTestfile.cmake
|
||||||
_deps
|
_deps
|
||||||
|
.cache/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -133,3 +133,8 @@ add_custom_target(run-debug
|
||||||
VERBATIM
|
VERBATIM
|
||||||
USES_TERMINAL
|
USES_TERMINAL
|
||||||
)
|
)
|
||||||
|
|
||||||
|
include(CTest)
|
||||||
|
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
|
||||||
|
add_subdirectory(test-cpp)
|
||||||
|
endif()
|
||||||
|
|
17
README.md
17
README.md
|
@ -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
|
cd build
|
||||||
cmake ..
|
conan install .. -s build_type=Release --build=missing
|
||||||
make
|
conan build ..
|
||||||
./test-qtapp
|
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
|
||||||
```
|
```
|
|
@ -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()
|
|
@ -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)
|
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue