From 24041c4d874815aab35b9249bd045e3ef2ceb0c7 Mon Sep 17 00:00:00 2001 From: "Jonathan R. Madsen" Date: Wed, 25 Oct 2023 04:17:34 -0500 Subject: [PATCH] C++ filesystem and link to dl library in test exe (#29) * Add lib/rocprofiler-register/details/filesystem.hpp - this provides backwards compatibility for compiler which do not have - use when not available * Update tests/CMakeLists.txt - test executables link to dl library (via CMAKE_DL_LIBS) * Update CI workflow - include ubuntu-20.04 jobs --- .github/workflows/continuous-integration.yml | 8 ++++ .../details/CMakeLists.txt | 3 +- .../lib/rocprofiler-register/details/dl.cpp | 4 +- .../details/filesystem.hpp | 48 +++++++++++++++++++ .../rocprofiler_register.cpp | 3 +- tests/CMakeLists.txt | 11 ++++- 6 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 source/lib/rocprofiler-register/details/filesystem.hpp diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 2235140a6e..0a27dec6ba 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -32,6 +32,14 @@ jobs: compiler: 'clang-15' ci-args: '--linter clang-tidy' ci-tag: '-clang-tidy' + - runner: 'ubuntu-20.04' + compiler: 'gcc-9' + ci-args: '' + ci-tag: '' + - runner: 'ubuntu-20.04' + compiler: 'clang-10' + ci-args: '' + ci-tag: '' # - runner: 'ubuntu-latest' # compiler: 'gcc-12' # ci-args: '--memcheck ThreadSanitizer' diff --git a/source/lib/rocprofiler-register/details/CMakeLists.txt b/source/lib/rocprofiler-register/details/CMakeLists.txt index ef1160ec66..71587dbd81 100644 --- a/source/lib/rocprofiler-register/details/CMakeLists.txt +++ b/source/lib/rocprofiler-register/details/CMakeLists.txt @@ -3,7 +3,8 @@ # set(rocprofiler_register_details_sources dl.cpp utility.cpp) -set(rocprofiler_register_details_headers environment.hpp dl.hpp utility.hpp) +set(rocprofiler_register_details_headers environment.hpp dl.hpp filesystem.hpp + utility.hpp) target_sources(rocprofiler-register PRIVATE ${rocprofiler_register_details_sources} ${rocprofiler_register_details_headers}) diff --git a/source/lib/rocprofiler-register/details/dl.cpp b/source/lib/rocprofiler-register/details/dl.cpp index 5c45c4ec8b..4a1e52327b 100644 --- a/source/lib/rocprofiler-register/details/dl.cpp +++ b/source/lib/rocprofiler-register/details/dl.cpp @@ -23,9 +23,9 @@ #define GNU_SOURCE 1 #include "dl.hpp" +#include "filesystem.hpp" #include "utility.hpp" -#include #include #include #include @@ -38,8 +38,6 @@ #include #include -namespace fs = ::std::filesystem; - namespace rocprofiler_register { namespace binary diff --git a/source/lib/rocprofiler-register/details/filesystem.hpp b/source/lib/rocprofiler-register/details/filesystem.hpp new file mode 100644 index 0000000000..550ce92a8f --- /dev/null +++ b/source/lib/rocprofiler-register/details/filesystem.hpp @@ -0,0 +1,48 @@ +// MIT License +// +// Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#if defined __has_include +# if __has_include() +# include +# endif +#endif + +#if defined(__cpp_lib_filesystem) +# define ROCPROFILER_REGISTER_HAS_CPP_LIB_FILESYSTEM 1 +#else +# if defined __has_include +# if __has_include() +# include +# endif +# endif +#endif + +#if defined(ROCPROFILER_REGISTER_HAS_CPP_LIB_FILESYSTEM) && \ + ROCPROFILER_REGISTER_HAS_CPP_LIB_FILESYSTEM > 0 +# include +namespace fs = ::std::filesystem; // NOLINT +#else +# include +namespace fs = ::std::experimental::filesystem; // NOLINT +#endif diff --git a/source/lib/rocprofiler-register/rocprofiler_register.cpp b/source/lib/rocprofiler-register/rocprofiler_register.cpp index a9329b5753..548b0ae540 100644 --- a/source/lib/rocprofiler-register/rocprofiler_register.cpp +++ b/source/lib/rocprofiler-register/rocprofiler_register.cpp @@ -24,12 +24,12 @@ #include "details/dl.hpp" #include "details/environment.hpp" +#include "details/filesystem.hpp" #include "glog/logging.h" #include #include #include -#include #include #include #include @@ -75,7 +75,6 @@ rocprofiler_register_import_roctx_static(void); namespace { -namespace fs = ::std::filesystem; using namespace rocprofiler_register; using rocprofiler_set_api_table_t = decltype(::rocprofiler_set_api_table)*; using bitset_t = std::bitset; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fc1c741ab6..077f647862 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -56,6 +56,14 @@ function(rocp_register_strip_target) endif() endfunction() +if(NOT CMAKE_DL_LIBS) + find_library(DL_LIBRARY NAMES dl) + if(NOT DL_LIBRARY) + set(DL_LIBRARY dl) + endif() + set(CMAKE_DL_LIBS ${DL_LIBRARY}) +endif() + # # mock libraries # @@ -72,7 +80,8 @@ find_package(Threads REQUIRED) add_library(rocprofiler-register-tests-common INTERFACE) target_include_directories(rocprofiler-register-tests-common INTERFACE $) -target_link_libraries(rocprofiler-register-tests-common INTERFACE Threads::Threads stdc++) +target_link_libraries(rocprofiler-register-tests-common INTERFACE Threads::Threads stdc++ + ${CMAKE_DL_LIBS}) add_library(rocprofiler-register-tests-strong INTERFACE) target_compile_definitions(rocprofiler-register-tests-strong