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

How to use Howard Hinnant's date library with CPM? #148

Closed
fgr opened this issue Sep 1, 2020 · 4 comments
Closed

How to use Howard Hinnant's date library with CPM? #148

fgr opened this issue Sep 1, 2020 · 4 comments

Comments

@fgr
Copy link

fgr commented Sep 1, 2020

I'm trying to use Howard Hinnant's date library with CPM.

This works:

CPMAddPackage(
        NAME HowardHinnant_date
        GITHUB_REPOSITORY HowardHinnant/date
        VERSION 3.0.0
)

But I have to use #include "include/date/date.h" to include the header. I want to get rid of the include part in the #include path (#include "date/date.h").

I tried

if(HowardHinnant_date_ADDED)
    target_include_directories( HowardHinnant_date INTERFACE
            ${HowardHinnant_date_SOURCE_DIR}/include )
endif()

But cmake complains that target HowardHinnant_date is not build in my cmake project. So I changed this into (using the actual target's name (e.g., myproject))

if(HowardHinnant_date_ADDED)
    target_include_directories( myproject INTERFACE
            ${HowardHinnant_date_SOURCE_DIR}/include )
endif()

But still the pre-processor cannot find date/date.h in #include "date/date.h".

@fgr
Copy link
Author

fgr commented Sep 1, 2020

Found a solution. Using target_include_directories was wrong. All I had to do was:

CPMAddPackage(
        NAME HowardHinnant_date
        GITHUB_REPOSITORY HowardHinnant/date
        VERSION 3.0.0
)

...

add_executable(mytarget_executable ...)

target_link_libraries(mytarget_executable date::date)

What I do not understand, though, is why I have to use date::date instead of something like HowardHinnant_date::HowardHinnant_date because the NAME property in CPMAddPackage() is HowardHinnant_date and not date.

@Andres6936
Copy link

It depends a lot on the documentation, in this case, the documentation of library you want to use is little.
But you should always try to check CMakeLists.txt and see which libraries are defined, for this case, look:

https://github.com/HowardHinnant/date/blob/313189b0a8767f9964704cfc87fe5956e12abc24/CMakeLists.txt#L62-L63

The library is being defined with the name date and an alias that is named date::date, so you should use date::date and not HowardHinnant_date::HowardHinnant_date.

@fgr
Copy link
Author

fgr commented Sep 2, 2020

Thanks for the clarification @Andres6936 I obviously have to learn more about CMake.

@fgr fgr closed this as completed Sep 2, 2020
@fgr
Copy link
Author

fgr commented Sep 2, 2020

Added information on how to use the date library with CPM to the wiki.

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

No branches or pull requests

2 participants