diff --git a/rviz_assimp_vendor/CMakeLists.txt b/rviz_assimp_vendor/CMakeLists.txt index 4eebc55c4..47c066b4e 100644 --- a/rviz_assimp_vendor/CMakeLists.txt +++ b/rviz_assimp_vendor/CMakeLists.txt @@ -52,6 +52,72 @@ macro(build_assimp) ) endmacro() +# Copy and fix the assimp config files on Ubuntu, in order to suppress a warning. +# This should be removed once upstream is updated to assimp-0.5.1, see: +# https://github.com/ros2/rviz/issues/524 +# https://bugs.launchpad.net/ubuntu/+source/assimp/+bug/1869405 +### BEGIN HACKS +set(IS_UBUNTU FALSE) +if(UNIX AND NOT APPLE) + find_program(LSB_RELEASE_EXEC lsb_release) + if(EXISTS "${LSB_RELEASE_EXEC}") + execute_process(COMMAND ${LSB_RELEASE_EXEC} -is + OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + else() + set(LSB_RELEASE_ID_SHORT "Unknown") + endif() + + if(${LSB_RELEASE_ID_SHORT} STREQUAL "Ubuntu") + set(IS_UBUNTU TRUE) + endif() +endif() + +if(IS_UBUNTU) + file(GLOB_RECURSE assimp_target_files "/usr/lib/*/cmake/assimp-5.0/assimpTargets.cmake") + list(LENGTH assimp_target_files assimp_target_files_len) + if(assimp_target_files_len EQUAL 0) + message(FATAL_ERROR "failed to find assimpTargets.cmake as expected") + endif() + if(NOT assimp_target_files_len EQUAL 1) + message(FATAL_ERROR "found multiple assimpTargets.cmake files, unexpectedly") + endif() + list(GET assimp_target_files 0 assimp_target_file) + + get_filename_component(assimp_target_dir "${assimp_target_file}" DIRECTORY) + set(new_assimp_target_dir "${CMAKE_CURRENT_BINARY_DIR}/assimp-0.5") + + file(READ "${assimp_target_dir}/assimpTargets.cmake" assimp_targets_content) + string(REPLACE + "if(ON)" + "set(WORKAROUND ON)\nif(WORKAROUND)" + assimp_targets_content + ${assimp_targets_content}) + file(WRITE "${new_assimp_target_dir}/assimpTargets.cmake" "${assimp_targets_content}") + file(READ "${assimp_target_dir}/assimpTargets-release.cmake" assimp_targets_content) + string(REPLACE + "if(ON)" + "set(WORKAROUND ON)\nif(WORKAROUND)" + assimp_targets_content + ${assimp_targets_content}) + file(WRITE "${new_assimp_target_dir}/assimpTargets-release.cmake" "${assimp_targets_content}") + file( + COPY "${assimp_target_dir}/assimp-config.cmake" + DESTINATION "${new_assimp_target_dir}") + file( + COPY "${assimp_target_dir}/assimp-config-version.cmake" + DESTINATION "${new_assimp_target_dir}") + set(assimp_DIR "${new_assimp_target_dir}") + + install( + DIRECTORY + ${new_assimp_target_dir}/ + DESTINATION + ${CMAKE_INSTALL_PREFIX}/opt/rviz_assimp_vendor_custom_config + ) +endif() +### END HACKS find_package(assimp QUIET) if(NOT assimp_FOUND OR "${assimp_VERSION}" VERSION_LESS 4.1.0) diff --git a/rviz_assimp_vendor/rviz_assimp_vendor-extras.cmake.in b/rviz_assimp_vendor/rviz_assimp_vendor-extras.cmake.in index 8f8133d4f..971971563 100644 --- a/rviz_assimp_vendor/rviz_assimp_vendor-extras.cmake.in +++ b/rviz_assimp_vendor/rviz_assimp_vendor-extras.cmake.in @@ -1,3 +1,30 @@ +# Use custom CMake config files for assimp on Ubuntu to work around a cmake warning. +# This should be removed once upstream is updated to assimp-0.5.1, see: +# https://github.com/ros2/rviz/issues/524 +# https://bugs.launchpad.net/ubuntu/+source/assimp/+bug/1869405 +### BEGIN HACKS +set(IS_UBUNTU FALSE) +if(UNIX AND NOT APPLE) + find_program(LSB_RELEASE_EXEC lsb_release) + if(EXISTS "${LSB_RELEASE_EXEC}") + execute_process(COMMAND ${LSB_RELEASE_EXEC} -is + OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + else() + set(LSB_RELEASE_ID_SHORT "Unknown") + endif() + + if(${LSB_RELEASE_ID_SHORT} STREQUAL "Ubuntu") + set(IS_UBUNTU TRUE) + endif() +endif() + +if(IS_UBUNTU) + set(assimp_DIR "${@PROJECT_NAME@_DIR}/../../../opt/rviz_assimp_vendor_custom_config") +endif() +### END HACKS + find_package(assimp QUIET) if(NOT assimp_FOUND OR "${assimp_VERSION}" VERSION_LESS 4.1.0)