We have a solution with projects that is generate by cmake.
There is src
folder that has all the source code. Proj_Service1
, Proj_Service2
and Proj_Service3
reference same Main.cpp
and Base_Service.cpp
files. In addition, each project has reference to its own ServiceX.cpp
file. All projects are console projects (exe). See solution structure below:
-Solution
----Proj_Service1
-------Main.cpp
-------Base_Service.cpp
-------Service1.cpp
----Proj_Service2
-------Main.cpp
-------Base_Service.cpp
-------Service2.cpp
----Proj_Service3
-------Main.cpp
-------Base_Service.cpp
-------Service3.cpp
The reason the structure above in that way is becuase it was decided in the company that each project should include only files that relevant to the project.
I want to add Test_Proj
project that will test one of the services or/and all of them using googletest.
When I try to instantiate ServiceX.cpp
in Test_Proj
, I obviously get linker errors since Proj_ServiceX
is not lib
and therefore I cannot link to it.
What I thought to do is to create an additional project of type "lib", move Service1.cpp
, Service2.cpp
and Service3.cpp
files to it and make all projects reference it. Basically:
-Solution
----Service_Proj
-------Base_Service.cpp
-------Service1.cpp
-------Service2.cpp
-------Service3.cpp
----Proj_Service1
-------[Reference to Service_Proj]
----Proj_Service2
-------[Reference to Service_Proj]
----Proj_Service3
-------[Reference to Service_Proj]
----Test_Proj
-------[Reference to Service_Proj]
Questions:
- Is the solution I suggested above is the only way?
- If there is a different, better approach, even the one that requires using other tools, I'll be glad to hear.