cucumber / cucumber-cpp

Support for writing Cucumber step definitions in C++
MIT License
306 stars 131 forks source link

Unable to add_subdirectory (cucumber-cpp) because include directory is not setup properly #210

Closed ghost closed 5 years ago

ghost commented 5 years ago

Steps to Reproduce

Clone into sub-directory import and use add_subdirectory (import/cucumber-cpp). Build fails:

...

Scanning dependencies of target cucumber-cpp-nomain
[ 14%] Building CXX object import/cucumber-cpp/src/CMakeFiles/cucumber-cpp-nomain.dir/drivers/GenericDriver.cpp.o
/home/sbon/Code/project/import/cucumber-cpp/src/drivers/GenericDriver.cpp:1:10: fatal error: 'cucumber-cpp/internal/drivers/GenericDriver.hpp' file not found
#include "cucumber-cpp/internal/drivers/GenericDriver.hpp"
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [import/cucumber-cpp/src/CMakeFiles/cucumber-cpp-nomain.dir/build.make:67: import/cucumber-cpp/src/CMakeFiles/cucumber-cpp-nomain.dir/drivers/GenericDriver.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1294: import/cucumber-cpp/src/CMakeFiles/cucumber-cpp-nomain.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

Cucumber C++ Include directory resolved as project/include But it should be project/import/cucumber-cpp/include

Possible Solution

Change this:

https://github.com/cucumber/cucumber-cpp/blob/f79990879a3c2eea288de6efeefc4008937300cc/src/CMakeLists.txt#L75

to this:

        $<BUILD_INTERFACE:${CUKE_INCLUDE_DIR}>

Use case

CMakeLists.txt

FetchContent_Declare (cucumber_cpp
    GIT_REPOSITORY https://github.com/cucumber/cucumber-cpp.git
    GIT_TAG        v0.5
)

FetchContent_GetProperties (cucumber_cpp)
if (NOT cucumber_cpp_POPULATED)

    FetchContent_Populate (cucumber_cpp)

    set (CUKE_DISABLE_GTEST         ON CACHE BOOL "Don't build Google Test")
    set (CUKE_DISABLE_QT            ON CACHE BOOL "Don't build Qt")
    set (CUDE_DISABLE_UNIT_TESTS    ON CACHE BOOL "Don't build unit tests")
    set (CUKE_DISABLE_E2E_TESTS     ON CACHE BOOL "Don't build end-to-end tests")

    add_subdirectory (
        ${cucumber_cpp_SOURCE_DIR}
        ${cucumber_cpp_BINARY_DIR}
    )

endif ()