Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
28 changes: 7 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
cmake_minimum_required(VERSION 3.23)

# Toolchain setup must come before the first project() call in the entire CMake buildsystem.
# If ystdlib is not the top-level project, the following setup has no effect.
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/Toolchains/utils.cmake")
setup_toolchains()

project(ystdlib VERSION "0.1.0" LANGUAGES CXX)

validate_compiler_versions()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
Expand All @@ -10,27 +17,6 @@ include(ystdlib-helpers)
option(BUILD_SHARED_LIBS "Build using shared libraries." OFF)
option(ystdlib_BUILD_TESTING "Build the testing tree for ystdlib." ON)

# Require compiler versions that support the C++20 features necessary for compiling ystdlib
if("AppleClang" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
set(ystdlib_CMAKE_CXX_COMPILER_MIN_VERSION "16")
elseif("Clang" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
set(ystdlib_CMAKE_CXX_COMPILER_MIN_VERSION "16")
elseif("GNU" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
set(ystdlib_CMAKE_CXX_COMPILER_MIN_VERSION "11")
else()
message(
FATAL_ERROR
"Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}. Please use AppleClang, Clang, or GNU."
)
endif()
if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "${ystdlib_CMAKE_CXX_COMPILER_MIN_VERSION}")
message(
FATAL_ERROR
"${CMAKE_CXX_COMPILER_ID} version ${CMAKE_CXX_COMPILER_VERSION} is too low. Must be at \
least ${ystdlib_CMAKE_CXX_COMPILER_MIN_VERSION}."
)
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS
ON
CACHE BOOL
Expand Down
21 changes: 21 additions & 0 deletions cmake/Toolchains/llvm-clang-15-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
message(STATUS "Setting up LLVM v15 toolchain...")

execute_process(
COMMAND
"brew" "--prefix" "llvm@15"
RESULT_VARIABLE BREW_RESULT
OUTPUT_VARIABLE LLVM_TOOLCHAIN_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT 0 EQUAL BREW_RESULT)
message(
FATAL_ERROR
"Failed to locate LLVM v15 using Homebrew. Please ensure llvm@15 is installed: 'brew \
install llvm@15'"
)
endif()

set(CMAKE_C_COMPILER "${LLVM_TOOLCHAIN_PREFIX}/bin/clang")
set(CMAKE_CXX_COMPILER "${LLVM_TOOLCHAIN_PREFIX}/bin/clang++")
set(CMAKE_AR "${LLVM_TOOLCHAIN_PREFIX}/bin/llvm-ar")
set(CMAKE_RANLIB "${LLVM_TOOLCHAIN_PREFIX}/bin/llvm-ranlib")
49 changes: 49 additions & 0 deletions cmake/Toolchains/utils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This file contains utility functions for setting up toolchains and validating toolchain versions
# to ensure compatibility with the C++20 features required by the project.

# Sets up the appropriate toolchain file based on the host system.
function(setup_toolchains)
# For macOS versions below 15, use the LLVM 15 Clang toolchain.
if("Darwin" STREQUAL "${CMAKE_HOST_SYSTEM_NAME}")
execute_process(
COMMAND
"sw_vers" "--productVersion"
OUTPUT_VARIABLE MACOS_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if("${MACOS_VERSION}" VERSION_LESS "15")
set(CMAKE_TOOLCHAIN_FILE
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Toolchains/llvm-clang-15-toolchain.cmake"
CACHE STRING
"Toolchain file"
)
endif()
endif()
endfunction()

# Checks if the compiler ID and version meet the minimum requirements to support C++20 features
# required by the project:
# - AppleClang: version 15+
# - Clang: version 15+
# - GNU: version 11+
function(validate_compiler_versions)
if("AppleClang" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
set(CXX_COMPILER_MIN_VERSION "15")
elseif("Clang" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
set(CXX_COMPILER_MIN_VERSION "15")
elseif("GNU" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
set(CXX_COMPILER_MIN_VERSION "11")
else()
message(
FATAL_ERROR
"Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}. Please use AppleClang, Clang, or GNU."
)
endif()
if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "${CXX_COMPILER_MIN_VERSION}")
message(
FATAL_ERROR
"${CMAKE_CXX_COMPILER_ID} version ${CMAKE_CXX_COMPILER_VERSION} is too low. Must be at \
least ${CXX_COMPILER_MIN_VERSION}."
)
endif()
endfunction()
2 changes: 1 addition & 1 deletion cmake/ystdlib-helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function(add_cpp_library)
)
endfunction()

# Adds a C++ 20 test executable named `unit-test-NAME` that will be built with `SOURCES` and linked
# Adds a C++20 test executable named `unit-test-NAME` that will be built with `SOURCES` and linked
# with `LINK_LIBRARIES`, in addition to Catch2.
#
# @param {string} NAME
Expand Down
2 changes: 0 additions & 2 deletions src/ystdlib/error_handling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ add_cpp_library(
NAMESPACE ystdlib
PUBLIC_HEADERS
ErrorCode.hpp
TraceableException.hpp
Result.hpp
utils.hpp
PUBLIC_LINK_LIBRARIES
Expand All @@ -30,7 +29,6 @@ if(ystdlib_ENABLE_TESTS)
SOURCES
test/test_ErrorCode.cpp
test/test_Result.cpp
test/test_TraceableException.cpp
test/types.cpp
UNIFIED_TEST_TARGET "${UNIFIED_UNIT_TEST_TARGET}"
)
Expand Down
78 changes: 0 additions & 78 deletions src/ystdlib/error_handling/TraceableException.hpp

This file was deleted.

67 changes: 0 additions & 67 deletions src/ystdlib/error_handling/test/test_TraceableException.cpp

This file was deleted.

Loading