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

Propagate include directory when consuming this library from CMake #66

Closed

Conversation

KKoovalsky
Copy link

This allows to properly consume the library when it is used via add_subdirectory or FetchConten module.

Consider CMake code:

FetchContent_Declare(printf_library
    GIT_REPOSITORY /~https://github.com/eyalroz/printf.git
    GIT_TAG v5.0.0
)
FetchContent_MakeAvailable(printf_library)

Then consume the printf library created within "eyalroz/printf" project:

add_executable(main main.cpp)
target_link_libraries(main PRIVATE printf)

Inside 'main.cpp':

#include "printf.h" // ERROR: No such file or directory OR
                    // includes "/usr/include/printf.h' which comes
                    // installed with GNU C library

#include "printf/printf.h" // ERROR: No such file or directory

After this commit is applied, one can consume the library from C/C++ code with:

#include "printf/printf.h"

eyalroz and others added 3 commits November 22, 2021 15:19
…intf/printf.h`, to allow inclusing using `<printf/printf.h>`, thus avoiding conflicts with glibc's `printf.h`.
This allows to properly consume the library when it is used via
"add_subdirectory" or "FetchContent" module.

Consider CMake code:

    FetchContent_Declare(printf_library
        GIT_REPOSITORY /~https://github.com/eyalroz/printf.git
        GIT_TAG v5.0.0
    )
    FetchContent_MakeAvailable(printf_library)

Then consume the 'printf' library created within "eyalroz/printf"
project:

    add_executable(main main.cpp)
    target_link_libraries(main PRIVATE printf)

Inside 'main.cpp':

    #include "printf.h" // ERROR: No such file or directory OR
                        // includes "/usr/include/printf.h' which comes
                        // installed with GNU C library

    #include "printf/printf.h" // ERROR: No such file or directory

After this commit is applied one can consume the library from C/C++ code
with:

    #include "printf/printf.h"
@eyalroz
Copy link
Owner

eyalroz commented Nov 30, 2021

So, most of what you suggest here seems to already have been done in #58 . There seems to be one relevant commit. ... but that commit has a super-long commit message, which belongs here in the discussion or is just the text you added on the issue you filed. Let me see..

@eyalroz
Copy link
Owner

eyalroz commented Nov 30, 2021

I think I've effectively merged your PR, even though GitHub doesn't recognize that fact... can you check and make sure the HEAD of the develop branch works as you would expect?

@KKoovalsky KKoovalsky closed this Dec 1, 2021
@KKoovalsky
Copy link
Author

I guess that you have rewritten the history, because the develop branch is missing two commits since yesterday. This PR included only this commit: bbc87a4995acb6523e36f618f96cdaf2d326018b
. The two missing commits must have been removed and I guess that git push -f ... has been used.

@eyalroz
Copy link
Owner

eyalroz commented Dec 1, 2021

@KKoovalsky : Yes, my personal custom is that the master branch is "pristine" with no history rewrites, but on the develop branch I often change things retroactively.

Anyway, I'm glad that, eventually, the necessary change strictly for supporting add_subdirectory was pretty small (or arguably, nothing was strictly justified by this kind of use and everything sort of makes sense even for the regular use of the repository). Thanks again and now onto the aliasing business.

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