| 1 |
# Copyright (c) Glyn Matthews 2012-2017. |
| 2 |
# Distributed under the Boost Software License, Version 1.0. |
| 3 |
# (See accompanying file LICENSE_1_0.txt or copy at |
| 4 |
# http://www.boost.org/LICENSE_1_0.txt) |
| 5 |
|
| 6 |
|
| 7 |
cmake_minimum_required(VERSION 3.13) |
| 8 |
project(Uri) |
| 9 |
|
| 10 |
option(Uri_BUILD_TESTS "Build the URI tests." ON) |
| 11 |
option(Uri_BUILD_DOCS "Build the URI documentation." ON) |
| 12 |
option(Uri_FULL_WARNINGS "Build the library with all warnings turned on." ON) |
| 13 |
option(Uri_WARNINGS_AS_ERRORS "Treat warnings as errors." ON) |
| 14 |
option(Uri_USE_STATIC_CRT "Use static C Runtime library (/MT or MTd)." ON) |
| 15 |
option(Uri_USE_LIBCXX "Use libc++ (only applies if compiler is clang)" OFF) |
| 16 |
|
| 17 |
find_package(Threads REQUIRED) |
| 18 |
|
| 19 |
set(CMAKE_VERBOSE_MAKEFILE true) |
| 20 |
|
| 21 |
message(STATUS "Configure compiler") |
| 22 |
message("Using ${CMAKE_CXX_COMPILER_ID}") |
| 23 |
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU) |
| 24 |
INCLUDE(CheckCXXCompilerFlag) |
| 25 |
CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD11) |
| 26 |
|
| 27 |
if (HAVE_STD11) |
| 28 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
| 29 |
else() |
| 30 |
message(FATAL_ERROR "No C++ 11 support (Compiler does not define -std=c++11).") |
| 31 |
endif() |
| 32 |
|
| 33 |
if (Uri_FULL_WARNINGS) |
| 34 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") |
| 35 |
endif() |
| 36 |
|
| 37 |
if (Uri_WARNINGS_AS_ERRORS) |
| 38 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-parentheses") |
| 39 |
endif() |
| 40 |
|
| 41 |
message("C++ Flags: ${CMAKE_CXX_FLAGS} link flags: ${CMAKE_CXX_LINK_FLAGS}") |
| 42 |
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES Clang) |
| 43 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
| 44 |
|
| 45 |
if (Uri_USE_LIBCXX) |
| 46 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") |
| 47 |
endif() |
| 48 |
|
| 49 |
if (Uri_FULL_WARNINGS) |
| 50 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") |
| 51 |
endif() |
| 52 |
|
| 53 |
if (Uri_WARNINGS_AS_ERRORS) |
| 54 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-parentheses") |
| 55 |
endif() |
| 56 |
|
| 57 |
message("C++ Flags: ${CMAKE_CXX_FLAGS} link flags: ${CMAKE_CXX_LINK_FLAGS}") |
| 58 |
endif() |
| 59 |
|
| 60 |
|
| 61 |
if (MSVC) |
| 62 |
if(DEFINED MSVC_VERSION AND MSVC_VERSION LESS 1900) |
| 63 |
message(FATAL_ERROR "Requires VS 2015 or later") |
| 64 |
endif() |
| 65 |
|
| 66 |
if (Uri_USE_STATIC_CRT) |
| 67 |
# Replace dynamic MSVCRT linker flags with static version. |
| 68 |
foreach(flag_var |
| 69 |
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE |
| 70 |
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) |
| 71 |
if(${flag_var} MATCHES "/MD") |
| 72 |
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") |
| 73 |
endif(${flag_var} MATCHES "/MD") |
| 74 |
endforeach(flag_var) |
| 75 |
endif(Uri_USE_STATIC_CRT) |
| 76 |
|
| 77 |
add_definitions(-D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE) |
| 78 |
endif(MSVC) |
| 79 |
|
| 80 |
include_directories(${Uri_SOURCE_DIR}/src ${Uri_SOURCE_DIR}/include) |
| 81 |
|
| 82 |
add_subdirectory(src) |
| 83 |
|
| 84 |
# Testing |
| 85 |
if (Uri_BUILD_TESTS) |
| 86 |
message(STATUS "Configuring tests") |
| 87 |
enable_testing() |
| 88 |
add_subdirectory(deps/googletest) |
| 89 |
add_subdirectory(test) |
| 90 |
endif() |
| 91 |
|
| 92 |
# Documentation |
| 93 |
if (Uri_BUILD_DOCS) |
| 94 |
message("Configuring documentation") |
| 95 |
find_package(Doxygen) |
| 96 |
if (DOXYGEN_FOUND) |
| 97 |
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) |
| 98 |
add_custom_target(doc |
| 99 |
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile |
| 100 |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 101 |
COMMENT "Generating API documentation with Doxygen" VERBATIM) |
| 102 |
endif() |
| 103 |
endif() |
| 104 |
|
| 105 |
install(DIRECTORY include DESTINATION ".") |