Skip to content

Commit

Permalink
Get precompiled headers working for unit tests too
Browse files Browse the repository at this point in the history
  • Loading branch information
seantalts committed Nov 5, 2017
1 parent 5753b3c commit 7a04063
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 16 deletions.
101 changes: 86 additions & 15 deletions make/tests
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,10 @@ GTEST_CXXFLAGS += -isystem $(GTEST)/include -isystem $(GTEST) -O$O
##
# Build the google test library.
##
$(GTEST)/src/gtest-all.o: CXXFLAGS += $(GTEST_CXXFLAGS)

PCH_HEADER := stan/math/mix/mat.hpp
PCH := $(PCH_HEADER:.hpp=.hpp.gch)

$(PCH) : $(PCH_HEADER)
@echo 'Compiling PCH'
$(COMPILE.cpp) -O$O $(PCH_HEADER) -o $@

test/prob/%.o : test/prob/%.cpp $(PCH)
$(COMPILE.cpp) -include-pch $(PCH) -O$O -o $@ $<

test/%$(EXE) : CXXFLAGS += $(GTEST_CXXFLAGS)
test/%$(EXE) : test/%.o $(GTEST_MAIN) $(GTEST)/src/gtest-all.o
$(LINK.cpp) -o $@ $^
$(GTEST)/src/gtest-all.o: $(GTEST)/src/gtest-all.cc
$(COMPILE.cpp) -o $@ $<

$(GTEST)/%.cc: ;

##
# Rule for generating dependencies.
Expand All @@ -51,6 +39,7 @@ test/unit/libmultiple.so : test/unit/multiple_translation_units1.o test/unit/mul

test/unit/multiple_translation_units_test.cpp : test/unit/libmultiple.so


############################################################
#
# CVODES tests
Expand Down Expand Up @@ -84,6 +73,88 @@ test/dummy.cpp:
.PHONY: test-headers
test-headers: $(HEADER_TESTS)

test/unit/math_include_test.o: test/unit/math_include_test.cpp
$(COMPILE.cpp) $< -o $@

############################################################
#
# General make targets for tests
# (necessary now that implicit SUFFIX rules are actually turned off)
#

test/%$(EXE) : CXXFLAGS += $(GTEST_CXXFLAGS)
test/%$(EXE) : test/%.o $(GTEST_MAIN) $(GTEST)/src/gtest-all.o
$(LINK.cpp) -o $@ $^

# We need these explicit targets here because we turned off suffixes. We can't
# make a more general pattern rule like test/%.o because we want to force make
# to generate the pre-compiled headers (below) when applicable.
test/unit/math_c11_test.o: test/unit/math_c11_test.cpp
$(COMPILE.cpp) $< -o $@

test/unit/math/memory/%.o: test/unit/math/memory/%.cpp
$(COMPILE.cpp) $< -o $@

############################################################
#
# Targets to include proper pre-compiled header files (.hpp.gch) for unit tests
# and distribution tests
##

.PRECIOUS: %.hpp.gch test/%.o

%.hpp.gch: %.hpp
$(COMPILE.cpp) -o $@ $(@:.gch=)

test/prob/%.o : stan/math/mix/mat.hpp.gch test/prob/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)

test/unit/math/prim/scal/%.o : stan/math/prim/scal.hpp.gch test/unit/math/prim/scal/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)

test/unit/math/prim/arr/%.o : stan/math/prim/arr.hpp.gch test/unit/math/prim/arr/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)

test/unit/math/prim/mat/%.o : tstan/math/prim/mat.hpp.gch test/unit/math/prim/mat/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)

test/unit/math/rev/core/%.o : tstan/math/rev/core.hpp.gch test/unit/math/rev/core/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)

test/unit/math/rev/scal/%.o : tstan/math/rev/scal.hpp.gch test/unit/math/rev/scal/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)

test/unit/math/rev/arr/%.o : stan/math/rev/arr.hpp.gch test/unit/math/rev/arr/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)

test/unit/math/rev/mat/%.o : stan/math/rev/mat.hpp.gch test/unit/math/rev/mat/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)

test/unit/math/fwd/core/%.o : stan/math/fwd/core.hpp.gch test/unit/math/fwd/core/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)

test/unit/math/fwd/scal/%.o : stan/math/fwd/scal.hpp.gch test/unit/math/fwd/scal/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)

test/unit/math/fwd/arr/%.o : stan/math/fwd/arr.hpp.gch test/unit/math/fwd/arr/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)

test/unit/math/fwd/mat/%.o : stan/math/fwd/mat.hpp.gch test/unit/math/fwd/mat/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)

test/unit/math/mix/core/%.o : stan/math/mix/core.hpp.gch test/unit/math/mix/core/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)

test/unit/math/mix/scal/%.o : stan/math/mix/scal.hpp.gch test/unit/math/mix/scal/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)

test/unit/math/mix/arr/%.o : stan/math/mix/arr.hpp.gch test/unit/math/mix/arr/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)

test/unit/math/mix/mat/%.o : stan/math/mix/mat.hpp.gch test/unit/math/mix/mat/%.cpp
$(COMPILE.cpp) -include-pch $< -o $@ $(@:.o=.cpp)


############################################################
##
# Test generator for distribution tests
Expand Down
2 changes: 2 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Makefile for Stan.
##

.SUFFIXES:

# The default target of this Makefile is...
help:

Expand Down
2 changes: 1 addition & 1 deletion runTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

winsfx = ".exe"
testsfx = "_test.cpp"
batchSize = 25
batchSize = 32


def processCLIArgs():
Expand Down

0 comments on commit 7a04063

Please sign in to comment.