Reputation: 597
I use Google Test in my C++ project. I build the target either for my i386 virtual machine or for the real ARMEL target. What I would like to do is have my Makefile link in the correct google test .a file for the right architecture, depending on the host system. E.g. if I am running the test target from my i386 VM, I'd like to link in the i386 built libgtest.a, and ditto when building on my ARMEL system. How do I do that? I do not cross compile the ARM build, I build it on the ARM target hardware itself. I don't really want to build libtest.a from scratch as it's pretty slow to build.
My Makefile is:
CC = g++-4.7 CXX := $(CC) SVNDEV := -D'SVN_REV="$(shell svnversion -n .)"' CFLAGS += -Os -Wall -Wno-write-strings $(SVNDEV) -Iinclude -I/usr/include/c++/4.7 -Llib CXXFLAGS += --std=c++11 -D_GLIBCXX_USE_NANOSLEEP $(CFLAGS) TARGET = connectionmanager LIBS = -lzmq -ljansson -lpthread objects = systeminterface.o linuxsysteminterface.o connectionmanagerutils.o connectionmanagerexception.o logger.o jsoninterface.o configuration.o diagnosticslogger.o serial.o \ modemstrategy.o lisac200modemstrategy.o maestrom1003gmodemstrategy.o test_objects = mocksysteminterface.o mockmodemstrategy.o test/connectionmanagertest.o test/connectionmanagerutiltest.o test/jsoninterfacetest.o test/gtest_main.o $(TARGET): connectionmanager.o $(objects) $(LIBS) .PHONY: clean all test all: $(TARGET) cmmain.o: connectionmanager.cpp $(CXX) -DUNIT_TESTING $(CPPFLAGS) $(CXXFLAGS) -c connectionmanager.cpp -o cmmain.o connectionmanagertest : cmmain.o $(objects) $(test_objects) lib/libgtest.a $(LIBS) $(CXX) -DUNIT_TESTING $(CPPFLAGS) $(CXXFLAGS) $(LIBS) lib/libgtest.a $^ -o $@ test: connectionmanagertest ./connectionmanagertest clean: rm -f $(TARGET) rm -f $(objects) rm -f $(test_objects) rm -f connectionmanager.o rm -f cmmain.o rm -f $(test_objects)
Upvotes: 1
Views: 2760
Reputation: 439
Please, have a look here. As well your question looks like a duplicate of this. As a suggestion - you might be interested in CMake. Another good point is to parse /proc/cpuinfo for Linux, or use a sysctl call if you are on FreeBSD. Anyway the source of primary system information must be extracted either by existing utility that will return result for later processing in Makefile or using standard system tools. As a source of ideas I would also recommend to download any opensource package and look into the Makefile generators.
Upvotes: 1