Skip to content

Commit

Permalink
Clean up repo, use CPM for dependency management
Browse files Browse the repository at this point in the history
- Update CMake version to 3.21
- Make this repo able to be pulled in as a dependency via CMake
- Use new compiler and environment detection (from range-v3)
- Use CPM for dependencies
- Fix Github actions to work on Clang 10,11,12,14
  • Loading branch information
maztheman authored and MazTheMan committed Dec 7, 2023
1 parent ecdb4eb commit e2e2f8d
Show file tree
Hide file tree
Showing 11 changed files with 363 additions and 47 deletions.
61 changes: 43 additions & 18 deletions .github/workflows/skyr-url-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: skyr-url CI
on: [ push, pull_request ]

env:
CMAKE_VERSION: 3.18.6
CMAKE_VERSION: 3.21.7
NINJA_VERSION: 1.11.0

jobs:
Expand Down Expand Up @@ -80,14 +80,14 @@ jobs:
# Clang-10
- {
name: "Linux Clang 10 Debug (C++20)", artifact: "Linux.tar.xz",
os: ubuntu-latest,
os: ubuntu-20.04,
build_type: Debug,
cc: "clang-10", cxx: "clang++-10",
cxx_standard: 20
}
- {
name: "Linux Clang 10 Release (C++20)", artifact: "Linux.tar.xz",
os: ubuntu-latest,
os: ubuntu-20.04,
build_type: RelWithDebInfo,
cc: "clang-10", cxx: "clang++-10",
cxx_standard: 20,
Expand All @@ -96,14 +96,14 @@ jobs:
# Clang-11
- {
name: "Linux Clang 11 Debug (C++20)", artifact: "Linux.tar.xz",
os: ubuntu-latest,
os: ubuntu-20.04,
build_type: Debug,
cc: "clang-11", cxx: "clang++-11",
cxx_standard: 20,
}
- {
name: "Linux Clang 11 Release (C++20)", artifact: "Linux.tar.xz",
os: ubuntu-latest,
os: ubuntu-20.04,
build_type: RelWithDebInfo,
cc: "clang-11", cxx: "clang++-11",
cxx_standard: 20,
Expand All @@ -112,14 +112,14 @@ jobs:
# Clang-12
- {
name: "Linux Clang 12 Debug (C++20)", artifact: "Linux.tar.xz",
os: ubuntu-latest,
os: ubuntu-20.04,
build_type: Debug,
cc: "clang-12", cxx: "clang++-12",
cxx_standard: 20,
}
- {
name: "Linux Clang 12 Release (C++20)", artifact: "Linux.tar.xz",
os: ubuntu-latest,
os: ubuntu-20.04,
build_type: RelWithDebInfo,
cc: "clang-12", cxx: "clang++-12",
cxx_standard: 20,
Expand Down Expand Up @@ -238,16 +238,16 @@ jobs:
if ("${{ runner.os }}" STREQUAL "Windows")
set(ninja_suffix "win.zip")
set(cmake_suffix "win64-x64.zip")
set(cmake_dir "cmake-${cmake_version}-win64-x64/bin")
set(cmake_suffix "windows-x86_64.zip")
set(cmake_dir "cmake-${cmake_version}-windows-x86_64/bin")
elseif ("${{ runner.os }}" STREQUAL "Linux")
set(ninja_suffix "linux.zip")
set(cmake_suffix "Linux-x86_64.tar.gz")
set(cmake_dir "cmake-${cmake_version}-Linux-x86_64/bin")
set(cmake_suffix "linux-x86_64.tar.gz")
set(cmake_dir "cmake-${cmake_version}-linux-x86_64/bin")
elseif ("${{ runner.os }}" STREQUAL "macOS")
set(ninja_suffix "mac.zip")
set(cmake_suffix "Darwin-x86_64.tar.gz")
set(cmake_dir "cmake-${cmake_version}-Darwin-x86_64/CMake.app/Contents/bin")
set(cmake_suffix "macos10.10-universal.tar.gz")
set(cmake_dir "cmake-${cmake_version}-macos10.10-universal/CMake.app/Contents/bin")
endif()
set(ninja_url "https://github.com/ninja-build/ninja/releases/download/v${ninja_version}/ninja-${ninja_suffix}")
Expand All @@ -267,6 +267,7 @@ jobs:
COMMAND chmod +x ${cmake_dir}/cmake
)
- name: Install GCC 7
id: install_gcc_7
if: startsWith(matrix.config.os, 'ubuntu') && ( matrix.config.cxx == 'g++-7' )
Expand Down Expand Up @@ -331,6 +332,7 @@ jobs:
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 11
sudo apt-get install -y libc++-11-dev libc++abi-11-dev
- name: Install Clang 12
id: install_clang_12
Expand All @@ -341,6 +343,7 @@ jobs:
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 12
sudo apt-get install -y libc++-12-dev libc++abi-12-dev libunwind-12-dev
- name: Install Clang 14
id: install_clang_14
Expand All @@ -365,7 +368,7 @@ jobs:
git checkout -b master origin/master
export
./bootstrap-vcpkg.sh
./vcpkg install tl-expected range-v3 catch2 nlohmann-json fmt
./vcpkg install fmt
- name: Install vcpkg (MacOS)
id: vcpkg_macos
Expand All @@ -381,7 +384,7 @@ jobs:
git checkout -b master origin/master
export
./bootstrap-vcpkg.sh
./vcpkg install tl-expected range-v3 catch2 nlohmann-json fmt
./vcpkg install fmt
- name: Install vcpkg (Windows)
id: vcpkg_windows
Expand All @@ -391,8 +394,8 @@ jobs:
git clone https://github.com/microsoft/vcpkg.git ${Env:GITHUB_WORKSPACE}\vcpkg
cd ${Env:GITHUB_WORKSPACE}\vcpkg
.\bootstrap-vcpkg.bat
vcpkg install tl-expected range-v3 catch2 nlohmann-json fmt --triplet x64-windows
vcpkg integrate install
vcpkg install fmt --triplet x64-windows
- name: Configure
shell: cmake -P {0}
Expand Down Expand Up @@ -440,6 +443,27 @@ jobs:
set(BUILD_V2 ON)
endif()
set(USE_LLVM OFF)
if("${{ matrix.config.name }}" STREQUAL "macOS Clang Debug (C++17)" OR
"${{ matrix.config.name }}" STREQUAL "macOS Clang Release (C++17)" OR
"${{ matrix.config.name }}" STREQUAL "macOS Clang Debug (C++20)" OR
"${{ matrix.config.name }}" STREQUAL "macOS Clang Release (C++20)" OR
"${{ matrix.config.name }}" STREQUAL "Linux Clang 11 Debug (C++17)" OR
"${{ matrix.config.name }}" STREQUAL "Linux Clang 11 Release (C++17)" OR
"${{ matrix.config.name }}" STREQUAL "Linux Clang 12 Debug (C++17)" OR
"${{ matrix.config.name }}" STREQUAL "Linux Clang 12 Release (C++17)" OR
"${{ matrix.config.name }}" STREQUAL "Linux Clang 14 Debug (C++17)" OR
"${{ matrix.config.name }}" STREQUAL "Linux Clang 14 Release (C++17)" OR
"${{ matrix.config.name }}" STREQUAL "Linux Clang 11 Debug (C++20)" OR
"${{ matrix.config.name }}" STREQUAL "Linux Clang 11 Release (C++20)" OR
"${{ matrix.config.name }}" STREQUAL "Linux Clang 12 Debug (C++20)" OR
"${{ matrix.config.name }}" STREQUAL "Linux Clang 12 Release (C++20)" OR
"${{ matrix.config.name }}" STREQUAL "Linux Clang 14 Debug (C++20)" OR
"${{ matrix.config.name }}" STREQUAL "Linux Clang 14 Release (C++20)"
)
set(USE_LLVM ON)
endif()
execute_process(
COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/cmake
-S .
Expand All @@ -451,8 +475,9 @@ jobs:
-D skyr_BUILD_DOCS=OFF
-D skyr_BUILD_EXAMPLES=OFF
-D skyr_BUILD_V2=${BUILD_V2}
-D skyr_BUILD_WITH_LLVM_LIBCXX=${USE_LLVM}
-D SKY_VERBOSE_BUILD=ON
-D CMAKE_BUILD_TYPE=${{ matrix.config.build_type }}
-D CMAKE_TOOLCHAIN_FILE=$ENV{GITHUB_WORKSPACE}/vcpkg/scripts/buildsystems/vcpkg.cmake
-D CMAKE_INSTALL_PREFIX=$ENV{GITHUB_WORKSPACE}/install
RESULT_VARIABLE result
)
Expand Down
65 changes: 44 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@
# http://www.boost.org/LICENSE_1_0.txt)


cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.21)

get_directory_property(skyr_is_subproject PARENT_DIRECTORY)

if(NOT skyr_is_subproject)
set(skyr_IS_TOP_LEVEL_PROJECT YES)
else()
set(skyr_IS_TOP_LEVEL_PROJECT NO)
endif()

project(
skyr-url
VERSION 2.0.0
VERSION 2.0.1
HOMEPAGE_URL https://cpp-netlib.github.io/url
DESCRIPTION "A C++ library that implements the WhatWG URL specification"
LANGUAGES CXX
)

if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(skyr_IS_TOP_LEVEL_PROJECT YES)
else()
set(skyr_IS_TOP_LEVEL_PROJECT NO)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

option(skyr_BUILD_TESTS "Build the URL tests." ON)
option(skyr_BUILD_DOCS "Build the URL documentation." OFF)
Expand All @@ -35,23 +39,41 @@ option(skyr_BUILD_V1 "Build v1" ON)
option(skyr_BUILD_V2 "Build v2, which uses C++20 features" OFF)

if (skyr_IS_TOP_LEVEL_PROJECT)
set(CMAKE_VERBOSE_MAKEFILE true)
set(CMAKE_CXX_STANDARD 17)
if (skyr_BUILD_V2)
if(skyr_BUILD_V2)
set(CMAKE_CXX_STANDARD 20)
else()
set(CMAKE_CXX_STANDARD 17)
endif()

set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

find_package(tl-expected CONFIG REQUIRED)
find_package(range-v3 CONFIG REQUIRED)
include(skyr-url-options)
include(skyr-url-env)
include(skyr-url-flags)

include(cmake/CPM.cmake)
CPMAddPackage(
NAME expected
GITHUB_REPOSITORY TartanLlama/expected
GIT_TAG v1.1.0
OPTIONS "EXPECTED_BUILD_TESTS OFF" #pulls is super old catch2
)
CPMAddPackage("gh:ericniebler/range-v3#0.12.0")
CPMAddPackage("gh:fmtlib/fmt#10.1.1")


if (skyr_ENABLE_JSON_FUNCTIONS)
find_package(nlohmann_json CONFIG REQUIRED)
CPMAddPackage(
NAME json
GITHUB_REPOSITORY nlohmann/json
GIT_TAG v3.11.3
OPTIONS "JSON_Install ON"
)
endif()

if (skyr_USE_STATIC_CRT AND ${CMAKE_CXX_COMPILER_ID} MATCHES MSVC)
if (skyr_USE_STATIC_CRT AND (SKY_CXX_COMPILER_CLANGCL OR SKY_CXX_COMPILER_MSVC))
include(${PROJECT_SOURCE_DIR}/cmake/skyr-url-functions.cmake)
skyr_replace_dynamic_msvcrt_linker_flags()
endif()
Expand All @@ -61,30 +83,31 @@ set(warnings_as_errors $<BOOL:${skyr_WARNINGS_AS_ERRORS}>)
set(no_exceptions $<BOOL:${skyr_BUILD_WITHOUT_EXCEPTIONS}>)
set(no_rtti $<BOOL:${skyr_BUILD_WITHOUT_RTTI}>)

set(gnu $<CXX_COMPILER_ID:GNU>)
set(clang $<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>)
set(gnu $<BOOL:${SKY_CXX_COMPILER_GCC}>)
set(clang $<BOOL:${SKY_CXX_COMPILER_CLANG}>)
set(libcxx $<AND:${clang},$<BOOL:${skyr_BUILD_WITH_LLVM_LIBCXX}>>)
set(clang_with_gnu_stdlib $<AND:$<CXX_COMPILER_ID:Clang>,$<NOT:$<BOOL:${WIN32}>>,$<NOT:$<BOOL:${skyr_BUILD_WITH_LLVM_LIBCXX}>>>)
set(msvc $<CXX_COMPILER_ID:MSVC>)
set(clang_with_gnu_stdlib $<AND:${clang},$<NOT:$<BOOL:${skyr_BUILD_WITH_LLVM_LIBCXX}>>>)
set(msvc $<BOOL:${SKY_CXX_COMPILER_MSVC}>)

add_subdirectory(src)

# Testing
if (skyr_BUILD_TESTS)
message(STATUS "Configuring tests")
message(STATUS "[skyr-url] Configuring tests")
CPMAddPackage("gh:catchorg/[email protected]")
enable_testing()
add_subdirectory(tests)
endif()

# Documentation
if (skyr_BUILD_DOCS)
message(STATUS "Configuring documentation")
message(STATUS "[skyr-url] Configuring documentation")
add_subdirectory(docs)
endif()

# Examples
if (skyr_BUILD_EXAMPLES)
message(STATUS "Configuring examples")
message(STATUS "[skyr-url] Configuring examples")
add_subdirectory(examples)
endif()

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![GitHub Actions Status](
https://github.com/cpp-netlib/url/workflows/skyr-url%20CI/badge.svg?branch=main)](
https://github.com/cpp-netlib/url/actions?query=workflow%3A%22skyr-url+CI%22)

## Notice

I've changed the name of the default branch from `master` to `main`. Please make future
Expand Down
24 changes: 24 additions & 0 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.38.7)
set(CPM_HASH_SUM "83e5eb71b2bbb8b1f2ad38f1950287a057624e385c238f6087f94cdfc44af9c5")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)

include(${CPM_DOWNLOAD_LOCATION})
Loading

0 comments on commit e2e2f8d

Please sign in to comment.