Compilation of C++ sources with .cc file extension

60 views
Skip to first unread message

ferdi....@gmail.com

unread,
May 14, 2013, 3:33:18 AM5/14/13
to cppu...@googlegroups.com
Some of the C++ files in my module-under-test use a .cc file extension. This is apparently not recognized by /build/MakefileWorker.mk (in CppUTest version 3.3) as a C++ source file.

I tried the following modification to the function __src_to in MakefileWorker.mk. My intention was that files with .cc extension should also be compiled as C++ source files:
diff -r 08d7291886ae -r 1fa55f1a1621 build/MakefileWorker.mk
--- a/build/MakefileWorker.mk   Mon Apr 22 13:04:28 2013 +0800
+++ b/build/MakefileWorker.mk   Mon Apr 22 13:09:09 2013 +0800
@@ -310,7 +310,7 @@
 get_src_from_dir  = $(wildcard $1/*.cpp) $(wildcard $1/*.c)
 get_dirs_from_dirspec  = $(wildcard $1)
 get_src_from_dir_list = $(foreach dir, $1, $(call get_src_from_dir,$(dir)))
-__src_to = $(subst .c,$1, $(subst .cpp,$1,$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2)))
+__src_to = $(subst .c,$1, $(subst .cpp,$1, $(subst .cc,$1, $(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2))))
 src_to = $(addprefix $(CPPUTEST_OBJS_DIR)/,$(call __src_to,$1,$2))
 src_to_o = $(call src_to,.o,$1)
 src_to_d = $(call src_to,.d,$1)

I doubt I'm the first CppUTest user to deal with this issue... Any advice?

ferdi....@gmail.com

unread,
May 16, 2013, 2:36:52 AM5/16/13
to cppu...@googlegroups.com
I have a working solution, involving 3 additions to MakefileWorker.mk:
diff
310c310

< get_src_from_dir  = $(wildcard $1/*.cpp) $(wildcard $1/*.c)
---
> get_src_from_dir  = $(wildcard $1/*.cpp) $(wildcard $1/*.c) $(wildcard $1/*.cc)
313c313

< __src_to = $(subst .c,$1, $(subst .cpp,$1,$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2)))
---

> __src_to = $(subst .c,$1, $(subst .cpp,$1, $(subst .cc,$1, $(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2))))
456a457,461
> $(CPPUTEST_OBJS_DIR)/%.o: %.cc
>       @echo compiling $(notdir $<)
>       $(SILENCE)mkdir -p $(dir $@)
>       $(SILENCE)$(COMPILE.cc) $(DEP_FLAGS) $(OUTPUT_OPTION) $<

Not too elegant, since the last addition is a essentially a copy of an existing rule, but it works.

Bas Vodde

unread,
May 19, 2013, 10:27:35 PM5/19/13
to cppu...@googlegroups.com

Hi Ferdi,

Indeed not too elegant, but I guess it will work. There are a limited amount of C++ file extensions in use and I guess the mainstream is either cpp or cc :)

Could you make a git pull request for this? Then I'll merge it in the MakefileWorker.mk (as long as we still have that).

Thanks!

Bas
> --
> You received this message because you are subscribed to the Google Groups "cpputest" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

ferdi....@gmail.com

unread,
May 20, 2013, 3:05:06 AM5/20/13
to cppu...@googlegroups.com
Hi Bas

I'm not using git (we use Mercurial) -- I downloaded CppUTest as a zipfile. I guess that if I want to make a contribution, my first step is to install git, and then clone the repository?

I gather from comments I've read here that MakefileWorker.mk is becoming obsolete. Something tells me I'm in the minority, but I like what it does for me: it automagically takes care of generating dependencies for my code-under-test and test-doubles, and putting the object files in a separate directory tree. These are things I'm not expert in, and the fact that CppUTest has a makefile that does this for me is not something I'd like to give up!

Ferdi
Reply all
Reply to author
Forward
0 new messages