|
1 | 1 | # |
2 | 2 | # Copyright (c) 2019 Vinnie Falco ([email protected]) |
| 3 | +# Copyright (c) 2021 DMitry Arkhipov ([email protected]) |
| 4 | +# Copyright (c) 2022 Alan de Freitas ([email protected]) |
| 5 | +# Copyright (c) 2025 Mohammad Nejati |
3 | 6 | # |
4 | 7 | # Distributed under the Boost Software License, Version 1.0. (See accompanying |
5 | 8 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 | 9 | # |
7 | 10 | # Official repository: https://github.com/cppalliance/http_proto |
8 | 11 | # |
9 | 12 |
|
10 | | -cmake_minimum_required(VERSION 3.8...3.16) |
11 | | - |
| 13 | +#------------------------------------------------- |
| 14 | +# |
| 15 | +# Project |
| 16 | +# |
| 17 | +#------------------------------------------------- |
| 18 | +cmake_minimum_required(VERSION 3.8...3.20) |
12 | 19 | set(BOOST_HTTP_PROTO_VERSION 1) |
13 | | -if(BOOST_SUPERPROJECT_VERSION) |
| 20 | +if (BOOST_SUPERPROJECT_VERSION) |
14 | 21 | set(BOOST_HTTP_PROTO_VERSION ${BOOST_SUPERPROJECT_VERSION}) |
15 | | -endif() |
16 | | - |
| 22 | +endif () |
17 | 23 | project(boost_http_proto VERSION "${BOOST_HTTP_PROTO_VERSION}" LANGUAGES CXX) |
18 | | - |
19 | | -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
20 | | - include(CTest) |
21 | | - option(BOOST_HTTP_PROTO_INSTALL "Install boost::http_proto files" ON) |
22 | | - option(BOOST_HTTP_PROTO_BUILD_TESTS "Build boost::http_proto tests" ${BUILD_TESTING}) |
| 24 | +set(BOOST_HTTP_PROTO_IS_ROOT OFF) |
| 25 | +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
23 | 26 | set(BOOST_HTTP_PROTO_IS_ROOT ON) |
24 | | -else() |
25 | | - set(BOOST_HTTP_PROTO_BUILD_TESTS OFF CACHE BOOL "") |
26 | | - set(BOOST_HTTP_PROTO_IS_ROOT OFF) |
27 | | -endif() |
| 27 | +endif () |
| 28 | +set(__ignore__ ${CMAKE_C_COMPILER}) |
28 | 29 |
|
29 | | -include(GNUInstallDirs) |
30 | | -if(BOOST_HTTP_PROTO_IS_ROOT) |
31 | | - set(BOOST_INCLUDE_LIBRARIES http_proto buffers filesystem url) |
32 | | - set(BOOST_EXCLUDE_LIBRARIES http_proto) |
33 | | - set(CMAKE_FOLDER Dependencies) |
34 | | - add_subdirectory(../.. Dependencies/boost EXCLUDE_FROM_ALL) |
35 | | - unset(CMAKE_FOLDER) |
36 | | -endif() |
37 | | - |
38 | | -find_package(ZLIB) |
39 | | - |
40 | | -function(boost_http_proto_setup_properties target) |
41 | | - target_compile_features(${target} PUBLIC cxx_constexpr) |
42 | | - target_compile_definitions(${target} PUBLIC BOOST_HTTP_PROTO_NO_LIB=1) |
| 30 | +#------------------------------------------------- |
| 31 | +# |
| 32 | +# Options |
| 33 | +# |
| 34 | +#------------------------------------------------- |
| 35 | +if (BOOST_HTTP_PROTO_IS_ROOT) |
| 36 | + include(CTest) |
| 37 | +endif () |
| 38 | +option(BOOST_HTTP_PROTO_BUILD_TESTS "Build boost::http_proto tests" ${BUILD_TESTING}) |
| 39 | +option(BOOST_HTTP_PROTO_BUILD_EXAMPLES "Build boost::http_proto examples" ${BOOST_HTTP_PROTO_IS_ROOT}) |
43 | 40 |
|
44 | | - if(BOOST_SUPERPROJECT_VERSION) |
45 | | - target_include_directories(${target} PUBLIC "${PROJECT_SOURCE_DIR}/include") |
46 | | - else() |
47 | | - target_include_directories(${target} |
48 | | - PUBLIC |
49 | | - "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>" |
50 | | - "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" |
51 | | - ) |
52 | | - endif() |
53 | 41 |
|
54 | | - target_link_libraries(${target} |
55 | | - PUBLIC |
56 | | - Boost::align |
57 | | - Boost::assert |
58 | | - Boost::buffers |
59 | | - Boost::config |
60 | | - Boost::container_hash |
61 | | - Boost::system |
62 | | - Boost::throw_exception |
63 | | - Boost::url |
64 | | - Boost::utility |
65 | | - Boost::winapi |
66 | | - ) |
67 | | - if (ZLIB_FOUND) |
68 | | - target_compile_definitions(${target} PUBLIC BOOST_HTTP_PROTO_HAS_ZLIB) |
69 | | - endif() |
70 | | -endfunction() |
| 42 | +# Check if environment variable BOOST_SRC_DIR is set |
| 43 | +if (NOT DEFINED BOOST_SRC_DIR AND DEFINED ENV{BOOST_SRC_DIR}) |
| 44 | + set(DEFAULT_BOOST_SRC_DIR "$ENV{BOOST_SRC_DIR}") |
| 45 | +else () |
| 46 | + set(DEFAULT_BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..") |
| 47 | +endif () |
| 48 | +set(BOOST_SRC_DIR ${DEFAULT_BOOST_SRC_DIR} CACHE STRING "Boost source dir to use when running CMake from this directory") |
71 | 49 |
|
72 | | -file(GLOB_RECURSE BOOST_HTTP_PROTO_HEADERS CONFIGURE_DEPENDS |
73 | | - include/boost/*.hpp |
74 | | - include/boost/*.ipp |
75 | | - include/boost/*.natvis |
76 | | -) |
77 | | -file(GLOB_RECURSE BOOST_HTTP_PROTO_SOURCES CONFIGURE_DEPENDS src/*.cpp src/*.hpp) |
| 50 | +#------------------------------------------------- |
| 51 | +# |
| 52 | +# Boost modules |
| 53 | +# |
| 54 | +#------------------------------------------------- |
| 55 | +# The boost super-project requires one explicit dependency per-line. |
| 56 | +set(BOOST_HTTP_PROTO_DEPENDENCIES |
| 57 | + Boost::align |
| 58 | + Boost::assert |
| 59 | + Boost::buffers |
| 60 | + Boost::config |
| 61 | + Boost::container_hash |
| 62 | + Boost::system |
| 63 | + Boost::throw_exception |
| 64 | + Boost::url |
| 65 | + Boost::utility |
| 66 | + Boost::winapi) |
| 67 | + |
| 68 | +foreach (BOOST_HTTP_PROTO_DEPENDENCY ${BOOST_HTTP_PROTO_DEPENDENCIES}) |
| 69 | + if (BOOST_HTTP_PROTO_DEPENDENCY MATCHES "^[ ]*Boost::([A-Za-z0-9_]+)[ ]*$") |
| 70 | + list(APPEND BOOST_HTTP_PROTO_INCLUDE_LIBRARIES ${CMAKE_MATCH_1}) |
| 71 | + endif () |
| 72 | +endforeach () |
| 73 | +# Conditional dependencies |
| 74 | +if (BOOST_HTTP_PROTO_BUILD_TESTS) |
| 75 | + set(BOOST_HTTP_PROTO_UNIT_TEST_LIBRARIES filesystem) |
| 76 | +endif () |
| 77 | +if (BOOST_HTTP_PROTO_BUILD_EXAMPLES) |
| 78 | + # set(BOOST_HTTP_PROTO_EXAMPLE_LIBRARIES json) |
| 79 | +endif () |
| 80 | +# Complete dependency list |
| 81 | +set(BOOST_INCLUDE_LIBRARIES ${BOOST_HTTP_PROTO_INCLUDE_LIBRARIES} ${BOOST_HTTP_PROTO_UNIT_TEST_LIBRARIES} ${BOOST_HTTP_PROTO_EXAMPLE_LIBRARIES}) |
| 82 | +set(BOOST_EXCLUDE_LIBRARIES http_proto) |
| 83 | + |
| 84 | +#------------------------------------------------- |
| 85 | +# |
| 86 | +# Add Boost Subdirectory |
| 87 | +# |
| 88 | +#------------------------------------------------- |
| 89 | +if (BOOST_HTTP_PROTO_IS_ROOT) |
| 90 | + set(CMAKE_FOLDER Dependencies) |
| 91 | + # Find absolute BOOST_SRC_DIR |
| 92 | + if (NOT IS_ABSOLUTE ${BOOST_SRC_DIR}) |
| 93 | + set(BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${BOOST_SRC_DIR}") |
| 94 | + endif () |
| 95 | + |
| 96 | + # Validate BOOST_SRC_DIR |
| 97 | + set(BOOST_SRC_DIR_IS_VALID ON) |
| 98 | + foreach (F "CMakeLists.txt" "Jamroot" "boost-build.jam" "bootstrap.sh" "libs") |
| 99 | + if (NOT EXISTS "${BOOST_SRC_DIR}/${F}") |
| 100 | + message(STATUS "${BOOST_SRC_DIR}/${F} does not exist. Fallback to find_package.") |
| 101 | + set(BOOST_SRC_DIR_IS_VALID OFF) |
| 102 | + break() |
| 103 | + endif () |
| 104 | + endforeach () |
| 105 | + |
| 106 | + # Create Boost interface targets |
| 107 | + if (BOOST_SRC_DIR_IS_VALID) |
| 108 | + # From BOOST_SRC_DIR |
| 109 | + if (BUILD_SHARED_LIBS) |
| 110 | + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) |
| 111 | + endif () |
| 112 | + set(BOOST_EXCLUDE_LIBRARIES ${PROJECT_NAME}) |
| 113 | + set(PREV_BUILD_TESTING ${BUILD_TESTING}) |
| 114 | + set(BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE) |
| 115 | + add_subdirectory(${BOOST_SRC_DIR} Dependencies/boost EXCLUDE_FROM_ALL) |
| 116 | + set(BUILD_TESTING ${PREV_BUILD_TESTING} CACHE BOOL "Build the tests." FORCE) |
| 117 | + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${BOOST_SRC_DIR}/tools/cmake/include") |
| 118 | + else () |
| 119 | + # From Boost Package |
| 120 | + find_package(Boost REQUIRED COMPONENTS buffers filesystem url) |
| 121 | + foreach (BOOST_INCLUDE_LIBRARY ${BOOST_INCLUDE_LIBRARIES}) |
| 122 | + if (NOT TARGET Boost::${BOOST_INCLUDE_LIBRARY}) |
| 123 | + add_library(Boost::${BOOST_INCLUDE_LIBRARY} ALIAS Boost::headers) |
| 124 | + endif () |
| 125 | + endforeach () |
| 126 | + endif () |
| 127 | + unset(CMAKE_FOLDER) |
| 128 | +endif () |
78 | 129 |
|
| 130 | +#------------------------------------------------- |
| 131 | +# |
| 132 | +# Library |
| 133 | +# |
| 134 | +#------------------------------------------------- |
79 | 135 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
80 | | - |
| 136 | +file(GLOB_RECURSE BOOST_HTTP_PROTO_HEADERS CONFIGURE_DEPENDS include/boost/*.hpp include/boost/*.natvis) |
| 137 | +file(GLOB_RECURSE BOOST_HTTP_PROTO_SOURCES CONFIGURE_DEPENDS src/*.cpp src/*.hpp) |
81 | 138 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include/boost PREFIX "" FILES ${BOOST_HTTP_PROTO_HEADERS}) |
82 | 139 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src PREFIX "http_proto" FILES ${BOOST_HTTP_PROTO_SOURCES}) |
83 | | -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES Jamfile) |
84 | | - |
85 | | -add_library(boost_http_proto ${BOOST_HTTP_PROTO_HEADERS} ${BOOST_HTTP_PROTO_SOURCES} build/Jamfile) |
| 140 | +add_library(boost_http_proto ${BOOST_HTTP_PROTO_HEADERS} ${BOOST_HTTP_PROTO_SOURCES}) |
86 | 141 | add_library(Boost::http_proto ALIAS boost_http_proto) |
87 | | -boost_http_proto_setup_properties(boost_http_proto) |
88 | | - |
89 | | -target_compile_definitions(boost_http_proto |
90 | | - PUBLIC |
91 | | - BOOST_HTTP_PROTO_NO_LIB |
92 | | -) |
93 | | - |
94 | | -if(BUILD_SHARED_LIBS) |
95 | | - target_compile_definitions(boost_http_proto PUBLIC BOOST_HTTP_PROTO_DYN_LINK=1) |
96 | | -else() |
97 | | - target_compile_definitions(boost_http_proto PUBLIC BOOST_HTTP_PROTO_STATIC_LINK=1) |
98 | | -endif() |
| 142 | +target_compile_features(boost_http_proto PUBLIC cxx_constexpr) |
| 143 | +target_compile_definitions(boost_http_proto PUBLIC BOOST_HTTP_PROTO_NO_LIB=1) |
| 144 | +target_include_directories(boost_http_proto PUBLIC "${PROJECT_SOURCE_DIR}/include") |
| 145 | +target_link_libraries(boost_http_proto PUBLIC ${BOOST_HTTP_PROTO_DEPENDENCIES}) |
| 146 | +target_compile_definitions(boost_http_proto PUBLIC $<IF:$<BOOL:${BUILD_SHARED_LIBS}>,BOOST_HTTP_PROTO_DYN_LINK=1,BOOST_HTTP_PROTO_STATIC_LINK=1>) |
99 | 147 | target_compile_definitions(boost_http_proto PRIVATE BOOST_HTTP_PROTO_SOURCE) |
100 | 148 |
|
101 | | -if(BOOST_HTTP_PROTO_INSTALL AND NOT BOOST_SUPERPROJECT_VERSION) |
102 | | - install(TARGETS boost_http_proto |
103 | | - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" |
104 | | - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
105 | | - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
106 | | - ) |
107 | | -endif() |
| 149 | +find_package(ZLIB) |
108 | 150 |
|
109 | 151 | if (ZLIB_FOUND) |
110 | | - file(GLOB_RECURSE BOOST_HTTP_PROTO_ZLIB_SOURCES CONFIGURE_DEPENDS src_zlib/*.cpp) |
111 | | - |
112 | | - source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include/boost PREFIX "" FILES ${BOOST_HTTP_PROTO_HEADERS}) |
| 152 | + file(GLOB_RECURSE BOOST_HTTP_PROTO_ZLIB_SOURCES CONFIGURE_DEPENDS src_zlib/*.cpp src_zlib/*.hpp) |
113 | 153 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src_zlib PREFIX "http_proto" FILES ${BOOST_HTTP_PROTO_ZLIB_SOURCES}) |
114 | | - source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/build PREFIX "" FILES build/Jamfile) |
115 | | - |
116 | | - add_library(boost_http_proto_zlib ${BOOST_HTTP_PROTO_HEADERS} ${BOOST_HTTP_PROTO_ZLIB_SOURCES} build/Jamfile) |
| 154 | + add_library(boost_http_proto_zlib ${BOOST_HTTP_PROTO_HEADERS} ${BOOST_HTTP_PROTO_ZLIB_SOURCES}) |
117 | 155 | add_library(Boost::http_proto_zlib ALIAS boost_http_proto_zlib) |
118 | | - |
119 | 156 | target_link_libraries(boost_http_proto_zlib PUBLIC boost_http_proto) |
120 | | - target_link_libraries(boost_http_proto_zlib PUBLIC ZLIB::ZLIB) |
| 157 | + target_link_libraries(boost_http_proto_zlib PRIVATE ZLIB::ZLIB) |
121 | 158 | target_compile_definitions(boost_http_proto_zlib PUBLIC BOOST_HTTP_PROTO_HAS_ZLIB) |
122 | 159 | target_compile_definitions(boost_http_proto_zlib PRIVATE BOOST_HTTP_PROTO_ZLIB_SOURCE) |
| 160 | +endif () |
123 | 161 |
|
124 | | - if(BOOST_HTTP_PROTO_INSTALL AND NOT BOOST_SUPERPROJECT_VERSION) |
125 | | - install(TARGETS boost_http_proto_zlib |
126 | | - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" |
127 | | - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
128 | | - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
129 | | - ) |
130 | | - endif() |
131 | | -endif() |
132 | | - |
133 | | -if(BOOST_HTTP_PROTO_BUILD_TESTS) |
| 162 | +#------------------------------------------------- |
| 163 | +# |
| 164 | +# Tests |
| 165 | +# |
| 166 | +#------------------------------------------------- |
| 167 | +if (BOOST_HTTP_PROTO_BUILD_TESTS) |
134 | 168 | add_subdirectory(test) |
135 | | -endif() |
| 169 | +endif () |
| 170 | + |
| 171 | +#------------------------------------------------- |
| 172 | +# |
| 173 | +# Examples |
| 174 | +# |
| 175 | +#------------------------------------------------- |
| 176 | +if (BOOST_HTTP_PROTO_BUILD_EXAMPLES) |
| 177 | + # add_subdirectory(example) |
| 178 | +endif () |
0 commit comments