Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the starter project work as super build with main project #9

Closed
claremacrae opened this issue Jan 16, 2020 · 1 comment
Closed

Comments

@claremacrae
Copy link
Contributor

Currently, ApprovalTests.cpp.StarterProject always uses its own copy of ApprovalTests.cpp.

I would like to be able to have a super-build project which has these projects loaded:

  • ApprovalTests.cpp
  • ApprovalTests.cpp.StarterProject
  • Catch2
  • and other supported 3rd-party libraries

This mostly works, except that the starter project ignores the headers in ApprovalTests.cpp, and uses its own fixed copy of ApprovalTests.v.x.y.z instead.

@claremacrae
Copy link
Contributor Author

I had a quick go at fixing this, by:

In ApprovalTests.cpp:

  • Copying tests/GoogleTest_Tests/CompileAllIncludes.cpp to ApprovalTests/ApprovalTests.hpp

In ApprovalTests.cpp.StarterProject:

Changing lib/CMakeLists.txt like this:

index 3dc0f3c..ae25c5c 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -1,6 +1,8 @@
-set(LIB_NAME StarterProject.lib)
-add_library(${LIB_NAME} INTERFACE)
-target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
+if(NOT TARGET ApprovalTests)
+    set(LIB_NAME ApprovalTests)
+    add_library(${LIB_NAME} INTERFACE)
+    target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
+    add_library(${LIB_NAME}::${LIB_NAME} ALIAS ${LIB_NAME})
+endif()
 
 add_subdirectory(catch2)
-target_link_libraries(${LIB_NAME} INTERFACE Catch2::Catch2)

Changing tests/CMakeLists.txt like this:

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index f64b987..a5cc597 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -6,5 +6,5 @@ set(SOURCE_FILES
         NewTest.cpp
         Tutorial.cpp)
 add_executable(${TEST_NAME} ${SOURCE_FILES})
-target_link_libraries(${TEST_NAME} StarterProject.code StarterProject.lib)
+target_link_libraries(${TEST_NAME} StarterProject.code ApprovalTests::ApprovalTests Catch2::Catch2)
 add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})

Result

It almost worked, except that I had to change all the source files in the starter project like this:

diff --git a/tests/DemoTest.cpp b/tests/DemoTest.cpp
index dc859a7..0b28094 100644
--- a/tests/DemoTest.cpp
+++ b/tests/DemoTest.cpp
@@ -1,4 +1,4 @@
-#include "ApprovalTests.hpp"
+#include "ApprovalTests/ApprovalTests.hpp"
 #include "catch2/catch.hpp"
 #include <ostream>

So I would need to rework the header include paths in the main project to fix this, which is a larger change than I would like to do right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant