diff --git a/CMakeLists.txt b/CMakeLists.txt index d2d51b5..c774f1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,9 +25,10 @@ endif() add_library(${PROJECT_NAME} src/asserts.cpp + src/env.cpp src/filesystem_helper.cpp src/find_library.cpp - src/env.cpp + src/process.cpp src/shared_library.cpp) target_include_directories(${PROJECT_NAME} PUBLIC "$" @@ -36,7 +37,7 @@ if(WIN32) target_compile_definitions(${PROJECT_NAME} PRIVATE "RCPPUTILS_BUILDING_LIBRARY") endif() -ament_target_dependencies(${PROJECT_NAME} rcutils) +target_link_libraries(${PROJECT_NAME} PUBLIC rcutils::rcutils) # Export old-style CMake variables ament_export_include_directories("include/${PROJECT_NAME}") @@ -74,15 +75,13 @@ if(BUILD_TESTING) target_link_libraries(test_join ${PROJECT_NAME}) ament_add_gtest(test_time test/test_time.cpp) - target_link_libraries(test_time ${PROJECT_NAME}) - ament_target_dependencies(test_time rcutils) + target_link_libraries(test_time ${PROJECT_NAME} rcutils::rcutils) ament_add_gtest(test_env test/test_env.cpp ENV EMPTY_TEST= NORMAL_TEST=foo ) - ament_target_dependencies(test_env rcutils) target_link_libraries(test_env ${PROJECT_NAME}) ament_add_gtest(test_scope_exit test/test_scope_exit.cpp) @@ -95,7 +94,6 @@ if(BUILD_TESTING) ENV EXPECTED_WORKING_DIRECTORY=$ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - ament_target_dependencies(test_filesystem_helper rcutils) target_link_libraries(test_filesystem_helper ${PROJECT_NAME}) ament_add_gtest(test_find_and_replace test/test_find_and_replace.cpp) @@ -106,7 +104,6 @@ if(BUILD_TESTING) ament_add_gtest(test_process test/test_process.cpp) target_link_libraries(test_process ${PROJECT_NAME}) - ament_target_dependencies(test_process rcutils) set(append_library_dirs "$") @@ -129,8 +126,9 @@ if(BUILD_TESTING) add_library(test_library SHARED test/test_library.cpp) target_link_libraries(test_library PUBLIC ${PROJECT_NAME}) + ament_add_gtest(test_find_library test/test_find_library.cpp) - target_link_libraries(test_find_library test_library) + target_link_libraries(test_find_library test_library rcutils::rcutils) set_tests_properties(test_find_library PROPERTIES ENVIRONMENT "_TEST_LIBRARY_DIR=$;_TEST_LIBRARY=$") diff --git a/include/rcpputils/process.hpp b/include/rcpputils/process.hpp index 231f425..a8a9cbe 100644 --- a/include/rcpputils/process.hpp +++ b/include/rcpputils/process.hpp @@ -15,10 +15,10 @@ #ifndef RCPPUTILS__PROCESS_HPP_ #define RCPPUTILS__PROCESS_HPP_ -#include - #include +#include "rcpputils/visibility_control.hpp" + namespace rcpputils { @@ -32,17 +32,8 @@ namespace rcpputils * \return The program name. * \throws std::runtime_error on error */ -std::string get_executable_name() -{ - rcutils_allocator_t allocator = rcutils_get_default_allocator(); - char * executable_name = rcutils_get_executable_name(allocator); - if (nullptr == executable_name) { - throw std::runtime_error("Failed to get executable name"); - } - std::string ret(executable_name); - allocator.deallocate(executable_name, allocator.state); - return ret; -} +RCPPUTILS_PUBLIC +std::string get_executable_name(); } // namespace rcpputils diff --git a/include/rcpputils/time.hpp b/include/rcpputils/time.hpp index 073f72f..edf1a90 100644 --- a/include/rcpputils/time.hpp +++ b/include/rcpputils/time.hpp @@ -17,8 +17,6 @@ #include -#include "rcutils/time.h" - namespace rcpputils { diff --git a/src/process.cpp b/src/process.cpp new file mode 100644 index 0000000..a044641 --- /dev/null +++ b/src/process.cpp @@ -0,0 +1,38 @@ +// Copyright 2023 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "rcpputils/process.hpp" + +#include +#include + +#include "rcutils/allocator.h" +#include "rcutils/process.h" + +namespace rcpputils +{ + +std::string get_executable_name() +{ + rcutils_allocator_t allocator = rcutils_get_default_allocator(); + char * executable_name = rcutils_get_executable_name(allocator); + if (nullptr == executable_name) { + throw std::runtime_error("Failed to get executable name"); + } + std::string ret(executable_name); + allocator.deallocate(executable_name, allocator.state); + return ret; +} + +} // namespace rcpputils diff --git a/test/test_time.cpp b/test/test_time.cpp index 7f30ef3..7828630 100644 --- a/test/test_time.cpp +++ b/test/test_time.cpp @@ -16,6 +16,8 @@ #include +#include "rcutils/time.h" + TEST(test_time, test_convert_to_nanoseconds) { rcutils_duration_value_t expect_value = RCUTILS_S_TO_NS(5 * 60); // 5 minutes rcutils_duration_value_t cast_val = 0;