Skip to content
Open
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
116 changes: 61 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
# ----------------------------------------------------------------------------------------
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: Copyright (C) 2024 Fix8 Market Technologies Pty Ltd
# SPDX-FileType: SOURCE
#
# uri (header only)
# Copyright (C) 2024 Fix8 Market Technologies Pty Ltd
# by David L. Dight
# see https://github.com/fix8mt/uri
#
# Lightweight header-only C++20 URI parser
#
# Distributed under the Boost Software License, Version 1.0 August 17th, 2003
# Licensed under the MIT License <http://opensource.org/licenses/MIT>.
#
# Permission is hereby granted, free of charge, to any person or organization
# obtaining a copy of the software and accompanying documentation covered by
# this license (the "Software") to use, reproduce, display, distribute,
# execute, and transmit the Software, and to prepare derivative works of the
# Software, and to permit third-parties to whom the Software is furnished to
# do so, all subject to the following:
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is furnished
# to do so, subject to the following conditions:
#
# The copyright notices in the Software and this entire statement, including
# the above license grant, this restriction and the following disclaimer,
# must be included in all copies of the Software, in whole or in part, and
# all derivative works of the Software, unless such copies or derivative
# works are solely in the form of machine-executable object code generated by
# a source language processor.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
# SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
# FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# The above copyright notice and this permission notice (including the next paragraph)
# shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# ----------------------------------------------------------------------------------------
# cmake config
# clang
Expand All @@ -40,55 +36,65 @@
# min cmake version 3.20 (Mar 24, 2021)
# ----------------------------------------------------------------------------------------
cmake_minimum_required (VERSION 3.20)
project (uri
include(cmake/buildutils.cmake)
project(uri
LANGUAGES CXX
HOMEPAGE_URL https://github.com/fix8mt/uri
HOMEPAGE_URL https://github.com/fix8mt/${PROJECT_NAME}
DESCRIPTION "Lightweight header-only C++20 URI parser"
VERSION 1.3.1
VERSION 1.4.0
)
include(FetchContent)

# to disable building benchmarking tests:
# cmake -DBUILD_BENCHMARKS=false ..
option(BUILD_BENCHMARKS "enable building benchmarking tests" true)
message("-- Build benchmarking tests: ${BUILD_BENCHMARKS}")
if(BUILD_BENCHMARKS)
message(STATUS "Downloading Criterion...")
FetchContent_Declare(Criterion
GIT_REPOSITORY https://github.com/p-ranav/criterion.git
GIT_SHALLOW ON
)
FetchContent_MakeAvailable(Criterion)
endif()
fix8_setbuildtype(FIX8 Release)
fix8_addoption("BUILD_UNITTESTS|enable building unit tests|true")
fix8_addoption("BUILD_STATICTEST|enable building statictest|true")
fix8_addoption("BUILD_BENCHMARKS|enable building benchmarking|true")

message(STATUS "Downloading Catch2...")
FetchContent_Declare(Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_SHALLOW ON
GIT_TAG devel
)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
set(files uritest.cpp)

set(files uritest.cpp unittests.cpp)
if(BUILD_BENCHMARKS)
list(APPEND files benchmarks.cpp)
fix8_fetch(Criterion p-ranav/criterion master)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(Criterion INTERFACE -fbracket-depth=257)
endif()
endif()

if(BUILD_UNITTESTS)
list(APPEND files unittests.cpp)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
fix8_fetch(Catch2 catchorg/Catch2 devel)
endif()

if(BUILD_STATICTEST)
list(APPEND files statictest.cpp)
endif()

foreach(x IN LISTS files)
cmake_path(GET x STEM LAST_ONLY target)
add_executable(${target} examples/${x})
set_target_properties(${target} PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED true)
target_include_directories(${target} PRIVATE include examples)
target_link_libraries(${target} PRIVATE Catch2::Catch2WithMain)
if(BUILD_BENCHMARKS)
if(${target} STREQUAL benchmarks)
target_link_libraries(${target} PRIVATE Criterion)
endif()
cmake_path(GET x FILENAME fname)
if(${target} STREQUAL unittests)
target_link_libraries(${target} PRIVATE Catch2::Catch2WithMain)
include(Catch)
enable_testing()
catch_discover_tests(${target})
endif()
if(${target} STREQUAL statictest)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${target} PRIVATE -fconstexpr-ops-limit=50000000)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(${target} PRIVATE -fconstexpr-depth=50000000 -fconstexpr-steps=50000000)
endif()
endif()
get_target_property(cppstd ${target} CXX_STANDARD)
message("-- adding ${fname} cxx std: C++${cppstd}")
message("-- adding source ${x} (C++${cppstd}, ${CMAKE_CXX_COMPILER_ID})")
endforeach()

include(Catch)
enable_testing()
catch_discover_tests(unittests)
# make include visible to inheriting projects
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)

Loading