Skip to content

[22340] Error evaluating generator expression #5283

@burak-yildizoz

Description

@burak-yildizoz

Is there an already existing issue for this?

  • I have searched the existing issues

Expected behavior

CMake generate step should not fail.

Current behavior

CMake fails with the following error message.

CMake Error at CMakeLists.txt (target_link_libraries):
  Error evaluating generator expression:

    $<TARGET_PROPERTY:fastrtps,TYPE>

  Target "fastrtps" not found.


CMake Error at CMakeLists.txt (target_link_libraries):
  Error evaluating generator expression:

    $<TARGET_PROPERTY:fastcdr,TYPE>

  Target "fastcdr" not found.

Steps to reproduce

subdirectory/CMakeLists.txt:

find_package(fastcdr REQUIRED)
find_package(fastrtps REQUIRED)

add_library(my_lib STATIC "source.cpp")
target_link_libraries(my_lib PUBLIC fastcdr fastrtps)

CMakeLists.txt:

add_subdirectory(subdirectory)

add_executable(my_exe "main.cpp")
target_link_libraries(my_exe my_lib)

The issue is resolved if the following lines are added to CMakeLists.txt.

find_package(fastcdr QUIET)
find_package(fastrtps QUIET)

Fast DDS version/commit

2.14.2

Platform/Architecture

Windows 10 Visual Studio 2019

Transport layer

Default configuration, UDPv4 & SHM

Additional context

The problem is most likely caused by the following line at src/cpp/CMakeLists.txt files.

target_compile_definitions(${PROJECT_NAME}
    PRIVATE
    ${PROJECT_NAME_UPPER}_SOURCE
    INTERFACE
    $<$<BOOL:${WIN32}>:${PROJECT_NAME_UPPER}_NO_LIB>
    PUBLIC
    $<$<STREQUAL:$<TARGET_PROPERTY:${PROJECT_NAME},TYPE>,SHARED_LIBRARY>:${PROJECT_NAME_UPPER}_DYN_LINK>
    )

The generated line in fastcdr-static-targets.cmake is as follows.

set_target_properties(fastcdr PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "\$<\$<BOOL:1>FASTCDR_NO_LIB>;\$<\$<STREQUAL:\$<TARGET_PROPERTY:fastcdr,TYPE>,SHARED_LIBRARY>:FASTCDR_DYN_LINK>"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
)

Consequently, the problem described in CMake: set_target_properties fails with target defined by generator expression occurs.

XML configuration file

No response

Relevant log output

No response

Network traffic capture

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue to report a bugin progressIssue or PR which is being reviewed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions