1 # Copyright 2017 Nest Labs, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Configure the compiler.
18 # Other options: -std=c++0x -stdlib=libstdc++
20 # Sometimes it's worth trying -nostdinc++ to see what leaked.
21 LITE_CONFIG ?= -DBUILD_FEATURE_DETECTORGRAPH_CONFIG_LITE -fno-exceptions -fno-rtti -Os
24 # Enables std::static_asserts for checking library usage patterns.
25 LITE_CONFIG += -DBUILD_FEATURE_DETECTORGRAPH_CONFIG_STATIC_ASSERTS -DBUILD_FEATURE_DETECTORGRAPH_CONFIG_PERFECT_FORWARDING
27 # Uses own implementation of 64bit % 64bit operator (this is used on TimeoutPublisherService)
28 # LITE_CONFIG += -DBUILD_FEATURE_DETECTORGRAPH_CONFIG_NO_64BIT_REMAINDER
30 # To use the lite version of the library in the examples swap the config below
31 CONFIG ?= $(FULL_CONFIG)
32 # CONFIG=$(LITE_CONFIG)
34 # Enables a bunch of debug logs that help understand Graph and TimeoutPublisherService resource usage.
35 # CONFIG += -DBUILD_FEATURE_DETECTORGRAPH_CONFIG_INSTRUMENT_RESOURCE_USAGE
37 CXXFLAGS ?=-Wall -Werror -Wno-error=deprecated -Werror=sign-compare
39 # The core library will work fine without C++11 but some examples rely on it
40 # CPPSTD=-stdlib=libstdc++
42 # Core Library Include folder and sources
43 CORE_INCLUDE=./include
44 CORE_SRCS=src/graph.cpp \
46 src/timeoutpublisherservice.cpp \
49 # TODO(DGRAPH-10): TimeoutPublisherService on lite.
50 FULL_SRCS=$(CORE_SRCS) \
51 src/statesnapshot.cpp \
52 src/graphstatestore.cpp \
56 # Platform-specific headers and implementations
57 PLATFORM=./platform_standalone
58 PLATFORM_SRCS=$(PLATFORM)/dglogging.cpp
60 # Graph Analysis and Tools
62 UTIL_SRCS=$(UTIL)/graphanalyzer.cpp \
63 $(UTIL)/nodenameutils.cpp \
68 TEST_UTIL_SRCS=$(TEST_UTIL)/testtimeoutpublisherservice.cpp \
69 $(TEST_UTIL)/graphtestutils.cpp \
73 NLUNITTEST=./third_party/nltest/repo/src/
74 NLUNITTEST_SRCS=$(NLUNITTEST)/nltest.c
76 COMMON_TESTS=./unit-test/common
77 FULL_TESTS=./unit-test/full
78 LITE_TESTS=./unit-test/lite
79 COMMON_TESTS_SRCS=$(wildcard $(COMMON_TESTS)/*.cpp)
80 FULL_TESTS_SRCS=$(wildcard $(FULL_TESTS)/*.cpp)
81 LITE_TESTS_SRCS=$(wildcard $(LITE_TESTS)/*.cpp)
85 doxygen ./doxygen/Doxyfile
87 unit-test/test_all: unit-test/test_full unit-test/test_lite
88 @echo Ran unit tests for the Vanilla and Lite configs of the library
91 $(CXX) $(CPPSTD) $(CXXFLAGS) $(FULL_CONFIG) -g -I$(CORE_INCLUDE) -I$(PLATFORM) -I$(UTIL) -I$(TEST_UTIL) -I$(NLUNITTEST) -I$(COMMON_TESTS) -I$(FULL_TESTS) $(FULL_SRCS) $(PLATFORM_SRCS) $(UTIL_SRCS) $(TEST_UTIL_SRCS) $(NLUNITTEST_SRCS) $(COMMON_TESTS_SRCS) $(FULL_TESTS_SRCS) -o test_full.out && ./test_full.out
94 $(CXX) $(CPPSTD) $(CXXFLAGS) $(LITE_CONFIG) -g -I$(CORE_INCLUDE) -I$(PLATFORM) -I$(TEST_UTIL) -I$(NLUNITTEST) -I$(COMMON_TESTS) -I$(LITE_TESTS) $(CORE_SRCS) $(PLATFORM_SRCS) $(TEST_UTIL_SRCS) $(NLUNITTEST_SRCS) $(COMMON_TESTS_SRCS) $(LITE_TESTS_SRCS) -o test_lite.out && ./test_lite.out
97 # Minimal Include & Sources dependencies
98 $(CXX) $(CPPSTD) $(CXXFLAGS) $(CONFIG) -g -I$(CORE_INCLUDE) -I$(PLATFORM) $(FULL_SRCS) $(PLATFORM_SRCS) examples/helloworld.cpp -o helloworld.out && ./helloworld.out
100 examples/robotlocalization:
101 # Note that this example depends on the Eigen library. For more info see
102 # https://eigen.tuxfamily.org/dox/GettingStarted.html
103 # If Eigen is not installed in your default include path you may need to
104 # add it (e.g. -I/usr/include/eigen3 ).
105 # Additionally, some versions of Eigen3 throw a bunch of warnings when
106 # compiling so you may need to turn off -Werror in CXXFLAGS at the top of this
108 $(CXX) $(CPPSTD) $(CXXFLAGS) $(CONFIG) -g -I$(CORE_INCLUDE) -I$(PLATFORM) -I$(UTIL) $(FULL_SRCS) $(PLATFORM_SRCS) $(UTIL_SRCS) examples/robotlocalization.cpp -o robotlocalization.out && ./robotlocalization.out
110 examples/beatmachine:
111 # Keeping a separate rule for this example so that we don't run it as it
112 # takes way too long to run it (2mins!)
113 $(CXX) $(CPPSTD) $(CXXFLAGS) $(CONFIG) -g -I$(CORE_INCLUDE) -I$(PLATFORM) -I$(UTIL) $(FULL_SRCS) $(PLATFORM_SRCS) $(UTIL_SRCS) examples/beatmachine.cpp -o beatmachine.out
116 # General Purpose Example building rule.
117 $(CXX) $(CPPSTD) $(CXXFLAGS) $(CONFIG) -g -I$(CORE_INCLUDE) -I$(PLATFORM) -I$(UTIL) $(FULL_SRCS) $(PLATFORM_SRCS) $(UTIL_SRCS) $@.cpp -o $(@:examples/%=%.out) && ./$(@:examples/%=%.out)
119 examples/all: $(basename $(wildcard examples/*.cpp))
120 @echo Built and Ran all Examples
122 unit-test/test_coverage: cleancoverage
123 $(CXX) $(CPPSTD) $(CXXFLAGS) $(CONFIG) --coverage -g -I$(CORE_INCLUDE) -I$(PLATFORM) -I$(UTIL) -I$(TEST_UTIL) -I$(NLUNITTEST) -I$(COMMON_TESTS) -I$(FULL_TESTS) $(FULL_SRCS) $(PLATFORM_SRCS) $(UTIL_SRCS) $(TEST_UTIL_SRCS) $(NLUNITTEST_SRCS) $(COMMON_TESTS_SRCS) $(FULL_TESTS_SRCS) -o test_coverage && ./test_coverage
125 lcov --capture --directory . --no-external \
126 -q --output-file coverage/coverage.info
127 lcov --remove coverage/coverage.info "*/third_party/*" \
128 -q --output-file coverage/coverage.info
129 lcov --extract coverage/coverage.info "*/src/*" \
130 --extract coverage/coverage.info "*/include/*" \
131 --extract coverage/coverage.info "*/unit-test/*" \
132 --extract coverage/coverage.info "*/test-util/*" \
133 -q --output-file coverage/coverage.info
134 lcov -l coverage/coverage.info > coverage/coverage.txt
135 genhtml coverage/coverage.info --output-directory coverage/.
137 code_size_benchmark/%:
138 $(CXX) $(CPPSTD) $(CXXFLAGS) -DNDEBUG $(LITE_CONFIG) -I$(CORE_INCLUDE) -I$(PLATFORM) -I$(dir $@) $(CORE_SRCS) $(PLATFORM_SRCS) $@.cpp -o $(@:code_size_benchmark/%/main=%.out) \
139 && ./$(@:code_size_benchmark/%/main=%.out) \
140 && size $(@:code_size_benchmark/%/main=%.out) \
141 && objdump -h $(@:code_size_benchmark/%/main=%.out)
143 code_size_benchmark/all: $(basename $(wildcard code_size_benchmark/*/main.cpp))
144 @echo Built and Ran all Benchmarks
146 all: unit-test/test_all docs examples/all unit-test/test_coverage
152 rm -fr *.gcda *.gcno coverage
154 clean: cleancoverage cleandocs
155 rm -rf *.out* test_all* test_coverage* *.gcda *.gcno *.o coverage