Skip to content

Conversation

@Davide-1998
Copy link

@Davide-1998 Davide-1998 commented Oct 1, 2025

Fix #2297
This PR adds the following:

  • Added aliases for targets avoiding multiple definitions with foreign code
  • Added missing semicolons in src/ddsrt/src/dynlib.c when DDSRT_HAVE_DYNLIB is false
  • Improved build system of cdr target
  • Added missing include of filesystem.h header in ddsrt target headers
  • Used DDS_STATIC_DEFINE for src/ddsrt/src/cdtors.c and src/idl/src/string.c to avoid multiple tls_callback_func definitions when building as a statically.
  • Added POSITION_INDEPENDENT_CODE statements

Davide-1998 and others added 5 commits October 1, 2025 00:03
Added aliases for targets avoiding multiple definitions with foreign code.
Minor fixes: missing semicolons and multiple 'tls_callback_func' definitions when building as a static library.

Signed-off-by: Davide Bertelli <[email protected]>
Copy link
Contributor

@eboasson eboasson left a comment

Choose a reason for hiding this comment

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

Thank you very much @Davide-1998 ! I am not much of a CMake user and I have never gotten around to trying to solve some vague reports about difficulties building it as a sub-project. So it is really nice to see a PR for addressing those issues.

It looks good to me, even if I there are some things I am not sure of yet. I'd appreciate it if you could help me with them.

LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib)
endif()
install(
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember adding this install. I didn't really want to install ucunit because I don't think it should be installed alongside Cyclone and would pollute the install dirs. However, I couldn't get the static build to work without it.

Thinking about it now, for the normal (dynamically linked) builds, you probably wouldn't want to install the version generated with -DBUILD_TESTING=1 anyway because it forces exporting all symbols.

So probably it is fine to install it always. (And perhaps it will even come in handy for someone 🙂)

Copy link
Author

Choose a reason for hiding this comment

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

The problem with ucunit comes into being whenever BUILD_TESTING=TRUE.
This causes the dds_security_*_wrapper targets to have ucunit as their direct dependency, thus their install command will require it to be inside an export group.
It would be possible to avoid installing ucunit by forcibly require it to be a STATIC library. In this way the security wrappers will use its code without needing it to be installed and exported.
By the way, if we build it statically we would also need to enable the POSITION_INDEPENDENT_CODE for it, otherwise another relocation issue is flagged.

set_target_properties(ddsc PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
POSITION_INDEPENDENT_CODE ON
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this force position independent code always? I remember trying to set it to ON and running into a problem. I think it was the one mentioned here:

# By default we do shared libraries (we really prefer shared libraries because of the

Copy link
Author

Choose a reason for hiding this comment

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

This property will set position indipendent code only for the DDSC target (and, in a future commit, also for CDR). I had to enable it due to relocation issues happening when building CycloneDDS as a static library on linux.
Specifically the errors were:

  • relocation R_X86_64_TPOFF32 for symbol tsd_thread_state from ddsi_thread.c. Fixed by adding POSITION_INDEPENDENT_CODE property on DDSC target
  • relocation R_X86_64_PC32 for symbol ddsrt_hh_empty from dds_cdrstream.c. Fixed by adding POSITION_INDEPENDENT_CODE property on CDR target

Seeing the shared nature of the project and the many relocation issues, I suggest to directly set CMAKE_POSITION_INDEPENDENT_CODE=ON whenever the library is built with BUILD_SHARED_LIBS=ON.
Further tests with this setting on Windows Environment are required though.

target_link_libraries(idl
PUBLIC
${PROJECT_NAME}::ddsc
$<$<NOT:$<STREQUAL:"${CMAKE_PROJECT_NAME}","CycloneDDS">>:${PROJECT_NAME}::cdr>
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean that when building Cyclone as a subproject, the CDR library would be split off into a separate shared library and that each application using Cyclone from that build is linking against it directly?

I don't mind if that's the case, but I do want to make sure I understand.

Copy link
Author

Choose a reason for hiding this comment

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

Yes indeed, when CycloneDDS will be built as a subproject, CDR will become a shared library, or static depending by the value of BUILD_SHARED_LIBS, and each application linking to CycloneDDS::ddsc will also indirectly link to CDR being one of its dependencies

Davide-1998 and others added 3 commits October 24, 2025 13:05
…g ddsrt_init when building statically

Not calling ddsrt_init triggers a debug assertion failure on TLS
…cifiers to allow cmake to chose the best one
@eboasson
Copy link
Contributor

Hi @Davide-1998 I really would like everyone to benefit from the cleaner CMake usage you propose. I am more or less waiting until I no longer see commits getting added 😱 I thought that might be the case, but it seems the CI is quite unhappy now.

When the CI's green and you let me know it is as good as it needs to be for now, then I'll do a final review and (hopefully) merge it. Do you think that's a reasonable plan?

@Davide-1998
Copy link
Author

Good afternoon.
I strongly agree with your statement.
Given the recent failures I started to rearrange my work and deeply test it.
As soon as a stable release will be available I will provide a cleaner pull request.
I was also thinking to deeply refactor the build system, but for the moment I will keep my changes as close as possible to the current one.

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.

feat: Support for building as a vendored library

2 participants