CMake FindRTIConnextDDS(): force linking against "Release" version of DDS libraries

4 posts / 0 new
Last post
WernerZeller's picture
Offline
Last seen: 9 months 6 days ago
Joined: 03/02/2022
Posts: 2
CMake FindRTIConnextDDS(): force linking against "Release" version of DDS libraries

I am wondering whether there is an easy way to link always against the release libraries of RTI Connext using the imported targets created by FindRTIConnextDDS() module regardless of the CMAKE_BUILD_TYPE currently used. The only way I could get this to work is to skip the use of imported target (RTIConnextDDS::cpp2_api in my specific case) and use the generated variables like CONNEXTDDS_CPP2_API_LIBRARIES_RELEASE_SHARED directly. However this would throw away the convenience of just linking against RTIConnextDDS::cpp2_api.

In my setup I have some prebuild libraries linked against the release RTI libs and some application I am currently working on which uses my prebuild libs and the DDS libs. Now I ran into the problem when running a debug build of my app, the app links both to the debug DDS libs (directly via CMakeLists.txt of my app project) and the release DDS libs (indirectly by linking against my prebuild libs).

Howard's picture
Offline
Last seen: 10 hours 8 min ago
Joined: 11/29/2012
Posts: 448

Probably the best way is to copy and modify the file FindRTIConnextDDS.cmake found in rti_connext_dds-6.1.0\resource\cmake.

WernerZeller's picture
Offline
Last seen: 9 months 6 days ago
Joined: 03/02/2022
Posts: 2

Hi Howard,

I've found in the meantime a working solution with CMake, there are already some properties for imported targets which control the mapping of libraries to a certain build configuration:

 
 if (NOT RTIConnextDDS_FOUND)
        find_package(RTIConnextDDS "6.1.0" EXACT REQUIRED COMPONENTS core)
        # use always the release configuration of RTI libs regardless of current
        # CMAKE_BUILD_TYPE (root cause of double free error)
        set_target_properties(RTIConnextDDS::core PROPERTIES
            MAP_IMPORTED_CONFIG_RELEASE Release
            MAP_IMPORTED_CONFIG_DEBUG Release
            MAP_IMPORTED_CONFIG_RELWITHDEBUGINFO Release)
        set_target_properties(RTIConnextDDS::c_api PROPERTIES
            MAP_IMPORTED_CONFIG_RELEASE Release
            MAP_IMPORTED_CONFIG_DEBUG Release
            MAP_IMPORTED_CONFIG_RELWITHDEBUGINFO Release)
        set_target_properties(RTIConnextDDS::cpp_api PROPERTIES
            MAP_IMPORTED_CONFIG_RELEASE Release
            MAP_IMPORTED_CONFIG_DEBUG Release
            MAP_IMPORTED_CONFIG_RELWITHDEBUGINFO Release)
        set_target_properties(RTIConnextDDS::cpp2_api PROPERTIES
            MAP_IMPORTED_CONFIG_RELEASE Release
            MAP_IMPORTED_CONFIG_DEBUG Release
            MAP_IMPORTED_CONFIG_RELWITHDEBUGINFO Release)
    endif()
Howard's picture
Offline
Last seen: 10 hours 8 min ago
Joined: 11/29/2012
Posts: 448

Great to hear, thanks for sharing!