Skip to content

Add support for CMake find_package() #106

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

Merged
merged 1 commit into from
Apr 20, 2016
Merged

Add support for CMake find_package() #106

merged 1 commit into from
Apr 20, 2016

Conversation

jasonhorsburgh
Copy link
Contributor

I had a need for this and noticed that it's also a current issue (#99).

The end result is you can import UnitTest++ in your CMakeLists.txt via:

find_package(UnitTest++ REQUIRED NO_MODULE) # probably don't need NO_MODULE
add_executable(foo ...)
include_directories(${UTPP_INCLUDE_DIRS})
target_link_libraries(foo UnitTest++)

More can be done with this including adding proper version checking support but i'm not sure how to go about that with a minimum CMake version of 2.8.1 since I don't have much experience with it. There's an easier method with more recent versions of CMake using CMakePackageConfigHelpers module and setting the version in the project() call.
A more recent version of CMake would also allow setting the install include directory as part of the imported target meaning you can drop include_directories(${UTPP_INCLUDE_DIRS}) calls when linking the target.

Worth noting that the config file doesn't deal with changing '++' to 'pp' but it looks like the CMakeLists.txt has sort of broken that functionality since it was originally put in and i'm not sure if I should approach that issue here.

Added export configuration for UnitTest++ target and installed the export and config file in libs/cmake/UnitTest++.
Added basic UnitTest++Config.cmake file which includes exported targets file and sets UTPP_INCLUDE_DIRS to the install location of the includes directory, this allows UnitTest++ to be used as a normal target in your own CMakeLists.txt file.

e.g.:

    find_package(UnitTest++ REQUIRED NO_MODULE)
    add_executable(foo ...)
    include_directories(${UTPP_INCLUDE_DIRS})
    target_link_libraries(foo UnitTest++)

which will ensure the library and installed headers paths are set up correctly for your own target.
@pjohnmeyer
Copy link
Member

Looks good, thanks for the PR. I'm on vacation but I'll give it a go when I get home, unless somebody else wants to vouch for it.

@pjohnmeyer pjohnmeyer merged commit e88121f into unittest-cpp:master Apr 20, 2016
pjohnmeyer added a commit that referenced this pull request Apr 20, 2016
Add support for CMake find_package()

Fixes #99
@pjohnmeyer pjohnmeyer added this to the 1.6.1 milestone Apr 20, 2016
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

Successfully merging this pull request may close these issues.

2 participants