Skip to content

Commit

Permalink
Choose the appropriate library for experimental filesystem, based on …
Browse files Browse the repository at this point in the history
…the compiler and standard library (ros2#146)

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
  • Loading branch information
emersonknapp authored and nuclearsandwich committed Mar 21, 2019
1 parent cc6af50 commit 3bbc242
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
14 changes: 12 additions & 2 deletions pluginlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ install(
if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
set(FILESYSTEM_LIB c++experimental)
else()
set(FILESYSTEM_LIB c++fs)
endif()
else()
set(FILESYSTEM_LIB stdc++fs)
endif()

set(prefix "${CMAKE_CURRENT_BINARY_DIR}/prefix")

# Write the necessary files for ament to detect a package.
Expand Down Expand Up @@ -81,7 +91,7 @@ if(BUILD_TESTING)
target_compile_definitions(${PROJECT_NAME}_unique_ptr_test PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")

if(UNIX AND NOT APPLE)
target_link_libraries(${PROJECT_NAME}_unique_ptr_test stdc++fs)
target_link_libraries(${PROJECT_NAME}_unique_ptr_test ${FILESYSTEM_LIB})
endif()
add_dependencies(${PROJECT_NAME}_unique_ptr_test test_plugins)
endif()
Expand All @@ -102,7 +112,7 @@ if(BUILD_TESTING)
target_compile_definitions(${PROJECT_NAME}_utest PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")

if(UNIX AND NOT APPLE)
target_link_libraries(${PROJECT_NAME}_utest stdc++fs)
target_link_libraries(${PROJECT_NAME}_utest ${FILESYSTEM_LIB})
endif()
add_dependencies(${PROJECT_NAME}_utest test_plugins)
endif()
Expand Down
12 changes: 11 additions & 1 deletion pluginlib/pluginlib-extras.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,18 @@ ament_register_extension("ament_package" "pluginlib"

include("${pluginlib_DIR}/pluginlib_export_plugin_description_file.cmake")

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
set(FILESYSTEM_LIB c++experimental)
else()
set(FILESYSTEM_LIB c++fs)
endif()
else()
set(FILESYSTEM_LIB stdc++fs)
endif()

if(UNIX AND NOT APPLE)
# this is needed to use the experimental/filesystem on Linux, but cannot be passed with
# ament_export_libraries() because it is not absolute and cannot be found with find_library
list(APPEND pluginlib_LIBRARIES stdc++fs)
list(APPEND pluginlib_LIBRARIES ${FILESYSTEM_LIB})
endif()

0 comments on commit 3bbc242

Please sign in to comment.