Skip to content

Commit

Permalink
Merge pull request #8 from rueyaa332266/add_cmake
Browse files Browse the repository at this point in the history
Add cmake
  • Loading branch information
hikimochi authored Mar 26, 2020
2 parents 2f4a827 + 350111c commit 45ac278
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 90 deletions.
70 changes: 29 additions & 41 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,88 +1,76 @@
version: 2.1

commands:
prepare_for_build:
description: "Prepare for build."
steps:
- restore_cache:
keys:
- v1-cxxops-cache-{{ .Branch }}-{{ .Revision }}-{{ checksum ".circleci/cxxops.sh" }}
- v1-cxxops-cache-{{ .Branch }}-{{ .Revision }}-
- v1-cxxops-cache-{{ .Branch }}-
- run:
name: download cxxopts.hpp
command: |
if [ ! -e include/cxxops.hpp ]; then
bash .circleci/cxxops.sh;
fi
- save_cache:
key: v1-cxxops-cache-{{ .Branch }}-{{ .Revision }}-{{ checksum ".circleci/cxxops.sh" }}
paths:
- include
prepare_for_test:
description: "Prepare for test."
steps:
- restore_cache:
keys:
- v1-gtest-cache-{{ .Branch }}-{{ .Revision }}-{ checksum ".circleci/build_googletest.sh" }}
- v1-gtest-cache-{{ .Branch }}-{{ .Revision }}-{ checksum "tests/build_googletest.sh" }}
- v1-gtest-cache-{{ .Branch }}-{{ .Revision }}-
- v1-gtest-cache-{{ .Branch }}-
- run:
name: download and build google test
command: |
if [ ! -d tests/googletest ]; then
bash .circleci/build_googletest.sh;
bash tests/build_googletest.sh;
fi
- save_cache:
key: v1-gtest-cache-{{ .Branch }}-{{ .Revision }}-{{ checksum ".circleci/cxxops.sh" }}
key: v1-gtest-cache-{{ .Branch }}-{{ .Revision }}-{{ checksum "tests/build_googletest.sh" }}
paths:
- tests/googletest
prepare_for_cmake:
description: "Prepare directory for cmake."
steps:
- run:
name: prepare build directory
command: mkdir build
jobs:
google_test:
working_directory: ~/test
docker:
- image: rhikimochi/opencv-docker:v0.14
steps:
- checkout
- prepare_for_build
- prepare_for_test
- prepare_for_cmake
- run:
name: build unit test
command: |
g++ -std=c++11 ./tests/unit_tests/imageDiffCalc_test.cpp -o test `pkg-config --cflags --libs opencv` -Isrc -Iinclude -Itests/googletest/include -Ltests/googletest -lgtest -lgtest_main -lpthread
- run:
name: unit test
command: ./test
cd build && cmake .. -DGTEST=ON -DTEST_LEVEL=unit && make
- run:
name: build integration test
command: |
g++ -std=c++11 ./tests/integration_tests/imageDiffCalc_test.cpp -o test `pkg-config --cflags --libs opencv` -Isrc -Iinclude -Itests/googletest/include -Ltests/googletest -lgtest -lgtest_main -lpthread
- run:
name: integration test
command: ./test
cd build && cmake .. -DGTEST=ON -DTEST_LEVEL=integration && make
- run:
name: build system test
command: |
g++ -std=c++11 ./tests/system_tests/imageDiffCalc_test.cpp -o test `pkg-config --cflags --libs opencv` -Isrc -Iinclude -Itests/googletest/include -Ltests/googletest -lgtest -lgtest_main -lpthread
cd build && cmake .. -DGTEST=ON -DTEST_LEVEL=system && make
- run:
name: execute unit test
command: ./gazosan_unit_test
- run:
name: syetem test
command: ./test
name: execute integration test
command: ./gazosan_integration_test
- run:
name: execute syetem test
command: ./gazosan_system_test
build_library:
working_directory: /tmp/build
docker:
- image: rhikimochi/opencv-docker:v0.14
steps:
- checkout
- prepare_for_build
- prepare_for_cmake
- run:
name: Make object file
command: g++ -std=c++11 ./src/imageDiffCalc.cpp `pkg-config --libs --cflags opencv` -Iinclude -c
name: build gazosan
command: cd build && cmake .. && make
- run:
name: Make static library
command: ar r libimageDiffCalc.a imageDiffCalc.o
name: move static library
command: mv build/libimageDiffCalc.a libimageDiffCalc.a
- persist_to_workspace:
root: /tmp/build
paths:
paths:
- libimageDiffCalc.a
build_and_deploy_image:
working_directory: ~/build
Expand All @@ -92,13 +80,13 @@ jobs:
steps:
- checkout
- attach_workspace:
at: /tmp/build
at: /tmp/build
- run:
name: Move library
command: mv /tmp/build/libimageDiffCalc.a ~/build/
- run:
name: Build and tagged image
command: |
command: |
docker build -t "$DOCKER_HUB_USER"/"$DOCKER_HUB_REPO":"${CIRCLE_TAG/v/}" .
docker tag "$DOCKER_HUB_USER"/"$DOCKER_HUB_REPO":"${CIRCLE_TAG/v/}" "$DOCKER_HUB_USER"/"$DOCKER_HUB_REPO":latest
- run:
Expand Down
5 changes: 0 additions & 5 deletions .circleci/cxxops.sh

This file was deleted.

52 changes: 52 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
cmake_minimum_required(VERSION 2.8)
project( Gazo-san )
set (CMAKE_CXX_STANDARD 11)
set(GTEST OFF CACHE BOOL "Test flag")
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )

if(GTEST)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/tests/googletest")
execute_process(
COMMAND bash tests/build_googletest.sh
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()
set (gtest ${CMAKE_SOURCE_DIR}/tests/googletest/libgtest.a)
set (gtest_main ${CMAKE_SOURCE_DIR}/tests/googletest/libgtest_main.a)
set (LIBRARIES_FOR_TEST ${OpenCV_LIBS} ${gtest} ${gtest_main} -lpthread)
include_directories( src/ )
include_directories( include/ )
include_directories( tests/googletest/include/ )
file(DOWNLOAD https://raw.githubusercontent.com/jarro2783/cxxopts/master/include/cxxopts.hpp ${CMAKE_SOURCE_DIR}/include/cxxopts.hpp)

if( ${TEST_LEVEL} STREQUAL "unit" )
add_executable(gazosan_unit_test tests/unit_tests/imageDiffCalc_test.cpp)
target_link_libraries( gazosan_unit_test ${LIBRARIES_FOR_TEST} )
elseif( ${TEST_LEVEL} STREQUAL "integration" )
add_executable( gazosan_integration_test tests/integration_tests/imageDiffCalc_test.cpp )
target_link_libraries( gazosan_integration_test ${LIBRARIES_FOR_TEST} )
elseif( ${TEST_LEVEL} STREQUAL "system" )
add_executable( gazosan_system_test tests/system_tests/imageDiffCalc_test.cpp )
target_link_libraries( gazosan_system_test ${LIBRARIES_FOR_TEST} )
endif()
else()
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin )
set (BIN_NAME gazosan )

if(EXISTS "${CMAKE_SOURCE_DIR}/libimageDiffCalc.a")
# Use static link library file
# Works only on ubuntu
add_executable( ${BIN_NAME} src/main.cpp )
target_link_libraries( ${BIN_NAME} ${OpenCV_LIBS} ${CMAKE_SOURCE_DIR}/libimageDiffCalc.a )
else()
# Build with source code
# Works on linux machine
file(DOWNLOAD https://raw.githubusercontent.com/jarro2783/cxxopts/master/include/cxxopts.hpp ${CMAKE_SOURCE_DIR}/include/cxxopts.hpp)
include_directories( include/ )
add_library(imageDiffCalc STATIC src/imageDiffCalc.cpp )
add_executable( ${BIN_NAME} src/main.cpp )
target_link_libraries( ${BIN_NAME} ${OpenCV_LIBS} imageDiffCalc )
endif()
endif()
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ FROM rhikimochi/opencv-docker:v0.14

COPY . /run
WORKDIR /run
RUN g++ -std=c++11 ./src/main.cpp -L./ -limageDiffCalc -o gazosan `pkg-config --libs opencv`
RUN mv gazosan /usr/local/bin
RUN mkdir build && \
cd build && \
cmake .. && \
make
RUN mv bin/gazosan /usr/local/bin
RUN rm -r /run/*
79 changes: 39 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,43 +76,18 @@ Each color stands for:

## How to build Gazo-san

### Compile with static link library

> Works only on Ubuntu
1. Download static link library file

```bash
curl -OLsS https://github.com/lifull-dev/Gazo-san/releases/download/{VERSION}/libimageDiffCalc.a
1. Build Gazo-san by CMake
```

2. Compile main.cpp

```bash
g++ -std=c++11 ./src/main.cpp -L./ -limageDiffCalc -o gazosan `pkg-config --libs opencv`
mkdir build
cd build
cmake ..
make
cd ..
```

### Compile with source code

> Works on linux machine or Mac
> Works on gcc version 4.2.1
1. Create directory and Download [cxxopts.hpp](https://github.com/jarro2783/cxxopts/blob/master/include/cxxopts.hpp) into include directory.

2. Binary file is in bin directory
```bash
sh .circleci/cxxops.sh
```

2. Add include in main.cpp
```
#include "imageDiffCalc.cpp"
```

3. Compile main.cpp

```bash
g++ -std=c++11 -I include/ ./src/main.cpp -o gazosan `pkg-config --libs --cflags opencv`
cd bin
./gazosan
```

## Execute Gazo-san
Expand Down Expand Up @@ -143,23 +118,47 @@ sh .circleci/build_googletest.sh

#### Unit test

1. Build unit tests by CMake
```
mkdir build
cd build
cmake .. -DGTEST=ON -DTEST_LEVEL=unit
make
cd ..
```
2. Execute unit tests
```bash
g++ -std=c++11 ./tests/unit_tests/imageDiffCalc_test.cpp -o test `pkg-config --cflags --libs opencv` -Isrc -Iinclude -Itests/googletest/include -Ltests/googletest -lgtest -lgtest_main -lpthread
./test
./gazosan_unit_test
```

#### Integration test

1. Build integration tests by CMake
```
mkdir build
cd build
cmake .. -DGTEST=ON -DTEST_LEVEL=integration
make
cd ..
```
2. Execute integration tests
```bash
g++ -std=c++11 ./tests/integration_tests/imageDiffCalc_test.cpp -o test `pkg-config --libs --cflags opencv` -Isrc -Iinclude -Itests/googletest/include -Ltests/googletest -lgtest -lgtest_main -lpthread
./test
./gazosan_integration_test
```

#### System test

1. Build system tests by CMake
```
mkdir build
cd build
cmake .. -DGTEST=ON -DTEST_LEVEL=system
make
cd ..
```
2. Execute system tests
```bash
g++ -std=c++11 ./tests/system_tests/imageDiffCalc_test.cpp -o test `pkg-config --libs --cflags opencv` -Isrc -Iinclude -Itests/googletest/include -Ltests/googletest -lgtest -lgtest_main -lpthread
./test
./gazosan_system_test
```

## License
Expand Down
4 changes: 2 additions & 2 deletions .circleci/build_googletest.sh → tests/build_googletest.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash

GOOGLETEST_VER=1.10.0
curl -OLsS https://github.com/google/googletest/archive/release-"$GOOGLETEST_VER".tar.gz
tar -zxvf release-"$GOOGLETEST_VER".tar.gz
cd googletest-release-"$GOOGLETEST_VER" || exit
mkdir build
cd build || exit
cd build || exit
cmake ..
make
cd ../../ || exit
Expand Down

0 comments on commit 45ac278

Please sign in to comment.