How to compile and link a cpp file separately in unity builds?

88 Views Asked by At

I have a file for which I wish to disable unity builds as it causes linker error.

For CMake I achieved the result using this-

set_source_files_properties(foo.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION true)

I wish to achieve the same result using Makefile.am

Currently, part of my Makefile.am looks as follows-

if UNITY_BUILD

nodist_my_project_SOURCES = unity.cpp
UNITY_SRC = $(filter-out foo.cpp,$(TEST_SRCS))

unity.cpp: Makefile.am
    echo "/* This file is automatically generated; do not edit.     */" > $@
    echo "/* Add the files to be included into Makefile.am instead. */" >> $@
    echo >> $@
    for i in $(UNITY_SRC); do \
        echo "#include \"test-suite/$$i\"" >> $@; \
    done

.PHONY: benchmark
benchmark: my_project$(EXEEXT)
    BOOST_TEST_LOG_LEVEL=message ./my_project$(EXEEXT)

However, this causes a linker error as foo.cpp is not linked together.

How can I compile and link the foo.cpp separately?

0

There are 0 best solutions below