Skip to content

Commit 5110e0e

Browse files
committed
restructure example projects
1 parent 656e02d commit 5110e0e

File tree

15 files changed

+106
-94
lines changed

15 files changed

+106
-94
lines changed

CMakeLists.txt

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,47 @@
11
cmake_minimum_required(VERSION 3.1)
2-
project(project-loader)
2+
project(crud)
3+
4+
set(CMAKE_CXX_STANDARD 11)
5+
6+
add_library(crud-lib
7+
src/AppComponent.hpp
8+
src/SwaggerComponent.hpp
9+
src/controller/UserController.hpp
10+
src/db/Database.cpp
11+
src/db/Database.hpp
12+
src/db/model/User.hpp
13+
src/dto/UserDto.hpp
14+
)
315

4-
include(ExternalProject)
16+
## include directories
517

6-
#############################################################################
7-
## load all dependencies
18+
target_include_directories(crud-lib PUBLIC src)
819

9-
ExternalProject_Add(oatpp
10-
GIT_REPOSITORY "https://github.com/oatpp/oatpp.git"
11-
GIT_TAG origin/master
12-
CMAKE_ARGS -DOATPP_BUILD_TESTS=OFF
13-
)
1420

15-
ExternalProject_Add(oatpp_swagger
16-
GIT_REPOSITORY "https://github.com/oatpp/oatpp-swagger.git"
17-
GIT_TAG origin/master
18-
DEPENDS oatpp
19-
)
21+
## link libs
22+
23+
find_package(oatpp 0.19.4 REQUIRED)
24+
find_package(oatpp-swagger 0.19.4 REQUIRED)
2025

21-
ExternalProject_Add(main
22-
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/main
23-
INSTALL_COMMAND cmake -E echo "SKIP INSTALL"
24-
DEPENDS oatpp oatpp_swagger
26+
target_link_libraries(crud-lib
27+
PUBLIC oatpp::oatpp
28+
PUBLIC oatpp::oatpp-swagger
2529
)
2630

27-
#############################################################################
28-
## make run command
31+
## define path to swagger-ui res folder
2932

30-
ExternalProject_Get_Property(main BINARY_DIR)
33+
add_definitions(-DOATPP_SWAGGER_RES_PATH="${oatpp-swagger_INCLUDE_DIRS}/../bin/oatpp-swagger/res")
3134

32-
add_custom_target(run
33-
COMMAND ${BINARY_DIR}/crud-exe
34-
DEPENDS main
35-
WORKING_DIRECTORY ${BINARY_DIR}
36-
)
3735

38-
#############################################################################
39-
## make test command
36+
## add executables
37+
38+
add_executable(crud-exe src/App.cpp)
39+
target_link_libraries(crud-exe crud-lib)
40+
41+
add_executable(crud-test
42+
test/tests.cpp
43+
)
44+
target_link_libraries(crud-test crud-lib)
4045

4146
enable_testing()
42-
add_test(all-tests ${BINARY_DIR}/crud-test)
47+
add_test(project-tests ${project_name}-test)

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ FROM lganzzzo/alpine-cmake:latest
22

33
ADD . /service
44

5+
WORKDIR /service/utility
6+
7+
RUN ./install-oatpp-modules.sh
8+
59
WORKDIR /service/build
610

711
RUN cmake ..
812
RUN make
913

1014
EXPOSE 8000 8000
1115

12-
ENTRYPOINT ["make", "run"]
16+
ENTRYPOINT ["./crud-exe"]

README.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,19 @@ This project is using `oatpp` and `oatpp-swagger` modules.
1313
### Project layout
1414

1515
```
16-
17-
- CMakeLists.txt // project loader script. load and build dependencies
18-
- main/ // main project directory
19-
|
20-
|- CMakeLists.txt // projects CMakeLists.txt
21-
|- src/ // source folder
22-
|- test/ // test folder
23-
24-
```
25-
```
16+
- CMakeLists.txt // projects CMakeLists.txt
2617
- src/
2718
|
28-
|- controller/ // Folder containing UserController where all endpoints are declared
29-
|- db/ // Folder with database mock
30-
|- dto/ // DTOs are declared here
31-
|- SwaggerComponent.hpp // Swagger-UI config
32-
|- AppComponent.hpp // Service config
33-
|- Logger.hpp // Application Logger
34-
|- App.cpp // main() is here
19+
|- controller/ // Folder containing UserController where all endpoints are declared
20+
|- db/ // Folder with database mock
21+
|- dto/ // DTOs are declared here
22+
|- SwaggerComponent.hpp // Swagger-UI config
23+
|- AppComponent.hpp // Service config
24+
|- Logger.hpp // Application Logger
25+
|- App.cpp // main() is here
26+
27+
- test/ // test folder
28+
- utility/install-oatpp-modules.sh // utility script to install required oatpp-modules.
3529
3630
```
3731

@@ -41,11 +35,16 @@ This project is using `oatpp` and `oatpp-swagger` modules.
4135

4236
#### Using CMake
4337

38+
**Requires**
39+
40+
- `oatpp` and `oatpp-swagger` modules installed. You may run `utility/install-oatpp-modules.sh`
41+
script to install required oatpp modules.
42+
4443
```
4544
$ mkdir build && cd build
4645
$ cmake ..
47-
$ make run ## Download, build, and install all dependencies. Run project
48-
46+
$ make
47+
$ ./crud-exe # - run application.
4948
```
5049

5150
#### In Docker

azure-pipelines.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ jobs:
1414
workspace:
1515
clean: all
1616
steps:
17+
- script: |
18+
sudo ./install-oatpp-modules.sh
19+
displayName: 'install oatpp modules'
20+
workingDirectory: utility
1721
- script: |
1822
mkdir build
1923
- script: |
@@ -24,4 +28,4 @@ jobs:
2428
- script: |
2529
make test ARGS="-V"
2630
displayName: 'Test'
27-
workingDirectory: build
31+
workingDirectory: build

main/CMakeLists.txt

Lines changed: 0 additions & 44 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)