Skip to content

Commit 4333370

Browse files
authored
Merge pull request #24 from ikeyasu/cmake
Change build system to CMake
2 parents 61aa11b + 7cfc0dd commit 4333370

11 files changed

+135
-193
lines changed

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CMakeCache.txt
2222
CMakeFiles
2323
cmake_install.cmake
2424
install_manifest.txt
25+
CTestTestfile.cmake
2526

2627
#ignore thumbnails created by windows
2728
Thumbs.db
@@ -56,5 +57,9 @@ _ReSharper*/
5657
build*/
5758
*~
5859

59-
#ignore binaries
60-
*_unittest
60+
#ignore executable binaries
61+
test/test_all
62+
63+
#ignore external lib
64+
/lib/gmock/gmock/
65+
/lib/gtest/gtest/

.travis.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
language: cpp
2+
sudo: false
23
compiler:
3-
- gcc
4+
- gcc
45
before_install:
5-
- sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu/ trusty main universe"
6-
- sudo apt-get update -qq
7-
- sudo apt-get install astyle=2.03-1 -qq
6+
# astyle-2.03
7+
# downloading astyle-2.03
8+
- mkdir -p .travis-tmp/astyle-2.03
9+
- wget -P .travis-tmp/astyle-2.03/ http://heanet.dl.sourceforge.net/project/astyle/astyle/astyle%202.03/astyle_2.03_linux.tar.gz
10+
- tar xvzf .travis-tmp/astyle-2.03/astyle_2.03_linux.tar.gz -C .travis-tmp/astyle-2.03/
11+
# build astyle-2.03
12+
- pushd .travis-tmp/astyle-2.03/astyle/build/gcc && make && export PATH=`pwd`/bin:$PATH && popd
13+
# cmake-3.2.2
14+
- mkdir -p .travis-tmp/cmake-3.2.2
15+
- wget --no-check-certificate -P .travis-tmp/cmake-3.2.2/ https://cmake.org/files/v3.2/cmake-3.2.2-Linux-x86_64.sh
16+
- bash .travis-tmp/cmake-3.2.2/cmake-3.2.2-Linux-x86_64.sh --exclude-subdir --prefix=.travis-tmp/cmake-3.2.2 --skip-license
17+
- export PATH=`pwd`/.travis-tmp/cmake-3.2.2/bin:$PATH
818
script:
9-
- pushd test && make test && popd
19+
- ./build.sh
1020
- ./script/travis_format_checcker.sh

CMakeLists.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
cmake_minimum_required (VERSION 2.8.8)
2+
project (arduino_mock)
3+
4+
find_package(Threads REQUIRED)
5+
add_subdirectory(lib/gtest)
6+
add_subdirectory(lib/gmock)
7+
8+
message ("building arduino_mock")
9+
message("Gtest include: ${GTEST_INCLUDE_DIRS}")
10+
message("Gmock include: ${GMOCK_INCLUDE_DIRS}")
11+
include_directories(${GTEST_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS} include)
12+
file(GLOB SRC
13+
"src/ArduinoMockAll.cc"
14+
)
15+
16+
add_library(arduino_mock STATIC ${SRC})
17+
18+
target_include_directories(arduino_mock
19+
PUBLIC "include"
20+
)
21+
22+
target_link_libraries(arduino_mock
23+
${GTEST_LIBS_DIR}/libgtest.a
24+
${GMOCK_LIBS_DIR}/libgmock.a
25+
${CMAKE_THREAD_LIBS_INIT}
26+
)
27+
28+
set_target_properties( arduino_mock
29+
PROPERTIES
30+
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dist/lib"
31+
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dist/lib"
32+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dist/bin"
33+
)
34+
35+
add_dependencies(arduino_mock gtest gmock)
36+
37+
option(test "Build all tests." OFF)
38+
39+
if (test)
40+
enable_testing()
41+
add_subdirectory(test)
42+
endif()

build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
cd -- "$(dirname -- "$0")"
5+
mkdir -p build
6+
cd build
7+
cmake -Dtest=ON ..
8+
make
9+
ctest -V

lib/gmock/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 2.8.8)
2+
project(gmock_builder C CXX)
3+
include(ExternalProject)
4+
5+
ExternalProject_Add(gmock
6+
URL https://googlemock.googlecode.com/files/gmock-1.7.0.zip
7+
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gmock
8+
INSTALL_COMMAND ""
9+
)
10+
11+
# Specify include dir
12+
ExternalProject_Get_Property(gmock source_dir)
13+
set(GMOCK_INCLUDE_DIRS ${source_dir}/include PARENT_SCOPE)
14+
15+
# Specify MainTest's link libraries
16+
ExternalProject_Get_Property(gmock binary_dir)
17+
set(GMOCK_LIBS_DIR ${binary_dir} PARENT_SCOPE)

lib/gtest/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
message("in gtest")
2+
project(gtest_builder C CXX)
3+
include(ExternalProject)
4+
5+
ExternalProject_Add(gtest
6+
URL https://googletest.googlecode.com/files/gtest-1.7.0.zip
7+
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gtest
8+
INSTALL_COMMAND ""
9+
)
10+
11+
# Specify include dir
12+
ExternalProject_Get_Property(gtest source_dir)
13+
set(GTEST_INCLUDE_DIRS ${source_dir}/include PARENT_SCOPE)
14+
15+
# Specify MainTest's link libraries
16+
ExternalProject_Get_Property(gtest binary_dir)
17+
set(GTEST_LIBS_DIR ${binary_dir} PARENT_SCOPE)

test/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
message ("building tests for Arduino Mock")
2+
# include_directories(${GTEST_INCLUDE_DIRS})
3+
file(GLOB SRCS *.cc)
4+
5+
add_executable(test_all test_all.cc)
6+
7+
target_link_libraries(test_all
8+
arduino_mock
9+
${GTEST_LIBS_DIR}/libgtest.a
10+
${GTEST_LIBS_DIR}/libgtest_main.a
11+
${GMOCK_LIBS_DIR}/libgmock.a
12+
${CMAKE_THREAD_LIBS_INIT}
13+
)
14+
15+
add_dependencies(test_all gtest)
16+
add_test(arduino_mock_test test_all)

test/Makefile

Lines changed: 0 additions & 184 deletions
This file was deleted.

test/gmock

Submodule gmock deleted from 896ba0e

test/googletest

Submodule googletest deleted from 4650552

test/test_all.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "Arduino_unittest.cc"
2+
#include "EEPROM_unittest.cc"
3+
#include "Serial_unittest.cc"
4+
#include "serialHelper_unittest.cc"
5+
#include "Spark_unittest.cc"
6+
#include "WiFi_unittest.cc"
7+
#include "Wire_unittest.cc"
8+
9+
int main(int argc, char* argv[]) {
10+
::testing::InitGoogleTest(&argc, argv);
11+
return RUN_ALL_TESTS();
12+
}

0 commit comments

Comments
 (0)