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

Ament exports won't work on cmake 3.24+ since they changed export file generator #396

Closed
topin89 opened this issue Aug 8, 2022 · 0 comments · Fixed by #395
Closed

Ament exports won't work on cmake 3.24+ since they changed export file generator #396

topin89 opened this issue Aug 8, 2022 · 0 comments · Fixed by #395

Comments

@topin89
Copy link

topin89 commented Aug 8, 2022

In short, this is how error looks on cmake 3.24:

CMake Error at /home/username/workspace/install/nav_2d_msgs/share/nav_2d_msgs/cmake/ament_cmake_export_targets-extras.cmake:24 (message):
  Failed to find exported target names in                                                                                                                                                                         
  '/home/username/workspace/install/nav_2d_msgs/share/nav_2d_msgs/cmake/nav_2d_msgs__rosidl_generator_cExport.cmake'                                                                                
Call Stack (most recent call first):                                                                                                                                                                              
  /home/username/workspace/install/nav_2d_msgs/share/nav_2d_msgs/cmake/nav_2d_msgsConfig.cmake:42 (include)                                                                                         
  CMakeLists.txt:6 (find_package)     

This is relevant part of ament_cmake_export_targets-extras.cmake:

    set(_regex "foreach\\(_expectedTarget (.+)\\)")
    file(
      STRINGS "${_export_file}" _foreach_targets
      REGEX "${_regex}")

This is how relevant part looks like in cmake 3.23.3 (link):

os << "# Protect against multiple inclusion, which would fail when already "
        "imported targets are added once more.\n"
        "set(_targetsDefined)\n"
        "set(_targetsNotDefined)\n"
        "set(_expectedTargets)\n"
        "foreach(_expectedTarget " << expectedTargets << ")\n"
        "  list(APPEND _expectedTargets ${_expectedTarget})\n"
        /* ... */
        "\n\n";

And this is how relevant part looks like in cmake 3.24 (link):

os << "# Protect against multiple inclusion, which would fail when already "
        "imported targets are added once more.\n"
        "set(_cmake_targets_defined \"\")\n"
        "set(_cmake_targets_not_defined \"\")\n"
        "set(_cmake_expected_targets \"\")\n"
        "foreach(_cmake_expected_target IN ITEMS " << expectedTargets << ")\n"
        "  list(APPEND _cmake_expected_targets \"${_cmake_expected_target}\")\n"
        /* ... */
        "\n\n";

This kind of situation was predicted about 9 month ago, along with a solution, so at least there is a known way to fix it. Alternative quick fix is to use regex like foreach\\((?:_expectedTarget|_cmake_expected_target) (.+)\\), less robust but faster to implement and it has a backward compatibility with previously generated packages. Still, probably better first check if IMPORTED_TARGETS exists, and if not, check for old regex.

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 a pull request may close this issue.

1 participant