Skip to content

Commit

Permalink
Use a precompiled header to speed-up compilation.
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaut-cea committed Jan 31, 2019
1 parent 2daae93 commit 1eb0d47
Show file tree
Hide file tree
Showing 4 changed files with 4,263 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Expand Up @@ -74,6 +74,7 @@ endmacro()


set_globals()
include("${CMAKE_CURRENT_LIST_DIR}/cmake/modules/cotire.cmake")
project(N2D2)


Expand Down Expand Up @@ -154,6 +155,10 @@ if(MSVC)
endif()


set_target_properties(n2d2_lib PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
set_target_properties(n2d2_lib PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "${CMAKE_CURRENT_LIST_DIR}/include/Precompiled.hpp")
cotire(n2d2_lib)


# n2d2_lib_cuda target
find_package(CUDA)
Expand Down Expand Up @@ -191,7 +196,6 @@ endif()




# The CMake is used directly and not through add_subdirectory
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
# n2d2 target
Expand Down
28 changes: 18 additions & 10 deletions Makefile
Expand Up @@ -22,11 +22,13 @@ ifndef PARENT
PARENT=.
endif

MAKEFILE_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

EXT=cpp
EXT_CUDA=cu

BIN:=$(foreach path, $(PARENT), $(subst .$(EXT),, $(shell find $(path)/exec/ -name "*.$(EXT)")))
BIN_TESTS:=$(foreach path, $(PARENT), $(subst .$(EXT),, $(shell find $(path)/tests/ -name "*.$(EXT)")))
BIN:=$(foreach path, $(PARENT), $(subst .$(EXT),, $(shell find "$(path)/exec/" -name "*.$(EXT)")))
BIN_TESTS:=$(foreach path, $(PARENT), $(subst .$(EXT),, $(shell find "$(path)/tests/" -name "*.$(EXT)")))

ifndef CXX
CXX=g++
Expand Down Expand Up @@ -217,9 +219,12 @@ ifndef N2D2_BINDIR
endif

OBJDIR=$(N2D2_BINDIR).obj
SRC=$(foreach path, $(PARENT), $(shell find $(path)/src/ -name "*.$(EXT)"))
SRC_CUDA=$(foreach path, $(PARENT), $(shell find $(path)/src/ -name "*.$(EXT_CUDA)"))
INCLUDES=$(foreach path, $(PARENT), $(shell find $(path)/include/ -name "*.hpp"))
SRC=$(foreach path, $(PARENT), $(shell find "$(path)/src/" -name "*.$(EXT)"))
SRC_CUDA=$(foreach path, $(PARENT), $(shell find "$(path)/src/" -name "*.$(EXT_CUDA)"))
INCLUDES=$(foreach path, $(PARENT), $(shell find "$(path)/include/" -name "*.hpp"))

PCH_SRC=$(MAKEFILE_DIR)/include/Precompiled.hpp
PCH_OUT=$(PCH_SRC).gch

OBJ:=$(SRC:%.$(EXT)=$(OBJDIR)/%.o)
ifdef CUDA
Expand Down Expand Up @@ -274,18 +279,21 @@ ifneq (,$(filter $(MAKECMDGOALS),clean clean-all))
-include $(OBJ:%.o=%.d)
endif

$(PCH_OUT): $(PCH_SRC)
$(CXX) $(CPPFLAGS) -o $@ $<

.PRECIOUS : $(OBJDIR)/%.o
$(OBJDIR)/%.o : %.$(EXT) $(INCLUDES)
$(OBJDIR)/%.o : %.$(EXT) $(INCLUDES) $(PCH_OUT)
@mkdir -p $(@D)
$(call make-depend,$<,$@,$(patsubst %.o,%.d,$@))
$(CXX) -o $@ -c $< $(CPPFLAGS)
$(CXX) -o $@ -c $< $(CPPFLAGS) -include $(PCH_SRC)

ifdef CUDA
.PRECIOUS : $(OBJDIR)/%.ocu
$(OBJDIR)/%.ocu : %.$(EXT_CUDA) $(INCLUDES)
$(OBJDIR)/%.ocu : %.$(EXT_CUDA) $(INCLUDES) $(PCH_OUT)
@mkdir -p $(@D)
$(call make-depend,$<,$@,$(patsubst %.o,%.d,$@))
$(NVCC) -o $@ -c $< $(NVFLAGS)
$(NVCC) -o $@ -c $< $(NVFLAGS) -include $(PCH_SRC)
endif

doc : $(SRC) $(SRC_CUDA) $(wildcard include/*.hpp) doxygen.cfg
Expand All @@ -294,7 +302,7 @@ doc : $(SRC) $(SRC_CUDA) $(wildcard include/*.hpp) doxygen.cfg
.PHONY : clean

clean :
@rm -rf $(OBJDIR) $(addprefix $(N2D2_BINDIR)/, $(BIN)) $(addprefix $(N2D2_BINDIR)/, $(BIN_TESTS)) doc/
@rm -rf $(OBJDIR) $(addprefix $(N2D2_BINDIR)/, $(BIN)) $(addprefix $(N2D2_BINDIR)/, $(BIN_TESTS)) doc/ $(PCH_OUT)

.PHONY : clean-all

Expand Down

0 comments on commit 1eb0d47

Please sign in to comment.