From e2e2f8da8f3747b6ee11b799169edb79288ae741 Mon Sep 17 00:00:00 2001 From: maztheman Date: Wed, 6 Dec 2023 16:00:13 -0700 Subject: [PATCH] Clean up repo, use CPM for dependency management - 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 --- .github/workflows/skyr-url-ci.yml | 61 ++++++++++---- CMakeLists.txt | 65 ++++++++++----- README.md | 2 +- cmake/CPM.cmake | 24 ++++++ cmake/skyr-url-env.cmake | 95 +++++++++++++++++++++ cmake/skyr-url-flags.cmake | 133 ++++++++++++++++++++++++++++++ cmake/skyr-url-options.cmake | 20 +++++ src/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 2 + tests/v1/CMakeLists.txt | 3 - tests/v2/CMakeLists.txt | 3 - 11 files changed, 363 insertions(+), 47 deletions(-) create mode 100644 cmake/CPM.cmake create mode 100644 cmake/skyr-url-env.cmake create mode 100644 cmake/skyr-url-flags.cmake create mode 100644 cmake/skyr-url-options.cmake diff --git a/.github/workflows/skyr-url-ci.yml b/.github/workflows/skyr-url-ci.yml index 6c3ac01a..66b40d1d 100644 --- a/.github/workflows/skyr-url-ci.yml +++ b/.github/workflows/skyr-url-ci.yml @@ -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: @@ -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, @@ -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, @@ -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, @@ -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}") @@ -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' ) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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} @@ -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 . @@ -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 ) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5824259b..dc0d6435 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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() @@ -61,30 +83,31 @@ set(warnings_as_errors $) set(no_exceptions $) set(no_rtti $) -set(gnu $) -set(clang $,$>) +set(gnu $) +set(clang $) set(libcxx $>) -set(clang_with_gnu_stdlib $,$>,$>>) -set(msvc $) +set(clang_with_gnu_stdlib $>>) +set(msvc $) add_subdirectory(src) # Testing if (skyr_BUILD_TESTS) - message(STATUS "Configuring tests") + message(STATUS "[skyr-url] Configuring tests") + CPMAddPackage("gh:catchorg/Catch2@3.4.0") 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() diff --git a/README.md b/README.md index 1d79503a..df1dc018 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 00000000..cc25ec28 --- /dev/null +++ b/cmake/CPM.cmake @@ -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}) diff --git a/cmake/skyr-url-env.cmake b/cmake/skyr-url-env.cmake new file mode 100644 index 00000000..b32a6df2 --- /dev/null +++ b/cmake/skyr-url-env.cmake @@ -0,0 +1,95 @@ +# Copyright Gonzalo Brito Gadeschi 2015 +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +# +# Detects the C++ compiler, system, build-type, etc. +include(CheckCXXCompilerFlag) + +if("x${CMAKE_CXX_COMPILER_ID}" MATCHES "x.*Clang") + if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") + set (SKY_CXX_COMPILER_CLANGCL TRUE) + if (SKY_VERBOSE_BUILD) + message(STATUS "[skyr-url]: compiler is clang-cl.") + endif() + else() + set (SKY_CXX_COMPILER_CLANG TRUE) + if (SKY_VERBOSE_BUILD) + message(STATUS "[skyr-url]: compiler is clang.") + endif() + endif() +elseif(CMAKE_COMPILER_IS_GNUCXX) + set (SKY_CXX_COMPILER_GCC TRUE) + if (SKY_VERBOSE_BUILD) + message(STATUS "[skyr-url]: compiler is gcc.") + endif() +elseif("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC") + set (SKY_CXX_COMPILER_MSVC TRUE) + if (SKY_VERBOSE_BUILD) + message(STATUS "[skyr-url]: compiler is msvc.") + endif() +else() + message(WARNING "[skyr-url warning]: unknown compiler ${CMAKE_CXX_COMPILER_ID} !") +endif() + +if(CMAKE_SYSTEM_NAME MATCHES "Darwin") + set (SKY_ENV_MACOSX TRUE) + if (SKY_VERBOSE_BUILD) + message(STATUS "[skyr-url]: system is MacOSX.") + endif() +elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") + set (SKY_ENV_LINUX TRUE) + if (SKY_VERBOSE_BUILD) + message(STATUS "[skyr-url]: system is Linux.") + endif() +elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") + set (SKY_ENV_WINDOWS TRUE) + if (SKY_VERBOSE_BUILD) + message(STATUS "[skyr-url]: system is Windows.") + endif() +elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + set (SKY_ENV_FREEBSD TRUE) + if (SKY_VERBOSE_BUILD) + message(STATUS "[skyr-url]: system is FreeBSD.") + endif() +elseif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD") + set (SKY_ENV_OPENBSD TRUE) + if (SKY_VERBOSE_BUILD) + message(STATUS "[skyr-url]: system is OpenBSD.") + endif() +elseif(CMAKE_SYSTEM_NAME MATCHES "Emscripten") + set (SKY_ENV_EMSCRIPTEN TRUE) + if (SKY_VERBOSE_BUILD) + message(STATUS "[skyr-url]: system is Emscripten.") + endif() +else() + message(WARNING "[skyr-url warning]: unknown system ${CMAKE_SYSTEM_NAME} !") +endif() + +if(SKY_CXX_STD MATCHES "^[0-9]+$") + if(SKY_CXX_COMPILER_MSVC AND SKY_CXX_STD LESS 17) + # MSVC is currently supported only in 17+ mode + set(SKY_CXX_STD 17) + elseif(SKY_CXX_STD LESS 14) + set(SKY_CXX_STD 14) + endif() +endif() + +# Build type +set(SKY_DEBUG_BUILD FALSE) +set(SKY_RELEASE_BUILD FALSE) + +if (CMAKE_BUILD_TYPE MATCHES "^Debug$") + set(SKY_DEBUG_BUILD TRUE) + if (SKY_VERBOSE_BUILD) + message(STATUS "[skyr-url]: build type is debug.") + endif() +elseif(CMAKE_BUILD_TYPE MATCHES "^(Release|RelWithDebInfo|MinSizeRel)$") + set(SKY_RELEASE_BUILD TRUE) + if (SKY_VERBOSE_BUILD) + message(STATUS "[skyr-url]: build type is release.") + endif() +else() + message(WARNING "[skr-url warning]: unknown build type, defaults to release!") + set(CMAKE_BUILD_TYPE "Release") + set(SKY_RELEASE_BUILD TRUE) +endif() diff --git a/cmake/skyr-url-flags.cmake b/cmake/skyr-url-flags.cmake new file mode 100644 index 00000000..337d48a7 --- /dev/null +++ b/cmake/skyr-url-flags.cmake @@ -0,0 +1,133 @@ +# Copyright Louis Dionne 2015 +# Copyright Gonzalo Brito Gadeschi 2015 +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +# +# Setup compiler flags (more can be set on a per-target basis or in +# subdirectories) + +# Compilation flags +include(CheckCXXCompilerFlag) +macro(sky_append_flag testname flag) + # As -Wno-* flags do not lead to build failure when there are no other + # diagnostics, we check positive option to determine their applicability. + # Of course, we set the original flag that is requested in the parameters. + string(REGEX REPLACE "^-Wno-" "-W" alt ${flag}) + check_cxx_compiler_flag(${alt} ${testname}) + if (${testname}) + add_compile_options(${flag}) + endif() +endmacro() + +function(cxx_standard_normalize cxx_standard return_value) + if("x${cxx_standard}" STREQUAL "x1y") + set( ${return_value} "14" PARENT_SCOPE ) + elseif("x${cxx_standard}" STREQUAL "x1z") + set( ${return_value} "17" PARENT_SCOPE ) + elseif("x${cxx_standard}" STREQUAL "xlatest" OR "x${cxx_standard}" STREQUAL "x2a") + set( ${return_value} "20" PARENT_SCOPE ) + else() + set( ${return_value} "${cxx_standard}" PARENT_SCOPE ) + endif() +endfunction() + +function(cxx_standard_denormalize cxx_standard return_value) + if("x${cxx_standard}" STREQUAL "x17") + if (SKY_CXX_COMPILER_CLANGCL OR SKY_CXX_COMPILER_MSVC) + set( ${return_value} 17 PARENT_SCOPE ) + else() + set( ${return_value} 1z PARENT_SCOPE ) + endif() + elseif("x${cxx_standard}" STREQUAL "x20") + if (SKY_CXX_COMPILER_CLANGCL OR SKY_CXX_COMPILER_MSVC) + set( ${return_value} latest PARENT_SCOPE ) + else() + set( ${return_value} 2a PARENT_SCOPE ) + endif() + else() + set( ${return_value} ${cxx_standard} PARENT_SCOPE ) + endif() +endfunction() + +if(CMAKE_CXX_STANDARD) + if(NOT "x${SKY_CXX_STD}" STREQUAL "xdefault") + # Normalize RANGES_CXX_STD + cxx_standard_normalize( ${SKY_CXX_STD} sky_cxx_std ) + if(NOT "x${sky_cxx_std}" STREQUAL "x${CMAKE_CXX_STANDARD}") + message(FATAL_ERROR "[skyr-url]: Cannot specify both CMAKE_CXX_STANDARD and SKY_CXX_STD, or they must match.") + endif() + else() + cxx_standard_denormalize(${CMAKE_CXX_STANDARD} SKY_CXX_STD) + endif() +elseif("x${SKY_CXX_STD}" STREQUAL "xdefault") + if (SKY_CXX_COMPILER_CLANGCL OR SKY_CXX_COMPILER_MSVC) + set(SKY_CXX_STD 17) + else() + set(SKY_CXX_STD 14) + endif() +endif() + +# All compilation flags +# Language flag: version of the C++ standard to use +message(STATUS "[skyr-url]: C++ std=${SKY_CXX_STD}") +if (SKY_CXX_COMPILER_CLANGCL OR SKY_CXX_COMPILER_MSVC) + sky_append_flag(SKY_HAS_CXXSTDCOLON "/std:c++${SKY_CXX_STD}") + set(SKY_STD_FLAG "/std:c++${SKY_CXX_STD}") + if (SKY_CXX_COMPILER_CLANGCL) + # The MSVC STL before VS 2019v16.6 with Clang 10 requires -fms-compatibility in C++17 mode, and + # doesn't support C++20 mode at all. Let's drop this flag until AppVeyor updates to VS2016v16.6. + # sky_append_flag(SKY_HAS_FNO_MS_COMPATIBIILITY "-fno-ms-compatibility") + sky_append_flag(SKY_HAS_FNO_DELAYED_TEMPLATE_PARSING "-fno-delayed-template-parsing") + endif() + # Enable "normal" warnings and make them errors: + #sky_append_flag(SKY_HAS_W3 /W3) + #sky_append_flag(SKY_HAS_WX /WX) +else() + sky_append_flag(SKY_HAS_CXXSTD "-std=c++${SKY_CXX_STD}") + set(SKY_STD_FLAG "-std=c++${SKY_CXX_STD}") + # Enable "normal" warnings and make them errors: + #sky_append_flag(SKY_HAS_WALL -Wall) + #sky_append_flag(SKY_HAS_WEXTRA -Wextra) + if (SKY_ENABLE_WERROR) + sky_append_flag(SKY_HAS_WERROR -Werror) + endif() +endif() + +if (SKY_ENV_LINUX AND SKY_CXX_COMPILER_CLANG) + # On linux libc++ re-exports the system math headers. The ones from libstdc++ + # use the GCC __extern_always_inline intrinsic which is not supported by clang + # versions 3.6, 3.7, 3.8, 3.9, 4.0, and current trunk 5.0 (as of 2017.04.13). + # + # This works around it by replacing __extern_always_inline with inline using a + # macro: + sky_append_flag(SKY_HAS_D__EXTERN_ALWAYS_INLINE -D__extern_always_inline=inline) +endif() + +if(SKY_CXX_COMPILER_CLANG) + if (skyr_BUILD_WITH_LLVM_LIBCXX) + sky_append_flag(SKY_HAS_LLVM_LIBCXX "-stdlib=libc++") + else() + sky_append_flag(SKY_HAS_LIBSTDCXX "-stdlib=libstdc++") + endif() +endif() + +# Template diagnostic flags +sky_append_flag(SKY_HAS_FDIAGNOSTIC_SHOW_TEMPLATE_TREE -fdiagnostics-show-template-tree) +sky_append_flag(SKY_HAS_FTEMPLATE_BACKTRACE_LIMIT "-ftemplate-backtrace-limit=0") +sky_append_flag(SKY_HAS_FMACRO_BACKTRACE_LIMIT "-fmacro-backtrace-limit=1") + +if (SKY_VERBOSE_BUILD) + get_directory_property(RANGES_COMPILE_OPTIONS COMPILE_OPTIONS) + message(STATUS "[skyr-url]: C++ flags: ${CMAKE_CXX_FLAGS}") + message(STATUS "[skyr-url]: C++ debug flags: ${CMAKE_CXX_FLAGS_DEBUG}") + message(STATUS "[skyr-url]: C++ Release Flags: ${CMAKE_CXX_FLAGS_RELEASE}") + message(STATUS "[skyr-url]: C++ Compile Flags: ${CMAKE_CXX_COMPILE_FLAGS}") + message(STATUS "[skyr-url]: Compile options: ${RANGES_COMPILE_OPTIONS}") + message(STATUS "[skyr-url]: C Flags: ${CMAKE_C_FLAGS}") + message(STATUS "[skyr-url]: C Compile Flags: ${CMAKE_C_COMPILE_FLAGS}") + message(STATUS "[skyr-url]: EXE Linker flags: ${CMAKE_EXE_LINKER_FLAGS}") + message(STATUS "[skyr-url]: C++ Linker flags: ${CMAKE_CXX_LINK_FLAGS}") + message(STATUS "[skyr-url]: MODULE Linker flags: ${CMAKE_MODULE_LINKER_FLAGS}") + get_directory_property(CMakeCompDirDefs COMPILE_DEFINITIONS) + message(STATUS "[skyr-url]: Compile Definitions: ${CmakeCompDirDefs}") +endif() diff --git a/cmake/skyr-url-options.cmake b/cmake/skyr-url-options.cmake new file mode 100644 index 00000000..b06cb729 --- /dev/null +++ b/cmake/skyr-url-options.cmake @@ -0,0 +1,20 @@ +include(CMakeDependentOption) + +set(SKY_CXX_STD default CACHE STRING "C++ standard version.") +option(SKY_VERBOSE_BUILD "Enables debug output from CMake." OFF) + + +# Enable verbose configure when passing -Wdev to CMake +if (DEFINED CMAKE_SUPPRESS_DEVELOPER_WARNINGS AND + NOT CMAKE_SUPPRESS_DEVELOPER_WARNINGS) + set(SKY_VERBOSE_BUILD ON) +endif() + +if (SKY_VERBOSE_BUILD) + message(STATUS "[skyr-url]: verbose build enabled.") +endif() + +CMAKE_DEPENDENT_OPTION(SKYR_URL_INSTALL + "Generate an install target for skyr-url" + ON "${skyr_IS_TOP_LEVEL_PROJECT}" OFF) + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 84ba8a04..ee6cd3ac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,7 @@ # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -include(${PROJECT_SOURCE_DIR}/cmake/skyr-url-functions.cmake) +include(skyr-url-functions) configure_file( version.hpp.in diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 365c97dc..f542e2a9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,6 @@ function(skyr_create_test file_name output_dir test_name version) + CPMAddPackage("gh:fmtlib/fmt#10.1.1") + CPMAddPackage("gh:catchorg/Catch2@3.4.0") skyr_remove_extension(${file_name} base) set(test ${base}-${version}) add_executable(${test}) diff --git a/tests/v1/CMakeLists.txt b/tests/v1/CMakeLists.txt index f9587684..a4e59fa7 100644 --- a/tests/v1/CMakeLists.txt +++ b/tests/v1/CMakeLists.txt @@ -5,9 +5,6 @@ include(${PROJECT_SOURCE_DIR}/cmake/skyr-url-functions.cmake) -find_package(Catch2 CONFIG REQUIRED) -find_package(fmt CONFIG REQUIRED) - set(clang $,$>) set(libcxx $>) diff --git a/tests/v2/CMakeLists.txt b/tests/v2/CMakeLists.txt index ae41ccf7..66480497 100644 --- a/tests/v2/CMakeLists.txt +++ b/tests/v2/CMakeLists.txt @@ -5,9 +5,6 @@ include(${PROJECT_SOURCE_DIR}/cmake/skyr-url-functions.cmake) -find_package(Catch2 CONFIG REQUIRED) -find_package(fmt CONFIG REQUIRED) - set(clang $,$>) set(libcxx $>)