Почему бы не использовать CMake для всего проекта? Предполагая, что ваша файловая структура похожа на ту, что показана в обозревателе решений Visual Studio, она может выглядеть примерно так:
CMakeLists.txt верхнего уровня:
cmake_minimum_required (VERSION 3.16)
# Name your VS solution.
project(MyProject)
enable_testing()
# Add the CMake file in the googletest repo
add_subdirectory(Project-A)
# Add the CMake file that configures your static library.
add_subdirectory(Project-B)
# Add the CMake file that configures your unit tests.
add_subdirectory(Project-C)
Файл CMakeLists.txt в Папка Project-B
:
# Add the VS project for the static library.
project(MyLibProj)
add_library(MyLib STATIC)
# Add the public/private sources for the static library.
target_sources(MyLib
PUBLIC
Folder-1/MyClass1.cpp
Folder-1/MyClass2.cpp
...
Folder-2/SubFolder1/UtilityClass1.cpp
Folder-2/SubFolder1/UtilityClass2.cpp
...
Folder-2/SubFolder2/HelperClass1.cpp
...
Folder-3/Circle.cpp
Folder-3/Square.cpp
PRIVATE
src/ImplClass1.cpp
src/ImplClass2.cpp
...
)
# Add the include directories for the library.
target_include_directories(MyLib
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/Folder-1
${CMAKE_CURRENT_LIST_DIR}/Folder-2/SubFolder1
${CMAKE_CURRENT_LIST_DIR}/Folder-2/SubFolder2
${CMAKE_CURRENT_LIST_DIR}/Folder-3
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/include
)
Файл CMakeLists.txt в папке Project-C
:
# Add the VS project for the executable.
project(MyExeProj)
# Create the test executable, and link the static library to it.
add_executable(MyTestExe main.cpp)
target_link_libraries(MyTestExe PRIVATE MyLib)
add_test(NAME MyTest COMMAND MyTestExe)