Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions .github/workflows/ci_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,9 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true

- name: Load ccache
uses: actions/cache@v4
with:
path: /home/runner/.ccache
key: ccache-${{ runner.os }}-${{ github.workflow }}-${{ matrix.compiler }}-${{ github.ref }}-${{ github.run_id }}
restore-keys: |
ccache-${{ runner.os }}-${{ github.workflow }}-${{ matrix.compiler }}-${{ github.ref }}
ccache-${{ runner.os }}-${{ github.workflow }}-${{ matrix.compiler }}
- name: Setup cache
uses: seqan/actions/setup-actions-cache@main

- name: Increase ccache size
run: echo "CCACHE_MAXSIZE=300M" >> "${GITHUB_ENV}"
Expand Down
12 changes: 2 additions & 10 deletions .github/workflows/ci_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- name: Load ccache
uses: actions/cache@v4
with:
path: /home/runner/.ccache
key: ccache-${{ runner.os }}-${{ github.workflow }}-${{ matrix.compiler }}-${{ github.ref }}-${{ github.run_id }}
restore-keys: |
ccache-${{ runner.os }}-${{ github.workflow }}-${{ matrix.compiler }}-${{ github.ref }}
ccache-${{ runner.os }}-${{ github.workflow }}-${{ matrix.compiler }}
- name: Setup cache
uses: seqan/actions/setup-actions-cache@main

- name: Configure tests
run: |
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- name: Setup toolchain
uses: seqan/actions/setup-toolchain@main
Expand Down
12 changes: 2 additions & 10 deletions .github/workflows/ci_misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- name: Load ccache
uses: actions/cache@v4
with:
path: /home/runner/.ccache
key: ccache-${{ runner.os }}-${{ github.workflow }}-${{ matrix.build }}-${{ matrix.compiler }}-${{ github.ref }}-${{ github.run_id }}
restore-keys: |
ccache-${{ runner.os }}-${{ github.workflow }}-${{ matrix.build }}-${{ matrix.compiler }}-${{ github.ref }}
ccache-${{ runner.os }}-${{ github.workflow }}-${{ matrix.build }}-${{ matrix.compiler }}
- name: Setup cache
uses: seqan/actions/setup-actions-cache@main

- name: Configure tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ VERSION

| | requirement | version | comment |
|-------------------|-----------------------------------------------------------|----------|---------------------------------------------|
|**compiler** | [GCC](https://gcc.gnu.org) | ≥ 11 | |
|**compiler** | [GCC](https://gcc.gnu.org) | ≥ 12 | |
|**compiler** | [Clang](https://clang.llvm.org/) | ≥ 17 | |
|**build system** | [CMake](https://cmake.org) | ≥ 3.16 | optional, but recommended |
|**optional libs** | [TDL](https://github.com/deNBI-cibi/tool_description_lib) | ≥ 1.0.0 | required for CWL and CTD export |
96 changes: 32 additions & 64 deletions cmake/sharg-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
# SHARG_INCLUDE_DIRS -- to be passed to include_directories ()
# SHARG_LIBRARIES -- to be passed to target_link_libraries ()
# SHARG_DEFINITIONS -- to be passed to add_definitions ()
# SHARG_CXX_FLAGS -- to be added to CMAKE_CXX_FLAGS
#
# Additionally, the following [IMPORTED][IMPORTED] targets are defined:
#
Expand All @@ -50,7 +49,6 @@
# target_include_directories(target $SHARG_INCLUDE_DIRS),
# target_link_libraries(target $SHARG_LIBRARIES),
# target_compile_definitions(target $SHARG_DEFINITIONS) and
# target_compile_options(target $SHARG_CXX_FLAGS)
# for a target.
#
# [IMPORTED]: https://cmake.org/cmake/help/v3.10/prop_tgt/IMPORTED.html#prop_tgt:IMPORTED
Expand Down Expand Up @@ -154,46 +152,25 @@ set (CMAKE_REQUIRED_FLAGS ${CMAKE_CXX_FLAGS})
option (SHARG_NO_TDL "Do not use TDL, even if present." OFF)

# ----------------------------------------------------------------------------
# Require C++20
# Check supported compilers
# ----------------------------------------------------------------------------

set (SHARG_CXX_FLAGS "")

set (CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})

set (CXXSTD_TEST_SOURCE
"#if !defined (__cplusplus) || (__cplusplus < 202002)
#error NOCXX20
#endif
int main() {}")

check_cxx_source_compiles ("${CXXSTD_TEST_SOURCE}" CXX20_BUILTIN)

if (CXX20_BUILTIN)
sharg_config_print ("C++ Standard-20 support: builtin")
else ()
set (CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS_SAVE} -std=c++20")

check_cxx_source_compiles ("${CXXSTD_TEST_SOURCE}" CXX20_FLAG)

if (CXX20_FLAG)
sharg_config_print ("C++ Standard-20 support: via -std=c++20")
else ()
sharg_config_error ("SHARG requires C++20, but your compiler does not support it.")
endif ()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12)
message (FATAL_ERROR "GCC < 12 is not supported. The detected compiler version is ${CMAKE_CXX_COMPILER_VERSION}.")
endif ()

list (APPEND SHARG_CXX_FLAGS "-std=c++20")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17)
message (FATAL_ERROR "Clang < 17 is not supported. The detected compiler version is ${CMAKE_CXX_COMPILER_VERSION}.")
endif ()

# ----------------------------------------------------------------------------
# thread support (pthread, windows threads)
# ----------------------------------------------------------------------------
set (SHARG_LIBRARIES "")

set (THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package (Threads QUIET)

if (Threads_FOUND)
if (TARGET Threads::Threads)
list (APPEND SHARG_LIBRARIES Threads::Threads)
if ("${CMAKE_THREAD_LIBS_INIT}" STREQUAL "")
sharg_config_print ("Thread support: builtin.")
Expand All @@ -207,7 +184,6 @@ endif ()
# ----------------------------------------------------------------------------
# tool description lib (tdl) dependency
# ----------------------------------------------------------------------------
set (SHARG_USE_TDL FALSE)

if (NOT SHARG_NO_TDL)
if (NOT SHARG_HAS_CPM)
Expand All @@ -216,42 +192,34 @@ if (NOT SHARG_NO_TDL)
CPMGetPackage (tdl)
endif ()

if (TDL_FOUND OR tdl_ADDED)
if (TARGET tdl::tdl)
sharg_config_print ("Optional dependency: TDL found.")
set (SHARG_USE_TDL TRUE)
list (APPEND SHARG_DEFINITIONS "-DSHARG_HAS_TDL=1")
list (APPEND SHARG_LIBRARIES tdl::tdl)
else ()
sharg_config_print ("Optional dependency: TDL not found.")
list (APPEND SHARG_DEFINITIONS "-DSHARG_HAS_TDL=0")
endif ()
else ()
sharg_config_print ("Optional dependency: TDL deactivated.")
endif ()

if (SHARG_USE_TDL)
set (SHARG_DEFINITIONS ${SHARG_DEFINITIONS} "-DSHARG_HAS_TDL=1")
else ()
set (SHARG_DEFINITIONS ${SHARG_DEFINITIONS} "-DSHARG_HAS_TDL=0")
list (APPEND SHARG_DEFINITIONS "-DSHARG_HAS_TDL=0")
endif ()

# ----------------------------------------------------------------------------
# System dependencies
# ----------------------------------------------------------------------------

# librt
if ((${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
OR (${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD")
OR (${CMAKE_SYSTEM_NAME} STREQUAL "GNU"))
list (APPEND SHARG_LIBRARIES rt)
find_library (SHARG_RT_LIB rt)
if (SHARG_RT_LIB)
list (APPEND SHARG_LIBRARIES ${SHARG_RT_LIB})
endif ()

# libexecinfo -- implicit
check_include_file_cxx (execinfo.h _SHARG_HAVE_EXECINFO)
mark_as_advanced (_SHARG_HAVE_EXECINFO)
if (_SHARG_HAVE_EXECINFO)
find_package (Backtrace QUIET)
if (TARGET Backtrace::Backtrace)
list (APPEND SHARG_LIBRARIES Backtrace::Backtrace)
sharg_config_print ("Optional dependency: libexecinfo found.")
if ((${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") OR (${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD"))
list (APPEND SHARG_LIBRARIES execinfo elf)
endif ()
else ()
sharg_config_print ("Optional dependency: libexecinfo not found.")
endif ()
Expand All @@ -260,22 +228,22 @@ endif ()
# Perform compilability test of platform.hpp (tests some requirements)
# ----------------------------------------------------------------------------

set (CXXSTD_TEST_SOURCE "#include <sharg/platform.hpp>
int main() {}")
# cmake-format: off
# Note: With CMake >= 3.25, the file WRITE can be removed, the second and third line in try_compile can be replaced by
# SOURCE_FROM_CONTENT "platform_test.cpp" "#include <sharg/platform.hpp>\nint main() {}"
file (WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/platform_test.cpp"
"#include <sharg/platform.hpp>\nint main() {}")

# using try_compile instead of check_cxx_source_compiles to capture output in case of failure
file (WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx" "${CXXSTD_TEST_SOURCE}\n")

# Can't find tdl::tdl in try_compile, so we need to remove it from SHARG_LIBRARIES
set (SHARG_TRY_COMPILE_LIBRARIES ${SHARG_LIBRARIES})
list (REMOVE_ITEM SHARG_TRY_COMPILE_LIBRARIES tdl::tdl)
try_compile (SHARG_PLATFORM_TEST ${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS:STRING=${CMAKE_CXX_FLAGS} ${SHARG_CXX_FLAGS}"
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_INCLUDE_PATH};${SHARG_INCLUDE_DIR}"
try_compile (SHARG_PLATFORM_TEST
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/platform_test.cpp
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${SHARG_INCLUDE_DIR}"
COMPILE_DEFINITIONS ${SHARG_DEFINITIONS}
LINK_LIBRARIES ${SHARG_TRY_COMPILE_LIBRARIES}
CXX_STANDARD 23
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
OUTPUT_VARIABLE SHARG_PLATFORM_TEST_OUTPUT)
# cmake-format: on

if (SHARG_PLATFORM_TEST)
sharg_config_print ("SHARG platform.hpp build: passed.")
Expand Down Expand Up @@ -310,14 +278,15 @@ if (CMAKE_FIND_PACKAGE_NAME)
else ()
set (SHARG_VERSION "${PACKAGE_VERSION}")
endif ()

# ----------------------------------------------------------------------------
# Export targets
# ----------------------------------------------------------------------------

if (NOT TARGET sharg::sharg)
add_library (sharg_sharg INTERFACE)
target_compile_definitions (sharg_sharg INTERFACE ${SHARG_DEFINITIONS})
target_compile_options (sharg_sharg INTERFACE ${SHARG_CXX_FLAGS})
target_compile_features (sharg_sharg INTERFACE cxx_std_23)
target_link_libraries (sharg_sharg INTERFACE ${SHARG_LIBRARIES})
target_include_directories (sharg_sharg INTERFACE "${SHARG_INCLUDE_DIR}")
add_library (sharg::sharg ALIAS sharg_sharg)
Expand All @@ -338,7 +307,6 @@ if (SHARG_FIND_DEBUG)
message (" SHARG_INCLUDE_DIR ${SHARG_INCLUDE_DIR}")
message (" SHARG_LIBRARIES ${SHARG_LIBRARIES}")
message (" SHARG_DEFINITIONS ${SHARG_DEFINITIONS}")
message (" SHARG_CXX_FLAGS ${SHARG_CXX_FLAGS}")
message ("")
message (" SHARG_VERSION ${SHARG_VERSION}")
message (" SHARG_VERSION_MAJOR ${SHARG_VERSION_MAJOR}")
Expand Down
16 changes: 9 additions & 7 deletions include/sharg/detail/type_name_as_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ inline std::string const type_name_as_string = []()
// We exclude status != 0, because this code can't be reached normally, only if there is a defect in the compiler
// itself, since the type is directly given by the compiler. See https://github.com/seqan/seqan3/pull/2311.
// LCOV_EXCL_START
// clang-format off
if (status != 0)
return std::string{typeid(type).name()} +
" (abi::__cxa_demangle error status (" + std::to_string(status) + "): " +
(status == -1 ? "A memory allocation failure occurred." :
(status == -2 ? "mangled_name is not a valid name under the C++ ABI mangling rules." :
(status == -3 ? "One of the arguments is invalid." : "Unknown Error"))) + ")";
// clang-format on
{
demangled_name =
std::string{typeid(type).name()} + " (abi::__cxa_demangle error status (" + std::to_string(status) + "): "
+ (status == -1 ? "A memory allocation failure occurred."
: (status == -2 ? "mangled_name is not a valid name under the C++ ABI mangling rules."
: (status == -3 ? "One of the arguments is invalid." : "Unknown Error")))
+ ")";
return demangled_name;
}
// LCOV_EXCL_STOP

demangled_name = std::string{std::addressof(*demangled_name_ptr)};
Expand Down
56 changes: 26 additions & 30 deletions test/header/generate_header_source.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,61 +13,57 @@ option (HEADER_SUB_TEST "")

file (WRITE "${HEADER_TARGET_SOURCE}" "") # write empty file

# cmake-format: off

if (HEADER_SUB_TEST STREQUAL "no-self-include")
# this test ensures that a header will not be included by itself later
file (READ "${HEADER_FILE_ABSOLUTE}" header_content)

string (REPLACE "#pragma once" "" header_content "${header_content}")

file (APPEND "${HEADER_TARGET_SOURCE}" "${header_content}")
file (APPEND "${HEADER_TARGET_SOURCE}"
"// sharg-header-test-no-self-include-start\n"
"${header_content}\n"
"// sharg-header-test-no-self-include-end\n\n")
else ()
# this test ensures that a header guard is in place
file (APPEND "${HEADER_TARGET_SOURCE}"
"
#include <${HEADER_FILE_INCLUDE}>
#include <${HEADER_FILE_INCLUDE}>")
"// sharg-header-test-header-guard-start\n"
"#include <${HEADER_FILE_INCLUDE}>\n"
"#include <${HEADER_FILE_INCLUDE}>\n"
"// sharg-header-test-header-guard-end\n\n")
endif ()

# these includes are required by some headers (note that they follow)
file (APPEND "${HEADER_TARGET_SOURCE}"
"
#include <gtest/gtest.h>
TEST(${HEADER_TEST_NAME_SAFE}) {}")
"// sharg-header-test-dependencies-start\n"
"#include <gtest/gtest.h>\n"
"TEST(${HEADER_TEST_NAME_SAFE}) {}\n"
"// sharg-header-test-dependencies-end\n\n")

# test that sharg headers include platform.hpp
if ("${HEADER_COMPONENT}" MATCHES "sharg")

# exclude sharg/std/* and sharg/version.hpp from platform test
if (NOT HEADER_FILE_INCLUDE MATCHES "sharg/(std/|version.hpp)")
file (APPEND "${HEADER_TARGET_SOURCE}"
"
#ifndef SHARG_DOXYGEN_ONLY
#error \"Your header '${HEADER_FILE_INCLUDE}' file is missing #include <sharg/platform.hpp>\"
#endif")
"// sharg-header-test-platform-start\n"
"#ifndef SHARG_DOXYGEN_ONLY\n"
"#error \"Your header '${HEADER_FILE_INCLUDE}' file is missing #include <sharg/platform.hpp>\"\n"
"#endif\n"
"// sharg-header-test-platform-end\n\n")
endif ()

# sharg/std/* must not include platform.hpp (and therefore any other sharg header)
# See https://github.com/seqan/product_backlog/issues/135
if (HEADER_FILE_INCLUDE MATCHES "sharg/std/")
file (APPEND "${HEADER_TARGET_SOURCE}"
"
#ifdef SHARG_DOXYGEN_ONLY
#error \"The standard header '${HEADER_FILE_INCLUDE}' file MUST NOT include any other sharg header\"
#endif")
"// sharg-header-test-no-platform-start\n"
"#ifdef SHARG_DOXYGEN_ONLY\n"
"#error \"The standard header '${HEADER_FILE_INCLUDE}' file MUST NOT include any other sharg header\"\n"
"#endif\n"
"// sharg-header-test-no-platform-end\n\n")
endif ()

# test whether sharg has the visibility bug on lower gcc versions
# https://github.com/seqan/seqan3/issues/1317
if (NOT HEADER_FILE_INCLUDE MATCHES "sharg/version.hpp")
file (APPEND "${HEADER_TARGET_SOURCE}"
"
#include <sharg/platform.hpp>
class A{ int i{5}; };

template <typename t>
concept private_bug = requires(t a){a.i;};

static_assert(!private_bug<A>, \"See https://github.com/seqan/seqan3/issues/1317\");")
endif ()

endif ()

# cmake-format: on
Loading