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

Fix and simplify cmake package config #596

Merged
merged 10 commits into from
Sep 3, 2024

Conversation

bjsowa
Copy link
Contributor

@bjsowa bjsowa commented Aug 15, 2024

The current package config template seems to be copied from zenoh-c and does not really work as the CMakeLists does not create STATICLIB or DYLIB variables.

The solution I propose is much simpler. It just exports the zenohpico target which contains the public include directories and compile definitions, instead of creating an imported library target.

Dependent projects can just find_package this project and link zenohpico::zenohpico target to their executable.

CMakeLists.txt Outdated
if(BUILD_SHARED_LIBS)
add_library(${Libname} SHARED)
else()
add_library(${Libname} STATIC)
endif()
add_library(${Libname})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was just redundant as add_library already does this:

If no is given the default is STATIC or SHARED based on the value of the BUILD_SHARED_LIBS variable.

Comment on lines +236 to +239
target_include_directories(${Libname}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The included directory is different for installed target

@@ -4,7 +4,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
project(zenohpico_examples LANGUAGES C)
include(../cmake/helpers.cmake)
set_default_build_type(Release)
configure_include_project(ZENOHPICO zenohpico zenohpico::static ".." zenohpico "https://github.com/eclipse-zenoh/zenoh-pico" "")
configure_include_project(ZENOHPICO zenohpico zenohpico ".." zenohpico "https://github.com/eclipse-zenoh/zenoh-pico" "")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This actually fixes the build if building the examples as the root project. When including the project using add_subdirectory or FetchContent the library target will be named zenohpico.
The only small problem is that the target name for a find_packaged library will be zenohpico::zenohpico and this macro does not take the target namespace into account.

@jean-roland
Copy link
Contributor

Hello @bjsowa and thanks for your contribution, we'll look into it after the end of our release cycle so probably next week.

Copy link

PR missing one of the required labels: breaking-change bug dependencies documentation enhancement new feature internal

@DenisBiryukov91 DenisBiryukov91 added enhancement Things could work better release Part of the next release labels Sep 2, 2024
@DenisBiryukov91
Copy link
Contributor

DenisBiryukov91 commented Sep 2, 2024

@bjsowa We still want to expose variables corresponding to enabled/disabled features of pico (this is needed mostly for cpp to decide which tests/examples to build) and the alias zenohpico::lib. I made corresponding pr to your branch.

Copy link
Contributor

@DenisBiryukov91 DenisBiryukov91 left a comment

Choose a reason for hiding this comment

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

Consider including changes from bjsowa#1

@bjsowa bjsowa marked this pull request as draft September 2, 2024 14:50
@@ -4,7 +4,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
project(zenohpico_examples LANGUAGES C)
include(../cmake/helpers.cmake)
set_default_build_type(Release)
configure_include_project(ZENOHPICO zenohpico zenohpico::static ".." zenohpico "https://github.com/eclipse-zenoh/zenoh-pico" "")
configure_include_project(ZENOHPICO zenohpico zenohpico::lib ".." zenohpico "https://github.com/eclipse-zenoh/zenoh-pico" "")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should now work regardless of whether zenohpico is included using find_package or add_subdirectory as both define zenohpico::lib target

add_library(${Libname} STATIC)
endif()
add_library(${Libname})
add_library(zenohpico::lib ALIAS ${Libname})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DenisBiryukov91 I assume there was no reason to put the alias definition inside add_definition function. Let me know if I'm wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, sorry, this was a typo.

@bjsowa bjsowa marked this pull request as ready for review September 2, 2024 15:16
@yellowhatter yellowhatter merged commit cb873fa into eclipse-zenoh:main Sep 3, 2024
53 checks passed
@bjsowa bjsowa deleted the fix-cmake-package-config branch September 3, 2024 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Things could work better release Part of the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants