Skip to content

Commit cc288a0

Browse files
committed
Cmake
1 parent e1bb7ea commit cc288a0

12 files changed

Lines changed: 176 additions & 19 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.pioenvs
22
.piolibdeps
3+
/external/unity/*-repo/
4+
/build/

.travis.yml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1-
language: python
2-
python:
3-
- "2.7"
4-
1+
dist: trusty
52
sudo: false
6-
cache:
7-
directories:
8-
- "~/.platformio"
3+
group: beta
4+
5+
language: cpp
6+
7+
matrix:
8+
include:
9+
- compiler: gcc
10+
addons:
11+
apt:
12+
sources:
13+
- ubuntu-toolchain-r-test
14+
packages:
15+
- git
16+
- g++-5
17+
env: COMPILER=g++-5
918

10-
install:
11-
- pip install -U platformio
19+
- compiler: clang
20+
addons:
21+
apt:
22+
sources:
23+
- ubuntu-toolchain-r-test
24+
- llvm-toolchain-precise-3.6
25+
packages:
26+
- git
27+
- clang-3.6
28+
env: COMPILER=clang++-3.6
1229

1330
script:
14-
- platformio test
31+
- git --version
32+
- cmake --version
33+
- make --version
34+
- make build test

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cmake_minimum_required(VERSION 3.2.2)
2+
project(ArduinoFake VERSION 0.1)
3+
4+
set(CMAKE_CXX_STANDARD 11)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
8+
9+
# Include external libs
10+
add_subdirectory(external)
11+
12+
# Targets that we develop here
13+
enable_testing()
14+
15+
add_subdirectory(src)
16+
add_subdirectory(test)

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
default_target: all
2+
3+
all: clean build test clean
4+
5+
cmake:
6+
@cmake $(CURDIR) -B$(CURDIR)/build
7+
8+
build: cmake
9+
@cd $(CURDIR)/build && make all
10+
11+
test:
12+
@cd $(CURDIR)/build && CTEST_OUTPUT_ON_FAILURE=TRUE make test
13+
14+
pio-test:
15+
@pio test
16+
17+
clean:
18+
@rm -rf $(CURDIR)/build/*
19+
@rm -rf $(CURDIR)/.pioenvs/*
20+
21+
.PHONY: cmake build test clean all

cmake/git-download.cmake

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
find_package(Git REQUIRED)
2+
3+
function(execute_git)
4+
set(options "")
5+
set(oneValueArgs
6+
OUTPUT_VARIABLE
7+
)
8+
set(multiValueArgs
9+
COMMAND
10+
)
11+
cmake_parse_arguments(args "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
12+
13+
execute_process(
14+
COMMAND ${GIT_EXECUTABLE} ${args_COMMAND}
15+
OUTPUT_VARIABLE GIT_RESULT
16+
)
17+
18+
set(${args_OUTPUT_VARIABLE} ${GIT_RESULT} PARENT_SCOPE)
19+
endfunction()
20+
21+
function(download_repo)
22+
set(options "")
23+
set(oneValueArgs
24+
URL
25+
TAG
26+
CLONE_DIR
27+
)
28+
set(multiValueArgs "")
29+
cmake_parse_arguments(args "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
30+
31+
# If no tag is specified, default to master
32+
if(NOT args_TAG)
33+
set(args_TAG master)
34+
endif()
35+
36+
execute_git(
37+
COMMAND rev-parse --show-toplevel
38+
OUTPUT_VARIABLE GIT_ROOT
39+
)
40+
41+
# Need to remove linebreak
42+
string(STRIP ${GIT_ROOT} GIT_ROOT)
43+
44+
# Make clone-dir path relative to git-root
45+
string(REPLACE ${GIT_ROOT}/ "" RELATIVE_CLONE_DIR ${args_CLONE_DIR})
46+
47+
if(NOT EXISTS ${args_CLONE_DIR})
48+
message("Cloning branch ${args_TAG} from ${args_URL} into directory ${args_CLONE_DIR}")
49+
execute_git(
50+
COMMAND clone --depth=50 --branch=${args_TAG} ${args_URL} ${args_CLONE_DIR}
51+
WORKING_DIRECTORY ${GIT_ROOT}
52+
)
53+
endif()
54+
55+
endfunction()

external/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Include external libs
2+
add_subdirectory(unity)

external/unity/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
cmake_minimum_required(VERSION 3.2.2)
2+
project(unity VERSION 2.4.1 LANGUAGES C)
3+
4+
include(git-download)
5+
6+
set(REPO_DIR ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}-repo)
7+
8+
download_repo(
9+
URL "https://github.com/ThrowTheSwitch/Unity.git"
10+
TAG v${PROJECT_VERSION}
11+
CLONE_DIR ${REPO_DIR}
12+
)
13+
14+
add_library(${PROJECT_NAME} STATIC
15+
${REPO_DIR}/src/unity.c
16+
)
17+
18+
target_include_directories(${PROJECT_NAME} PUBLIC
19+
${REPO_DIR}/src
20+
)

src/ArduinoFake.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
#endif
66

77
#include <cstring>
8-
#include <fakeit/fakeit.hpp>
8+
#include "fakeit/fakeit.hpp"
99

10-
#include <FunctionFake.h>
11-
#include <StreamFake.h>
12-
#include <SerialFake.h>
13-
#include <ClientFake.h>
14-
#include <PrintFake.h>
10+
#include "FunctionFake.h"
11+
#include "StreamFake.h"
12+
#include "SerialFake.h"
13+
#include "ClientFake.h"
14+
#include "PrintFake.h"
1515

16-
#include <arduino/Arduino.h>
16+
#include "arduino/Arduino.h"
1717

1818
#define ArduinoFakeGetFunction() ArduinoFakeGetter(Function)
1919
#define ArduinoFakeGetSerial() ArduinoFakeGetter(Serial)

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
aux_source_directory(. SRC_LIST)
2+
aux_source_directory(./fakeit SRC_LIST)
3+
aux_source_directory(./arduino SRC_LIST)
4+
5+
add_library(${PROJECT_NAME} SHARED ${SRC_LIST})

src/FunctionFake.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef FUNCTION_FAKE_H
22
#define FUNCTION_FAKE_H
33

4-
#include <fakeit/fakeit.hpp>
4+
#include "fakeit/fakeit.hpp"
55

66
struct FunctionFake
77
{

0 commit comments

Comments
 (0)