Skip to content

Commit c547d4a

Browse files
committed
restructure example projects
1 parent 96d00ec commit c547d4a

19 files changed

+139
-130
lines changed

CMakeLists.txt

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,85 @@ cmake_minimum_required(VERSION 3.1)
22

33
set(project_name example-postgresql) ## rename your project here
44

5-
project(${project_name}-loader)
5+
project(${project_name})
66

7-
include(ExternalProject)
7+
set(CMAKE_CXX_STANDARD 11)
88

9-
#############################################################################
10-
## load all dependencies
9+
add_library(${project_name}-lib
10+
src/App.cpp
11+
src/AppComponent.hpp
12+
src/ServiceComponent.hpp
13+
src/SwaggerComponent.hpp
14+
src/controller/UserController.cpp
15+
src/controller/UserController.hpp
16+
src/db/Database.cpp
17+
src/db/Database.hpp
18+
src/dto/ConfigDto.hpp
19+
src/dto/ErrorDto.hpp
20+
src/dto/UserDto.hpp
21+
)
22+
23+
target_include_directories(${project_name}-lib PUBLIC src)
24+
25+
## link libs
26+
27+
find_package(oatpp 0.19.4 REQUIRED)
28+
find_package(oatpp-swagger 0.19.4 REQUIRED)
1129

12-
ExternalProject_Add(oatpp
13-
GIT_REPOSITORY "https://github.com/oatpp/oatpp.git"
14-
GIT_TAG origin/master
15-
CMAKE_ARGS -DOATPP_BUILD_TESTS=OFF
30+
target_link_libraries(${project_name}-lib
31+
PUBLIC oatpp::oatpp
32+
PUBLIC oatpp::oatpp-test
33+
PUBLIC oatpp::oatpp-swagger
1634
)
1735

18-
ExternalProject_Add(oatpp_swagger
19-
GIT_REPOSITORY "https://github.com/oatpp/oatpp-swagger.git"
20-
GIT_TAG origin/master
21-
DEPENDS oatpp
36+
add_definitions(
37+
# Path to swagger-ui resources #
38+
-DOATPP_SWAGGER_RES_PATH="${oatpp-swagger_INCLUDE_DIRS}/../bin/oatpp-swagger/res"
39+
40+
# Path to config file #
41+
-DCONFIG_PATH="${CMAKE_CURRENT_LIST_DIR}/resources/config.json"
2242
)
2343

24-
ExternalProject_Add(main
25-
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/main
26-
INSTALL_COMMAND cmake -E echo "SKIP INSTALL"
27-
DEPENDS oatpp oatpp_swagger
44+
#################################################################
45+
## link postgresql client
46+
47+
include(FindPkgConfig)
48+
49+
set(ENV{PKG_CONFIG_PATH} "/usr/local/pgsql/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}") ## change this if needed
50+
51+
pkg_check_modules(PKG_PQ REQUIRED libpq)
52+
53+
message("PKG_PQ_INCLUDE_DIRS=${PKG_PQ_INCLUDE_DIRS}")
54+
message("PKG_PQ_LIBRARY_DIRS=${PKG_PQ_LIBRARY_DIRS}")
55+
message("PKG_PQ_LIBRARIES=${PKG_PQ_LIBRARIES}")
56+
57+
target_include_directories(${project_name}-lib
58+
PUBLIC ${PKG_PQ_INCLUDE_DIRS}
2859
)
2960

30-
#############################################################################
31-
## make run command
61+
link_directories(
62+
${PKG_PQ_LIBRARY_DIRS}
63+
)
3264

33-
ExternalProject_Get_Property(main BINARY_DIR)
65+
target_link_libraries(${project_name}-lib
66+
PUBLIC ${PKG_PQ_LIBRARIES}
67+
)
3468

35-
add_custom_target(run
36-
COMMAND ${BINARY_DIR}/${project_name}-exe
37-
DEPENDS main
38-
WORKING_DIRECTORY ${BINARY_DIR}
69+
#################################################################
70+
71+
## add executables
72+
73+
add_executable(${project_name}-exe
74+
src/App.cpp
3975
)
76+
target_link_libraries(${project_name}-exe ${project_name}-lib)
77+
add_dependencies(${project_name}-exe ${project_name}-lib)
4078

41-
#############################################################################
42-
## make test command
79+
add_executable(${project_name}-test
80+
test/tests.cpp
81+
)
82+
target_link_libraries(${project_name}-test ${project_name}-lib)
83+
add_dependencies(${project_name}-test ${project_name}-lib)
4384

4485
enable_testing()
45-
add_test(all-tests ${BINARY_DIR}/${project_name}-test)
86+
add_test(project-tests ${project_name}-test)

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ RUN apk add postgresql-dev
44

55
ADD . /service
66

7+
WORKDIR /service/utility
8+
9+
RUN ./install-oatpp-modules.sh
10+
711
WORKDIR /service/build
812

913
RUN cmake ..
1014
RUN make
1115

1216
EXPOSE 8000 8000
1317

14-
ENTRYPOINT ["make", "run"]
18+
ENTRYPOINT ["./example-postgresql-exe"]

README.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,26 @@ Example of a production grade entity service storing information in PostgreSQL.
55
*Dockerfile and docker-compose.yaml files included.*
66

77
#### More about oat++:
8+
89
- Website: [https://oatpp.io](https://oatpp.io)
910
- Docs: [https://oatpp.io/docs/start](https://oatpp.io/docs/start)
1011
- Oat++ Repo: [https://github.com/oatpp/oatpp](https://github.com/oatpp/oatpp)
1112

1213
## Overview
14+
1315
This project is using `oatpp` and `oatpp-swagger` modules.
1416

1517
### Project layout
1618

1719
```
1820
19-
|- CMakeLists.txt // project loader script. load and build dependencies
20-
|- main/ // main project directory
21-
| |
22-
| |- CMakeLists.txt // project's CMakeLists.txt
23-
| |- src/ // source folder
24-
| |- test/ // test folder
25-
| |- resources/
26-
| |
27-
| |- config.json // configuration file with configuration profiles
28-
|
29-
|- Dockerfile // Dockerfile
30-
|- docker-compose.yaml // Docker-compose with this service and postgresql
31-
21+
- CMakeLists.txt // projects CMakeLists.txt
22+
- src/ // source folder
23+
- test/ // test folder
24+
- utility/install-oatpp-modules.sh // utility script to install required oatpp-modules.
25+
- resources/config.json // configuration file with configuration profiles
26+
- Dockerfile // Dockerfile
27+
- docker-compose.yaml // Docker-compose with this service and postgresql
3228
```
3329
```
3430
- src/
@@ -50,15 +46,21 @@ This project is using `oatpp` and `oatpp-swagger` modules.
5046

5147
### Using CMake
5248

53-
**Requires libpq installed**. To install libpq:
54-
- On Mac `$ brew install libpq`
55-
- On Alpine `$ apk add postgresql-dev`
56-
- On Ubuntu - goto [Install PostgreSQL Client From Sources](#install-postgresql-client-from-sources)
49+
**Requires**
50+
51+
- libpq installed. To install libpq:
52+
- On Mac `$ brew install libpq`
53+
- On Alpine `$ apk add postgresql-dev`
54+
- On Ubuntu - goto [Install PostgreSQL Client From Sources](#install-postgresql-client-from-sources)
55+
56+
- `oatpp` and `oatpp-swagger` modules installed. You may run `utility/install-oatpp-modules.sh`
57+
script to install required oatpp modules.
5758

5859
```
5960
$ mkdir build && cd build
6061
$ cmake ..
61-
$ make run ## Download, build, and install all dependencies. Run project
62+
$ make
63+
$ ./example-postgresql-exe # - run application.
6264
```
6365

6466
*PostgreSQL is expected running as for `dev` config profile*

azure-pipelines.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ 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
19-
- task: CMake@1
2023
- script: |
2124
cmake ..
2225
sudo make
@@ -25,4 +28,4 @@ jobs:
2528
- script: |
2629
make test ARGS="-V"
2730
displayName: 'Test'
28-
workingDirectory: build
31+
workingDirectory: build

main/CMakeLists.txt

Lines changed: 0 additions & 83 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)