Skip to content

Commit

Permalink
build: got rid of old clang hacks and range-v3 dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Sep 26, 2023
1 parent 3b6a22d commit 25fee70
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 236 deletions.
10 changes: 0 additions & 10 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ def _use_libfmt(self):
std_support = compiler == "msvc" and version >= 193 and compiler.cppstd == 23
return not std_support

@property
def _use_range_v3(self):
compiler = self.settings.compiler
version = Version(self.settings.compiler.version)
return "clang" in compiler and compiler.libcxx == "libc++" and version < 14

def set_version(self):
content = load(self, os.path.join(self.recipe_folder, "src/CMakeLists.txt"))
version = re.search(
Expand All @@ -110,8 +104,6 @@ def requirements(self):
self.requires("gsl-lite/0.40.0")
if self._use_libfmt:
self.requires("fmt/10.1.0")
if self._use_range_v3:
self.requires("range-v3/0.11.0")

def build_requirements(self):
if self._build_all:
Expand Down Expand Up @@ -174,8 +166,6 @@ def package_info(self):
self.cpp_info.components["core"].requires = ["gsl-lite::gsl-lite"]
if compiler == "msvc":
self.cpp_info.components["core"].cxxflags = ["/utf-8"]
if self._use_range_v3:
self.cpp_info.components["core"].requires.append("range-v3::range-v3")

# rest
self.cpp_info.components["core-io"].requires = ["core"]
Expand Down
41 changes: 0 additions & 41 deletions src/cmake/CheckLibcxxInUse.cmake

This file was deleted.

13 changes: 1 addition & 12 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ if(NOT TARGET gsl::gsl-lite)
find_package(gsl-lite CONFIG REQUIRED)
endif()

# check if libc++ is being used
include(CheckLibcxxInUse)
check_libcxx_in_use(${projectPrefix}LIBCXX)

# core library definition
add_library(
mp-units-core
Expand Down Expand Up @@ -78,14 +74,7 @@ target_include_directories(
$<INSTALL_INTERFACE:include>
)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(${projectPrefix}LIBCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "14")
if(NOT TARGET range-v3::range-v3)
find_package(range-v3 CONFIG REQUIRED)
endif()
target_link_libraries(mp-units-core INTERFACE range-v3::range-v3)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(
mp-units-core
INTERFACE /utf-8 # Specifies both the source character set and the execution character set as UTF-8
Expand Down
144 changes: 1 addition & 143 deletions src/core/include/mp-units/bits/external/hacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,34 +70,10 @@
#define MP_UNITS_DIAGNOSTIC_IGNORE_DEPRECATED
#endif

#if _LIBCPP_VERSION
#define MP_UNITS_LIBCXX _LIBCPP_VERSION
#endif

#if MP_UNITS_LIBCXX

#if MP_UNITS_LIBCXX < 13000

#include <concepts/concepts.hpp>
#include <range/v3/algorithm/lower_bound.hpp>
#include <range/v3/algorithm/transform.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/iterator.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/range/concepts.hpp>

#elif MP_UNITS_LIBCXX < 14000

#include <range/v3/functional/comparisons.hpp>

#endif

#endif

#include <compare>
#include <concepts>

#if MP_UNITS_COMP_MSVC || (MP_UNITS_COMP_CLANG && MP_UNITS_COMP_CLANG < 16)
#if MP_UNITS_COMP_MSVC

#define MP_UNITS_TYPENAME typename

Expand Down Expand Up @@ -145,124 +121,6 @@ namespace std {
template<class T>
concept default_constructible = constructible_from<T>;

#elif MP_UNITS_LIBCXX

#if MP_UNITS_LIBCXX < 13000

// concepts
using concepts::common_with;
using concepts::constructible_from;
using concepts::convertible_to;
using concepts::copy_constructible;
using concepts::derived_from;
using concepts::equality_comparable;
using concepts::equality_comparable_with;
using concepts::integral;
using concepts::move_constructible;
using concepts::regular;
using concepts::three_way_comparable;
using concepts::three_way_comparable_with;
using concepts::totally_ordered;

using ranges::compare_three_way;

using ranges::input_iterator;
using ranges::iter_value_t;
using ranges::sentinel_for;

namespace ranges {

using ::ranges::begin;
using ::ranges::distance;
using ::ranges::end;

using ::ranges::input_range;
using ::ranges::range_value_t;

using ::ranges::lower_bound;
using ::ranges::transform;

} // namespace ranges

// missing in Range-v3
template<class T>
concept floating_point = std::is_floating_point_v<T>;

template<class T>
concept default_initializable =
std::constructible_from<T> && requires { T{}; } && requires { ::new (static_cast<void*>(nullptr)) T; };

template<class F, class... Args>
concept invocable = requires(F&& f, Args&&... args) { std::invoke(std::forward<F>(f), std::forward<Args>(args)...); };

template<class F, class... Args>
concept regular_invocable = invocable<F, Args...>;

template<class T, class U>
constexpr bool cmp_equal(T t, U u) noexcept
{
using UT = std::make_unsigned_t<T>;
using UU = std::make_unsigned_t<U>;
if constexpr (std::is_signed_v<T> == std::is_signed_v<U>)
return t == u;
else if constexpr (std::is_signed_v<T>)
return t < 0 ? false : UT(t) == u;
else
return u < 0 ? false : t == UU(u);
}

template<class T, class U>
constexpr bool cmp_not_equal(T t, U u) noexcept
{
return !cmp_equal(t, u);
}

template<class T, class U>
constexpr bool cmp_less(T t, U u) noexcept
{
using UT = std::make_unsigned_t<T>;
using UU = std::make_unsigned_t<U>;
if constexpr (std::is_signed_v<T> == std::is_signed_v<U>)
return t < u;
else if constexpr (std::is_signed_v<T>)
return t < 0 ? true : UT(t) < u;
else
return u < 0 ? false : t < UU(u);
}

template<class T, class U>
constexpr bool cmp_greater(T t, U u) noexcept
{
return cmp_less(u, t);
}

template<class T, class U>
constexpr bool cmp_less_equal(T t, U u) noexcept
{
return !cmp_greater(t, u);
}

template<class T, class U>
constexpr bool cmp_greater_equal(T t, U u) noexcept
{
return !cmp_less(t, u);
}

template<class R, class T>
constexpr bool in_range(T t) noexcept
{
return std::cmp_greater_equal(t, std::numeric_limits<R>::min()) &&
std::cmp_less_equal(t, std::numeric_limits<R>::max());
}

#elif MP_UNITS_LIBCXX < 14000

using concepts::three_way_comparable;
using concepts::three_way_comparable_with;
using ::ranges::compare_three_way;

#endif

#endif

} // namespace std
30 changes: 0 additions & 30 deletions src/mp-unitsConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

function(__check_libcxx_in_use variable)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(CHECK_START "Checking if libc++ is being used")
list(APPEND CMAKE_MESSAGE_INDENT " ")

include(CheckCXXSymbolExists)
check_cxx_symbol_exists(_LIBCPP_VERSION "ciso646" ${variable})
set(${variable} ${${variable}} PARENT_SCOPE)

list(POP_BACK CMAKE_MESSAGE_INDENT)

if(${variable})
message(CHECK_PASS "found")
else()
message(CHECK_FAIL "not found")
endif()
endif()
endfunction()

include(CMakeFindDependencyMacro)

if(MP_UNITS_USE_LIBFMT)
Expand All @@ -47,15 +28,4 @@ endif()

find_dependency(gsl-lite)

# add range-v3 dependency only for clang + libc++
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
__check_libcxx_in_use(__units_libcxx)

if(__units_libcxx AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "14")
find_dependency(range-v3)
endif()

unset(__units_libcxx)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/mp-unitsTargets.cmake")

0 comments on commit 25fee70

Please sign in to comment.