Skip to content

Commit 2f8d95a

Browse files
Joachim Schielekris-jusiak
authored andcommitted
Added gunit INTERFACE target, integrated gherkin-cpp via CMake instead of Makefile (make)
1 parent ba1e94e commit 2f8d95a

File tree

3 files changed

+41
-36
lines changed

3 files changed

+41
-36
lines changed

CMakeLists.txt

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,45 +31,41 @@ enable_testing()
3131

3232
add_subdirectory(libs/googletest)
3333

34-
include_directories(include)
35-
include_directories(SYSTEM
36-
${gtest_SOURCE_DIR}/include
34+
add_library(gunit INTERFACE)
35+
target_include_directories(gunit INTERFACE include)
36+
target_include_directories(gunit
37+
INTERFACE ${gtest_SOURCE_DIR}/include
3738
${gmock_SOURCE_DIR}/include
3839
libs/json/single_include/nlohmann
39-
libs/gherkin-cpp/include
4040
)
4141

42-
link_directories(${CMAKE_CURRENT_LIST_DIR}/libs/gherkin-cpp)
42+
target_link_libraries(gunit
43+
INTERFACE gtest_main
44+
INTERFACE gmock_main
45+
INTERFACE gherkin-cpp
46+
)
4347

4448
set(BUILD_GMOCK)
4549
set(BUILD_GTEST)
4650

47-
add_custom_command(
48-
OUTPUT libgherkin-cpp-static
49-
COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/libs/gherkin-cpp && make lib-static
50-
)
51-
add_custom_target(
52-
gherkin_cpp-static ALL DEPENDS libgherkin-cpp-static
53-
)
51+
add_subdirectory(libs/gherkin-cpp)
5452

5553
find_program(MEMORYCHECK_COMMAND valgrind)
5654
if (ENABLE_MEMCHECK AND MEMORYCHECK_COMMAND)
5755
function(test name scenario)
5856
string(REPLACE "/" "_" out ${name})
5957
add_executable(${out} ${CMAKE_CURRENT_LIST_DIR}/${name}.cpp)
6058
add_test(${out} ${MEMORYCHECK_COMMAND} --leak-check=full --error-exitcode=1 ./${out})
61-
add_dependencies(${out} gherkin_cpp-static)
62-
target_link_libraries(${out} gtest_main gmock_main gherkin-cpp)
63-
add_custom_command(TARGET ${out} COMMAND ${scenario} ./${out})
59+
target_link_libraries(${out} gunit)
60+
add_custom_command(TARGET ${out} COMMAND ${scenario} ./${out} --gtest_color=yes USES_TERMINAL)
6461
endfunction()
6562
else()
6663
function(test name scenario)
6764
string(REPLACE "/" "_" out ${name})
6865
add_executable(${out} ${CMAKE_CURRENT_LIST_DIR}/${name}.cpp)
6966
add_test(${out} ./${out})
70-
add_dependencies(${out} gherkin_cpp-static)
71-
target_link_libraries(${out} gtest_main gmock_main gherkin-cpp)
72-
add_custom_command(TARGET ${out} COMMAND ${scenario} ./${out})
67+
target_link_libraries(${out} gunit)
68+
add_custom_command(TARGET ${out} COMMAND ${scenario} ./${out} --gtest_color=yes USES_TERMINAL)
7369
endfunction()
7470
endif()
7571

README.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,30 @@
223223
224224
---
225225
226-
* [**Optional**] For [gherkin](https://github.com/cucumber/cucumber/wiki/Gherkin) support
227-
* Compile `gherkin-cpp`
228-
```sh
229-
$cd libs/gherkin-cpp && make lib
230-
$ls libs/gherkin-cpp
231-
libgherkin-cpp.a
232-
libgherkin-cpp.so
233-
```
234-
* Add include paths
235-
* `-I GUnit/gherkin-cpp/include`
236-
* `-I GUnit/json/src`
237-
* Link with `libgherkin-cpp.{a, so}`
238-
* `-L libgherkin-cpp`
239-
* Write some feature tests...
240-
* Compile and Run!
241-
226+
* [gherkin](https://github.com/cucumber/cucumber/wiki/Gherkin) support using CMake
227+
* `gherkin-cpp` using add_subdirectory
228+
```sh
229+
# using add_subdirectory from the top-level CMakeLists.txt file:
230+
add_subdirectory(gunit)
231+
```
232+
```sh
233+
# src/CMakeLists.txt contains either this:
234+
add_executable(myprogram)
235+
target_link_libraries(myprogram gunit)
236+
...
237+
# or you could have also been more explicit, then you would write this:
238+
target_link_libraries(myprogram gtest gtest_main)
239+
```
240+
* `gherkin-cpp` using a ExternalProject_Add(gunit ...)
241+
Note: This sections needs updates, when writing the gherkin-cpp CMake integration I used add_subdirectory:
242+
* Add include paths
243+
* `-I GUnit_install_dir/include`
244+
* Link with `libgherkin-cpp.{a, so}` Note: I wasn't able to nest the fmem/gherkin into libghekin-cpp, so two more libs to add: fmem/gherkin!
245+
* `-L gherkin-cpp`
246+
* `-L fmem`
247+
* `-L gherkin`
248+
* Write some feature tests...
249+
* Compile and Run!
242250
---
243251
244252
* To run GUnit tests/benchmarks
@@ -254,7 +262,8 @@
254262
* `GSteps`
255263
* [libs/json](https://github.com/nlohmann/json)
256264
* [libs/gherkin-cpp](https://github.com/c-libs/gherkin-cpp)
257-
265+
* [libs/gherkin-cpp/libs/fmem](https://github.com/c-libs/fmem.git)
266+
* [libs/gherkin-cpp/libs/gherkin-c](https://github.com/c-libs/gherkin-c.git)
258267
### Tested compilers
259268
* [Linux - GCC-5+](https://travis-ci.org/cpp-testing/GUnit)
260269
* [Linux - Clang-3.7+](https://travis-ci.org/cpp-testing/GUnit)

libs/gherkin-cpp

0 commit comments

Comments
 (0)