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

Make library target visible to downstream clients #64

Closed
wants to merge 2 commits into from

Conversation

yaneury
Copy link

@yaneury yaneury commented Mar 1, 2024

Using the library with FetchContent successfully downloaded the library onto the build/_deps directory but all the #include statements yielded a compiler error because CMake wasn't including atomic_queue directory for the target. You can test this on this repo likeso:

FetchContent_Declare(
        atomic_queue
        GIT_REPOSITORY https://github.com/max0x7ba/atomic_queue.git
        GIT_TAG v1.6.1)
FetchContent_MakeAvailable(atomic_queue)

target_link_libraries(${PROJECT_NAME} PRIVATE atomic_queue)

And link to an executable that includes the library. It should fail to compile.

If you instead link against my fork's version, it will work:

FetchContent_Declare(
        atomic_queue
        GIT_REPOSITORY https://github.com/yaneury/atomic_queue.git
        GIT_TAG stable)
FetchContent_MakeAvailable(atomic_queue)

This will allow outside packages, e.g. through FetchContent, to
consume the library and find the header files using `#include`.
@max0x7ba
Copy link
Owner

max0x7ba commented Mar 2, 2024

Thank you for your contribution.

CMake support is a contribution of @RedSkittleFox. I'd like him to to review the change and let us know whether it should be merged as is or if any adjustments are needed.

@RedSkittleFox
Copy link
Contributor

RedSkittleFox commented Mar 3, 2024

Hey @yaneury
The reason why your first code snippet fails is because the release v1.6.1 is outdated in regards to the master branch. It's using the commit 083f3e5 (Merge branch 'RedSkittleFox-allocator-aware-constructors') instead of the later commit which introduced CMake support (CMake Support added).

If you do:

FetchContent_Declare(
        atomic_queue
        GIT_REPOSITORY https://github.com/max0x7ba/atomic_queue.git
        GIT_TAG 10ae35d40449b07607238c3809d360765a8cff91 # Latest commit tag
)
FetchContent_MakeAvailable(atomic_queue)
target_link_libraries(${PROJECT_NAME} PRIVATE max0x7ba::atomic_queue) # use aliased target

then it should work just fine.

@@ -26,5 +26,3 @@ endif()
if ( ATOMIC_QUEUE_BUILD_TESTS OR ATOMIC_QUEUE_BUILD_EXAMPLES)
add_subdirectory( src )
endif()

add_library(max0x7ba::atomic_queue ALIAS atomic_queue)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the name was clobbering with the library target defined inside include/CMakeLists.txt. But I wasn't sure...

@@ -11,7 +13,8 @@ add_library(
)

target_include_directories(
atomic_queue
${PROJECT_NAME}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An explicit target name should be used here (as it was being used before), we should not assume that ${PROJECT_NAME} is the same as the target name passed to add_library.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but we don't have install(...) set up for this project. If we want to do this then we need to provide the installation config as well.

@max0x7ba
Copy link
Owner

max0x7ba commented Mar 3, 2024

The tag has been created now.

Should anything from this change be merged?

@RedSkittleFox
Copy link
Contributor

The tag has been created now.

Should anything from this change be merged?

This PR can be closed without merging.

@max0x7ba
Copy link
Owner

max0x7ba commented Mar 4, 2024

@yaneury Would you like to close this PR if your issue is resolved, please?

@yaneury
Copy link
Author

yaneury commented Mar 4, 2024

Just tested the updated tag and it works now. Thanks for your help!

@yaneury yaneury closed this Mar 4, 2024
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.

3 participants