Skip to content

Commit 4c98ca0

Browse files
committed
restructure example projects
1 parent 2c1381a commit 4c98ca0

File tree

12 files changed

+86
-86
lines changed

12 files changed

+86
-86
lines changed

CMakeLists.txt

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,47 @@ cmake_minimum_required(VERSION 3.1)
22

33
set(project_name example-async-api) ## 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
11-
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
9+
add_library(${project_name}-lib
10+
src/AppComponent.hpp
11+
src/controller/MyController.cpp
12+
src/controller/MyController.hpp
13+
src/dto/MyDTOs.hpp
1614
)
1715

18-
ExternalProject_Add(main
19-
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/main
20-
INSTALL_COMMAND cmake -E echo "SKIP INSTALL"
21-
DEPENDS oatpp
16+
## link libs
17+
18+
find_package(oatpp 0.19.4 REQUIRED)
19+
20+
target_link_libraries(${project_name}-lib
21+
PUBLIC oatpp::oatpp
22+
PUBLIC oatpp::oatpp-test
2223
)
2324

24-
#############################################################################
25-
## make run command
25+
target_include_directories(${project_name}-lib PUBLIC src)
2626

27-
ExternalProject_Get_Property(main BINARY_DIR)
27+
## add executables
2828

29-
add_custom_target(run
30-
COMMAND ${BINARY_DIR}/${project_name}-exe
31-
DEPENDS main
32-
WORKING_DIRECTORY ${BINARY_DIR}
29+
add_executable(${project_name}-exe
30+
src/App.cpp
3331
)
32+
target_link_libraries(${project_name}-exe ${project_name}-lib)
33+
add_dependencies(${project_name}-exe ${project_name}-lib)
3434

35-
#############################################################################
36-
## make test command
35+
add_executable(${project_name}-test
36+
test/tests.cpp
37+
)
38+
target_link_libraries(${project_name}-test ${project_name}-lib)
39+
add_dependencies(${project_name}-test ${project_name}-lib)
40+
41+
set_target_properties(${project_name}-lib ${project_name}-exe ${project_name}-test PROPERTIES
42+
CXX_STANDARD 11
43+
CXX_EXTENSIONS OFF
44+
CXX_STANDARD_REQUIRED ON
45+
)
3746

3847
enable_testing()
39-
add_test(all-tests ${BINARY_DIR}/${project_name}-test)
48+
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 ["./example-async-api-exe"]

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,17 @@ Example project how-to use oatpp asynchronous API.
1212
### Project layout
1313

1414
```
15-
16-
- CMakeLists.txt // project loader script. load and build dependencies
17-
- main/ // main project directory
18-
|
19-
|- CMakeLists.txt // projects CMakeLists.txt
20-
|- src/ // source folder
21-
|- test/ // test folder
22-
23-
```
24-
```
15+
- CMakeLists.txt // projects CMakeLists.txt
2516
- src/
2617
|
27-
|- controller/ // Folder containing controller where all endpoints are declared
28-
|- dto/ // DTOs are declared here
29-
|- AppComponent.hpp // Service config
30-
|- Logger.hpp // Application Logger
31-
|- App.cpp // main() is here
18+
|- controller/ // Folder containing controller where all endpoints are declared
19+
|- dto/ // DTOs are declared here
20+
|- AppComponent.hpp // Service config
21+
|- Logger.hpp // Application Logger
22+
|- App.cpp // main() is here
23+
24+
- test/ // test folder
25+
- utility/install-oatpp-modules.sh // utility script to install required oatpp-modules.
3226
3327
```
3428

@@ -38,10 +32,16 @@ Example project how-to use oatpp asynchronous API.
3832

3933
#### Using CMake
4034

35+
**Requires**
36+
37+
- `oatpp` module installed. You may run `utility/install-oatpp-modules.sh`
38+
script to install required oatpp modules.
39+
4140
```
4241
$ mkdir build && cd build
4342
$ cmake ..
44-
$ make run ## Download, build, and install all dependencies. Run project
43+
$ make
44+
$ ./example-async-api-exe # - run application.
4545
4646
```
4747

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 & 45 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy