Skip to content

Commit

Permalink
new project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
lganzzzo committed Jan 28, 2019
1 parent db7712e commit f8174cc
Show file tree
Hide file tree
Showing 25 changed files with 196 additions and 1,611 deletions.
1 change: 1 addition & 0 deletions .dockerignore
@@ -0,0 +1 @@
build/
8 changes: 8 additions & 0 deletions .gitignore
Expand Up @@ -30,3 +30,11 @@
*.exe
*.out
*.app

# custom build
build/

# idea
.idea/
cmake-build-debug/
*/cmake-build-debug/
39 changes: 39 additions & 0 deletions CMakeLists.txt
@@ -0,0 +1,39 @@
cmake_minimum_required(VERSION 3.1)

set(project_name my-project) ## rename your project here

project(${project_name}-loader)

include(ExternalProject)

#############################################################################
## load all dependencies

ExternalProject_Add(oatpp
GIT_REPOSITORY "https://github.com/oatpp/oatpp.git"
GIT_TAG origin/master
CMAKE_ARGS -DOATPP_BUILD_TESTS=OFF
)

ExternalProject_Add(main
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/main
INSTALL_COMMAND cmake -E echo "SKIP INSTALL"
DEPENDS oatpp
)

#############################################################################
## make run command

ExternalProject_Get_Property(main BINARY_DIR)

add_custom_target(run
COMMAND ${BINARY_DIR}/${project_name}-exe
DEPENDS main
WORKING_DIRECTORY ${BINARY_DIR}
)

#############################################################################
## make test command

enable_testing()
add_test(all-tests ${BINARY_DIR}/${project_name}-test)
12 changes: 12 additions & 0 deletions Dockerfile
@@ -0,0 +1,12 @@
FROM lganzzzo/alpine-cmake:latest

ADD . /service

WORKDIR /service/build

RUN cmake ..
RUN make

EXPOSE 8000 8000

ENTRYPOINT ["make", "run"]
27 changes: 27 additions & 0 deletions azure-pipelines.yml
@@ -0,0 +1,27 @@
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

jobs:
- job: ubuntu_16_04
displayName: 'Build - Ubuntu 16.04'
continueOnError: false
pool:
vmImage: 'Ubuntu 16.04'
container:
image: lganzzzo/ubuntu-cmake:latest
workspace:
clean: all
steps:
- script: |
mkdir build
- script: |
cmake ..
sudo make
displayName: 'CMake'
workingDirectory: build
- script: |
make test ARGS="-V"
displayName: 'Test'
workingDirectory: build
47 changes: 47 additions & 0 deletions main/CMakeLists.txt
@@ -0,0 +1,47 @@
cmake_minimum_required(VERSION 3.1)

set(project_name my-project) ## rename your project here

project(${project_name})

set(CMAKE_CXX_STANDARD 11)

include_directories(src)

add_library(${project_name}-lib
src/AppComponent.hpp
src/Logger.hpp
src/Logger.cpp
src/controller/MyController.hpp
src/dto/MyDto.hpp
)

## link libs

find_package(oatpp 0.19.1 REQUIRED)

target_link_libraries(${project_name}-lib
PUBLIC oatpp::oatpp
PUBLIC oatpp::oatpp-test
)

## add executables

add_executable(${project_name}-exe
src/App.cpp
)
target_link_libraries(${project_name}-exe ${project_name}-lib)
add_dependencies(${project_name}-exe ${project_name}-lib)

add_executable(${project_name}-test
test/tests.cpp
)
target_link_libraries(${project_name}-test ${project_name}-lib)
add_dependencies(${project_name}-test ${project_name}-lib)

set_target_properties(${project_name}-lib ${project_name}-exe ${project_name}-test PROPERTIES
CXX_STANDARD 11
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
LINKER_LANGUAGE CXX
)
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions main/src/Logger.cpp
@@ -0,0 +1,16 @@
//
// Logger.hpp
// oatpp-web-starter
//
// Created by Leonid on 3/2/18.
// Copyright © 2018 lganzzzo. All rights reserved.
//

#include "Logger.hpp"

#include <iostream>

void Logger::log(v_int32 priority, const std::string& tag, const std::string& message) {
oatpp::concurrency::SpinLock lock(m_atom);
std::cout << tag << ":" << message << "\n";
}
7 changes: 1 addition & 6 deletions src/Logger.hpp → main/src/Logger.hpp
Expand Up @@ -12,8 +12,6 @@
#include "oatpp/core/concurrency/SpinLock.hpp"
#include "oatpp/core/base/Environment.hpp"

#include <iostream>

/**
* Environment logger.
* All logs from OATPP_LOGV(...), OATPP_LOGD(...), OATPP_LOGE(...) go here
Expand All @@ -28,10 +26,7 @@ class Logger : public oatpp::base::Logger {
: m_atom(false)
{}

void log(v_int32 priority, const std::string& tag, const std::string& message) override {
oatpp::concurrency::SpinLock lock(m_atom);
std::cout << tag << ":" << message << "\n";
}
void log(v_int32 priority, const std::string& tag, const std::string& message) override;

};

Expand Down
File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions main/test/tests.cpp
@@ -0,0 +1,45 @@

#include "Logger.hpp"

#include "oatpp-test/UnitTest.hpp"
#include <iostream>

namespace {

class Test : public oatpp::test::UnitTest {
public:
Test() : oatpp::test::UnitTest("[MyTest]")
{}

bool onRun() override {
OATPP_LOGD(TAG, "Hello Test");
return true;
}
};

void runTests() {
OATPP_RUN_TEST(Test);
}

}

int main() {

oatpp::base::Environment::init();
oatpp::base::Environment::setLogger(new Logger());

runTests();

oatpp::base::Environment::setLogger(nullptr);
oatpp::base::Environment::destroy();

/* Print how much objects were created during app running, and what have left-probably leaked */
/* Disable object counting for release builds using '-D OATPP_DISABLE_ENV_OBJECT_COUNTERS' flag for better performance */
std::cout << "\nEnvironment:\n";
std::cout << "objectsCount = " << oatpp::base::Environment::getObjectsCount() << "\n";
std::cout << "objectsCreated = " << oatpp::base::Environment::getObjectsCreated() << "\n\n";

OATPP_ASSERT(oatpp::base::Environment::getObjectsCount() == 0);

return 0;
}

0 comments on commit f8174cc

Please sign in to comment.