My project is organized like this:
- cpp
- main.cpp (calls code from
dataStructures/
andcommon/
) - CMakeLists.txt (topmost CMakeLists file)
- build
- test
- main.cpp
- CMakeLists.txt
- common
- CMakeLists.txt
- include
- src
- googletest
- build
- common
- CMakeLists.txt (should be responsible for building common shared library)
- include
- utils.h
- src
- utils.cpp
- build
- main.cpp (calls code from
build\
directories contain the built target. The actual code can be seen here: https://github.com/brainydexter/PublicCode/tree/master/cpp
I'm able to build shared
libraries for the actual code ( like common
). Now, I'd like to test it using GoogleTest. So, I created a test
directory and put the test code in there (what I have in the repo is just a sample, more like hello world to get the build system up and working. I will be adding more test cases later on).
I need some help in triggering the tests from the topmost CMakeLists.txt. I'm not sure how to do this. In test
, CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.1.2)
add_subdirectory(googletest/googletest)
include_directories(googletest/googletest/include)
add_subdirectory(common)
enable_testing()
add_executable(testCpp main.cpp)
target_link_libraries(testCpp gtest gtest_main )
Do I need to add anything else to enable tests in test/common
?
test/common/CMakeLists.txt
:
file(GLOB SOURCES "src/*.cpp")
add_executable(testCommon ${SOURCES})
target_link_libraries(testCommon cppCommon)
I'm not sure if the target should be executable here or a library that the google test framework can consume ? I'd appreciate any help on this.