Skip to content

Commit

Permalink
Merge pull request #24 from ikeyasu/cmake
Browse files Browse the repository at this point in the history
Change build system to CMake
  • Loading branch information
ikeyasu authored Aug 12, 2016
2 parents 61aa11b + 7cfc0dd commit 4333370
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 193 deletions.
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CMakeCache.txt
CMakeFiles
cmake_install.cmake
install_manifest.txt
CTestTestfile.cmake

#ignore thumbnails created by windows
Thumbs.db
Expand Down Expand Up @@ -56,5 +57,9 @@ _ReSharper*/
build*/
*~

#ignore binaries
*_unittest
#ignore executable binaries
test/test_all

#ignore external lib
/lib/gmock/gmock/
/lib/gtest/gtest/
20 changes: 15 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
language: cpp
sudo: false
compiler:
- gcc
- gcc
before_install:
- sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu/ trusty main universe"
- sudo apt-get update -qq
- sudo apt-get install astyle=2.03-1 -qq
# astyle-2.03
# downloading astyle-2.03
- mkdir -p .travis-tmp/astyle-2.03
- wget -P .travis-tmp/astyle-2.03/ http://heanet.dl.sourceforge.net/project/astyle/astyle/astyle%202.03/astyle_2.03_linux.tar.gz
- tar xvzf .travis-tmp/astyle-2.03/astyle_2.03_linux.tar.gz -C .travis-tmp/astyle-2.03/
# build astyle-2.03
- pushd .travis-tmp/astyle-2.03/astyle/build/gcc && make && export PATH=`pwd`/bin:$PATH && popd
# cmake-3.2.2
- mkdir -p .travis-tmp/cmake-3.2.2
- 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
- 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
- export PATH=`pwd`/.travis-tmp/cmake-3.2.2/bin:$PATH
script:
- pushd test && make test && popd
- ./build.sh
- ./script/travis_format_checcker.sh
42 changes: 42 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required (VERSION 2.8.8)
project (arduino_mock)

find_package(Threads REQUIRED)
add_subdirectory(lib/gtest)
add_subdirectory(lib/gmock)

message ("building arduino_mock")
message("Gtest include: ${GTEST_INCLUDE_DIRS}")
message("Gmock include: ${GMOCK_INCLUDE_DIRS}")
include_directories(${GTEST_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS} include)
file(GLOB SRC
"src/ArduinoMockAll.cc"
)

add_library(arduino_mock STATIC ${SRC})

target_include_directories(arduino_mock
PUBLIC "include"
)

target_link_libraries(arduino_mock
${GTEST_LIBS_DIR}/libgtest.a
${GMOCK_LIBS_DIR}/libgmock.a
${CMAKE_THREAD_LIBS_INIT}
)

set_target_properties( arduino_mock
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dist/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dist/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dist/bin"
)

add_dependencies(arduino_mock gtest gmock)

option(test "Build all tests." OFF)

if (test)
enable_testing()
add_subdirectory(test)
endif()
9 changes: 9 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -eu

cd -- "$(dirname -- "$0")"
mkdir -p build
cd build
cmake -Dtest=ON ..
make
ctest -V
17 changes: 17 additions & 0 deletions lib/gmock/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 2.8.8)
project(gmock_builder C CXX)
include(ExternalProject)

ExternalProject_Add(gmock
URL https://googlemock.googlecode.com/files/gmock-1.7.0.zip
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gmock
INSTALL_COMMAND ""
)

# Specify include dir
ExternalProject_Get_Property(gmock source_dir)
set(GMOCK_INCLUDE_DIRS ${source_dir}/include PARENT_SCOPE)

# Specify MainTest's link libraries
ExternalProject_Get_Property(gmock binary_dir)
set(GMOCK_LIBS_DIR ${binary_dir} PARENT_SCOPE)
17 changes: 17 additions & 0 deletions lib/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
message("in gtest")
project(gtest_builder C CXX)
include(ExternalProject)

ExternalProject_Add(gtest
URL https://googletest.googlecode.com/files/gtest-1.7.0.zip
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gtest
INSTALL_COMMAND ""
)

# Specify include dir
ExternalProject_Get_Property(gtest source_dir)
set(GTEST_INCLUDE_DIRS ${source_dir}/include PARENT_SCOPE)

# Specify MainTest's link libraries
ExternalProject_Get_Property(gtest binary_dir)
set(GTEST_LIBS_DIR ${binary_dir} PARENT_SCOPE)
16 changes: 16 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
message ("building tests for Arduino Mock")
# include_directories(${GTEST_INCLUDE_DIRS})
file(GLOB SRCS *.cc)

add_executable(test_all test_all.cc)

target_link_libraries(test_all
arduino_mock
${GTEST_LIBS_DIR}/libgtest.a
${GTEST_LIBS_DIR}/libgtest_main.a
${GMOCK_LIBS_DIR}/libgmock.a
${CMAKE_THREAD_LIBS_INIT}
)

add_dependencies(test_all gtest)
add_test(arduino_mock_test test_all)
184 changes: 0 additions & 184 deletions test/Makefile

This file was deleted.

1 change: 0 additions & 1 deletion test/gmock
Submodule gmock deleted from 896ba0
1 change: 0 additions & 1 deletion test/googletest
Submodule googletest deleted from 465055
12 changes: 12 additions & 0 deletions test/test_all.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "Arduino_unittest.cc"
#include "EEPROM_unittest.cc"
#include "Serial_unittest.cc"
#include "serialHelper_unittest.cc"
#include "Spark_unittest.cc"
#include "WiFi_unittest.cc"
#include "Wire_unittest.cc"

int main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit 4333370

Please sign in to comment.