From 4ea59eb1292002a7b903f3b8289fad4ade2e95b3 Mon Sep 17 00:00:00 2001 From: RUEY JYE Date: Sun, 22 Mar 2020 23:02:35 +0900 Subject: [PATCH 01/13] add cmakelists --- CMakeLists.txt | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..576a07b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,44 @@ +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}) + set (gtest ${CMAKE_SOURCE_DIR}/tests/googletest/libgtest.a) + set (gtest_main ${CMAKE_SOURCE_DIR}/tests/googletest/libgtest_main.a) + 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 ${OpenCV_LIBS} ${gtest} ${gtest_main} ) + elseif( ${TEST_LEVEL} STREQUAL "integration" ) + add_executable( gazosan_integration_test tests/integration_tests/imageDiffCalc_test.cpp ) + target_link_libraries( gazosan_integration_test ${OpenCV_LIBS} ${gtest} ${gtest_main} ) + elseif( ${TEST_LEVEL} STREQUAL "system" ) + add_executable( gazosan_system_test tests/system_tests/imageDiffCalc_test.cpp ) + target_link_libraries( gazosan_system_test ${OpenCV_LIBS} ${gtest} ${gtest_main} ) + endif() +else() + set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin ) + + if(EXISTS "${CMAKE_SOURCE_DIR}/libimageDiffCalc.a") + # Use static link library file + # Works only on ubuntu + add_executable( gazosan src/main.cpp ) + target_link_libraries( gazosan ${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( gazosan src/main.cpp ) + target_link_libraries( gazosan ${OpenCV_LIBS} imageDiffCalc ) + endif() +endif() \ No newline at end of file From 2fab00da9bc9accb420de3fde542f2f57b96ee33 Mon Sep 17 00:00:00 2001 From: RUEY JYE Date: Sun, 22 Mar 2020 23:12:18 +0900 Subject: [PATCH 02/13] fix dockerfile --- Dockerfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6b9d94f..38c8d9c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/* \ No newline at end of file From f5dcd3a436791188b117dd6531c3719ee664d0c2 Mon Sep 17 00:00:00 2001 From: RUEY JYE Date: Mon, 23 Mar 2020 08:42:12 +0900 Subject: [PATCH 03/13] fix circle ci config --- .circleci/config.yml | 70 ++++++++++++++++++++------------------------ .circleci/cxxops.sh | 5 ---- 2 files changed, 31 insertions(+), 44 deletions(-) delete mode 100644 .circleci/cxxops.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index ff6b6a9..8707299 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,24 +1,6 @@ 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: @@ -34,9 +16,16 @@ commands: bash .circleci/build_googletest.sh; fi - save_cache: - key: v1-gtest-cache-{{ .Branch }}-{{ .Revision }}-{{ checksum ".circleci/cxxops.sh" }} + key: v1-gtest-cache-{{ .Branch }}-{{ .Revision }}-{{ checksum ".circleci/build_googletest.sh" }} paths: - tests/googletest + prepare_for_cmake: + description: "Prepare directory for cmake." + steps: + - run: + name: prepare build directory + command: | + mkdir build && cd build jobs: google_test: working_directory: ~/test @@ -44,45 +33,48 @@ jobs: - 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 + 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 + 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 + cmake .. -DGTEST=ON -DTEST_LEVEL=system && make + - run: + name: back to working directory + command: cd .. + - 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: cmake .. -DGTEST=OFF && make && cd .. - 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 @@ -92,13 +84,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: diff --git a/.circleci/cxxops.sh b/.circleci/cxxops.sh deleted file mode 100644 index 5a86817..0000000 --- a/.circleci/cxxops.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -mkdir -p include -curl -OLsS 'https://raw.githubusercontent.com/jarro2783/cxxopts/master/include/cxxopts.hpp' -mv cxxopts.hpp include/ \ No newline at end of file From b297077cfba39a87b6fb7aed4acb7da1d84cee26 Mon Sep 17 00:00:00 2001 From: RUEY JYE Date: Mon, 23 Mar 2020 08:54:23 +0900 Subject: [PATCH 04/13] fix readme --- README.md | 79 +++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index d9db18a..5b44da6 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 From 9ec798c0fbcc13414f8d8cc796446e1dd281a12a Mon Sep 17 00:00:00 2001 From: RUEY JYE Date: Mon, 23 Mar 2020 21:10:05 +0900 Subject: [PATCH 05/13] fix config --- .circleci/build_googletest.sh | 4 ++-- .circleci/config.yml | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.circleci/build_googletest.sh b/.circleci/build_googletest.sh index 3a9263f..2ff8c2f 100644 --- a/.circleci/build_googletest.sh +++ b/.circleci/build_googletest.sh @@ -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 diff --git a/.circleci/config.yml b/.circleci/config.yml index 8707299..2e8554b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,8 +24,7 @@ commands: steps: - run: name: prepare build directory - command: | - mkdir build && cd build + command: mkdir build && cd build jobs: google_test: working_directory: ~/test From ce1c32bc7a53eb96d07e7694f672abe38f8da2fb Mon Sep 17 00:00:00 2001 From: RUEY JYE Date: Mon, 23 Mar 2020 21:23:50 +0900 Subject: [PATCH 06/13] fix config --- .circleci/config.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2e8554b..6ba8fa1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,12 +19,6 @@ commands: key: v1-gtest-cache-{{ .Branch }}-{{ .Revision }}-{{ checksum ".circleci/build_googletest.sh" }} paths: - tests/googletest - prepare_for_cmake: - description: "Prepare directory for cmake." - steps: - - run: - name: prepare build directory - command: mkdir build && cd build jobs: google_test: working_directory: ~/test @@ -33,7 +27,10 @@ jobs: steps: - checkout - prepare_for_test - - prepare_for_cmake + - run: + name: prepare build directory + command: | + mkdir build && cd build - run: name: build unit test command: | @@ -64,7 +61,10 @@ jobs: - image: rhikimochi/opencv-docker:v0.14 steps: - checkout - - prepare_for_cmake + - run: + name: prepare build directory + command: | + mkdir build && cd build - run: name: build gazosan command: cmake .. -DGTEST=OFF && make && cd .. From 9c55c73300ea2fe8b9dd94f4cf156cf70dbe9ac2 Mon Sep 17 00:00:00 2001 From: RUEY JYE Date: Mon, 23 Mar 2020 21:28:13 +0900 Subject: [PATCH 07/13] debug --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6ba8fa1..146f61d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -30,11 +30,11 @@ jobs: - run: name: prepare build directory command: | - mkdir build && cd build + mkdir build && cd build && ls && pwd - run: name: build unit test command: | - cmake .. -DGTEST=ON -DTEST_LEVEL=unit && make + ls && pwd && cmake .. -DGTEST=ON -DTEST_LEVEL=unit && make - run: name: build integration test command: | From 1101854a642cb00e6ccd8dfcb0e31e02008da008 Mon Sep 17 00:00:00 2001 From: RUEY JYE Date: Mon, 23 Mar 2020 21:32:51 +0900 Subject: [PATCH 08/13] fix config --- .circleci/config.yml | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 146f61d..9780140 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,6 +19,12 @@ commands: key: v1-gtest-cache-{{ .Branch }}-{{ .Revision }}-{{ checksum ".circleci/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 @@ -27,25 +33,19 @@ jobs: steps: - checkout - prepare_for_test - - run: - name: prepare build directory - command: | - mkdir build && cd build && ls && pwd + - prepare_for_cmake - run: name: build unit test command: | - ls && pwd && cmake .. -DGTEST=ON -DTEST_LEVEL=unit && make + cd build && cmake .. -DGTEST=ON -DTEST_LEVEL=unit && make - run: name: build integration test command: | - cmake .. -DGTEST=ON -DTEST_LEVEL=integration && make + cd build && cmake .. -DGTEST=ON -DTEST_LEVEL=integration && make - run: name: build system test command: | - cmake .. -DGTEST=ON -DTEST_LEVEL=system && make - - run: - name: back to working directory - command: cd .. + cd build && cmake .. -DGTEST=ON -DTEST_LEVEL=system && make - run: name: execute unit test command: ./gazosan_unit_test @@ -61,13 +61,10 @@ jobs: - image: rhikimochi/opencv-docker:v0.14 steps: - checkout - - run: - name: prepare build directory - command: | - mkdir build && cd build + - prepare_for_cmake - run: name: build gazosan - command: cmake .. -DGTEST=OFF && make && cd .. + command: cd build && cmake .. -DGTEST=OFF && make && cd .. - run: name: move static library command: mv build/libimageDiffCalc.a libimageDiffCalc.a From a3ed816a6e8da36709cc2456404e2fc1423e8e48 Mon Sep 17 00:00:00 2001 From: RUEY JYE Date: Mon, 23 Mar 2020 21:49:13 +0900 Subject: [PATCH 09/13] back shell file --- .circleci/build_googletest.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/build_googletest.sh b/.circleci/build_googletest.sh index 2ff8c2f..3a9263f 100644 --- a/.circleci/build_googletest.sh +++ b/.circleci/build_googletest.sh @@ -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 From 88f141f99adea17c8ca252141a6126653a32aaa6 Mon Sep 17 00:00:00 2001 From: RUEY JYE Date: Mon, 23 Mar 2020 21:53:26 +0900 Subject: [PATCH 10/13] debug --- .circleci/build_googletest.sh | 4 ++-- .circleci/config.yml | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.circleci/build_googletest.sh b/.circleci/build_googletest.sh index 3a9263f..2ff8c2f 100644 --- a/.circleci/build_googletest.sh +++ b/.circleci/build_googletest.sh @@ -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 diff --git a/.circleci/config.yml b/.circleci/config.yml index 9780140..2f560fc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -34,6 +34,10 @@ jobs: - checkout - prepare_for_test - prepare_for_cmake + - run: + name: debug + command: | + ls tests/googletest - run: name: build unit test command: | From 7d488fc3ae117f4ae8770823440a8d14a89b6000 Mon Sep 17 00:00:00 2001 From: RUEY JYE Date: Mon, 23 Mar 2020 21:56:52 +0900 Subject: [PATCH 11/13] remove cache --- .circleci/config.yml | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2f560fc..37fbb4c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,21 +4,9 @@ commands: 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 }}- - - v1-gtest-cache-{{ .Branch }}- - run: name: download and build google test - command: | - if [ ! -d tests/googletest ]; then - bash .circleci/build_googletest.sh; - fi - - save_cache: - key: v1-gtest-cache-{{ .Branch }}-{{ .Revision }}-{{ checksum ".circleci/build_googletest.sh" }} - paths: - - tests/googletest + command: bash .circleci/build_googletest.sh prepare_for_cmake: description: "Prepare directory for cmake." steps: @@ -34,10 +22,6 @@ jobs: - checkout - prepare_for_test - prepare_for_cmake - - run: - name: debug - command: | - ls tests/googletest - run: name: build unit test command: | From 46a19c17e9dcda54abecefea3110afcc7e618b77 Mon Sep 17 00:00:00 2001 From: RUEY JYE Date: Mon, 23 Mar 2020 22:10:45 +0900 Subject: [PATCH 12/13] fix cmake list --- .circleci/config.yml | 14 +++++++++++++- CMakeLists.txt | 6 +++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 37fbb4c..9780140 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,9 +4,21 @@ commands: 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 }}- + - v1-gtest-cache-{{ .Branch }}- - run: name: download and build google test - command: bash .circleci/build_googletest.sh + command: | + if [ ! -d tests/googletest ]; then + bash .circleci/build_googletest.sh; + fi + - save_cache: + key: v1-gtest-cache-{{ .Branch }}-{{ .Revision }}-{{ checksum ".circleci/build_googletest.sh" }} + paths: + - tests/googletest prepare_for_cmake: description: "Prepare directory for cmake." steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index 576a07b..bd78fe7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,13 +16,13 @@ if(GTEST) if( ${TEST_LEVEL} STREQUAL "unit" ) add_executable(gazosan_unit_test tests/unit_tests/imageDiffCalc_test.cpp) - target_link_libraries( gazosan_unit_test ${OpenCV_LIBS} ${gtest} ${gtest_main} ) + target_link_libraries( gazosan_unit_test ${OpenCV_LIBS} ${gtest} ${gtest_main} -lpthread ) elseif( ${TEST_LEVEL} STREQUAL "integration" ) add_executable( gazosan_integration_test tests/integration_tests/imageDiffCalc_test.cpp ) - target_link_libraries( gazosan_integration_test ${OpenCV_LIBS} ${gtest} ${gtest_main} ) + target_link_libraries( gazosan_integration_test ${OpenCV_LIBS} ${gtest} ${gtest_main} -lpthread ) elseif( ${TEST_LEVEL} STREQUAL "system" ) add_executable( gazosan_system_test tests/system_tests/imageDiffCalc_test.cpp ) - target_link_libraries( gazosan_system_test ${OpenCV_LIBS} ${gtest} ${gtest_main} ) + target_link_libraries( gazosan_system_test ${OpenCV_LIBS} ${gtest} ${gtest_main} -lpthread ) endif() else() set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin ) From 350111c88da369a457f4e37e5cef6e97e015f54e Mon Sep 17 00:00:00 2001 From: RUEY JYE Date: Thu, 26 Mar 2020 08:58:55 +0900 Subject: [PATCH 13/13] fix for review --- .circleci/config.yml | 8 ++++---- CMakeLists.txt | 22 +++++++++++++++------- {.circleci => tests}/build_googletest.sh | 0 3 files changed, 19 insertions(+), 11 deletions(-) rename {.circleci => tests}/build_googletest.sh (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9780140..f01e8ab 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,17 +6,17 @@ commands: 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/build_googletest.sh" }} + key: v1-gtest-cache-{{ .Branch }}-{{ .Revision }}-{{ checksum "tests/build_googletest.sh" }} paths: - tests/googletest prepare_for_cmake: @@ -64,7 +64,7 @@ jobs: - prepare_for_cmake - run: name: build gazosan - command: cd build && cmake .. -DGTEST=OFF && make && cd .. + command: cd build && cmake .. && make - run: name: move static library command: mv build/libimageDiffCalc.a libimageDiffCalc.a diff --git a/CMakeLists.txt b/CMakeLists.txt index bd78fe7..d5c280d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,15 @@ 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/ ) @@ -16,29 +23,30 @@ if(GTEST) if( ${TEST_LEVEL} STREQUAL "unit" ) add_executable(gazosan_unit_test tests/unit_tests/imageDiffCalc_test.cpp) - target_link_libraries( gazosan_unit_test ${OpenCV_LIBS} ${gtest} ${gtest_main} -lpthread ) + 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 ${OpenCV_LIBS} ${gtest} ${gtest_main} -lpthread ) + 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 ${OpenCV_LIBS} ${gtest} ${gtest_main} -lpthread ) + 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( gazosan src/main.cpp ) - target_link_libraries( gazosan ${OpenCV_LIBS} ${CMAKE_SOURCE_DIR}/libimageDiffCalc.a ) + 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( gazosan src/main.cpp ) - target_link_libraries( gazosan ${OpenCV_LIBS} imageDiffCalc ) + add_executable( ${BIN_NAME} src/main.cpp ) + target_link_libraries( ${BIN_NAME} ${OpenCV_LIBS} imageDiffCalc ) endif() endif() \ No newline at end of file diff --git a/.circleci/build_googletest.sh b/tests/build_googletest.sh similarity index 100% rename from .circleci/build_googletest.sh rename to tests/build_googletest.sh