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

Provide example CMake configuration for single header bundled with project #882

Closed
johnthagen opened this issue Apr 4, 2017 · 3 comments

Comments

@johnthagen
Copy link

The current CMake Catch documentation provides an example on how to fetch and download Catch. I was wondering if it could be expanded to include a simple example of how to integrate a bundled single-header version of Catch into a CMake project. This appears to be the recommended way to use Catch often.

Having reviewed a stackoverflow answer about this, I am still struggling with what the best way to expose this all to CMake and lay out my test/ directory, and I think it could be a nice addition to the documentation.

@horenmar
Copy link
Member

horenmar commented Apr 4, 2017

What exactly is the problem?

If you are saving the single-include header inside your repository, you can just use it the way you would use any other header file, or you can do it like in the linked answer...

Just make the CATCH_INCLUDE_DIR point to wherever you have the catch.hpp

cmake_minimum_required(VERSION 3.0)

project(cmake_test)

# Prepare "Catch" library for other executables
set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/catch)
add_library(Catch INTERFACE)
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})

# Make test executable
set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
add_executable(tests ${TEST_SOURCES})
target_link_libraries(tests Catch)

@horenmar horenmar added the Query label Apr 4, 2017
@johnthagen
Copy link
Author

I guess it just wasn't immediately clear to me as someone new to Catch (and albeit not a seasoned CMake user) how to do this. I had a working CMake build, but wanted to drop in Catch into a separate build for the unit tests.

But I was able to finally get it working using the stack overflow example. Just thought it might be something that could be laid out explicitly in Catch's docs for others who found it was not trivially straight forward. But I admit, my lack of thorough understanding of CMake was probably most to blame.

Feel free to close to the issue, appreciate the help.

@horenmar
Copy link
Member

horenmar commented Apr 9, 2017

@johnthagen I will see about improving the documentation a bit. Obviously we don't want to substitute for CMake documentation, but maybe it would be valuable.

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

No branches or pull requests

2 participants