Skip to content

Commit 17e722a

Browse files
committed
Refactor CMakeLists
1 parent 967b09f commit 17e722a

File tree

5 files changed

+160
-117
lines changed

5 files changed

+160
-117
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ jobs:
954954
generator: ${{ matrix.generator }}
955955
generator-toolset: ${{ matrix.generator-toolset }}
956956
build-type: ${{ matrix.build-type }}
957+
build-target: tests
957958
run-tests: true
958959
install-prefix: .local
959960
cxxstd: ${{ matrix.latest-cxxstd }}
@@ -966,7 +967,6 @@ jobs:
966967
extra-args: |
967968
-D Boost_VERBOSE=ON
968969
-D BOOST_INCLUDE_LIBRARIES="${{ steps.patch.outputs.module }}"
969-
-D BOOST_HTTP_PROTO_BUILD_TESTS=ON
970970
export-compile-commands: ${{ matrix.time-trace }}
971971
package: false
972972
package-artifact: false
@@ -1033,18 +1033,18 @@ jobs:
10331033
with:
10341034
source-dir: boost-root/libs/${{ steps.patch.outputs.module }}
10351035
build-dir: __build_root_test__
1036+
build-target: tests
1037+
run-tests: true
10361038
generator: ${{ matrix.generator }}
10371039
generator-toolset: ${{ matrix.generator-toolset }}
10381040
build-type: ${{ matrix.build-type }}
1039-
run-tests: false
10401041
install: false
10411042
cxxstd: ${{ matrix.latest-cxxstd }}
10421043
cc: ${{ steps.setup-cpp.outputs.cc || matrix.cc }}
10431044
ccflags: ${{ matrix.ccflags }}
10441045
cxx: ${{ steps.setup-cpp.outputs.cxx || matrix.cxx }}
10451046
cxxflags: ${{ matrix.cxxflags }}
10461047
shared: ${{ matrix.shared }}
1047-
extra-args: -D Boost_VERBOSE=ON -D BUILD_TESTING=ON -D BOOST_SRC_DIR="../boost-root"
10481048
cmake-version: '>=3.15'
10491049
package: false
10501050
package-artifact: false

CMakeLists.txt

+145-102
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,178 @@
11
#
22
# 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
36
#
47
# Distributed under the Boost Software License, Version 1.0. (See accompanying
58
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
69
#
710
# Official repository: https://github.com/cppalliance/http_proto
811
#
912

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)
1219
set(BOOST_HTTP_PROTO_VERSION 1)
13-
if(BOOST_SUPERPROJECT_VERSION)
20+
if (BOOST_SUPERPROJECT_VERSION)
1421
set(BOOST_HTTP_PROTO_VERSION ${BOOST_SUPERPROJECT_VERSION})
15-
endif()
16-
22+
endif ()
1723
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)
2326
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})
2829

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})
4340

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()
5341

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")
7149

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 ()
78129

130+
#-------------------------------------------------
131+
#
132+
# Library
133+
#
134+
#-------------------------------------------------
79135
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)
81138
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include/boost PREFIX "" FILES ${BOOST_HTTP_PROTO_HEADERS})
82139
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})
86141
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>)
99147
target_compile_definitions(boost_http_proto PRIVATE BOOST_HTTP_PROTO_SOURCE)
100148

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)
108150

109151
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)
113153
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})
117155
add_library(Boost::http_proto_zlib ALIAS boost_http_proto_zlib)
118-
119156
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)
121158
target_compile_definitions(boost_http_proto_zlib PUBLIC BOOST_HTTP_PROTO_HAS_ZLIB)
122159
target_compile_definitions(boost_http_proto_zlib PRIVATE BOOST_HTTP_PROTO_ZLIB_SOURCE)
160+
endif ()
123161

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)
134168
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 ()

doc/mrdocs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ verbose: true
2525
multipage: true
2626
use-system-libc: true
2727

28-
cmake: '-D CMAKE_CXX_STANDARD=20 -D BUILD_TESTING=ON'
28+
cmake: '-DCMAKE_CXX_STANDARD=20 -DBOOST_HTTP_PROTO_BUILD_TESTS=OFF -DBOOST_HTTP_PROTO_BUILD_EXAMPLES=OFF'

test/limits/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ target_link_libraries(boost_http_proto_limits PRIVATE
3232
Boost::utility)
3333

3434
target_link_libraries(boost_http_proto_limits INTERFACE Boost::http_proto)
35+
3536
if (ZLIB_FOUND)
3637
target_link_libraries(boost_http_proto_limits INTERFACE ZLIB::ZLIB)
3738
endif()
39+
3840
add_test(NAME boost_http_proto_limits COMMAND boost_http_proto_limits)
41+
add_dependencies(tests boost_http_proto_limits)

test/unit/CMakeLists.txt

+8-11
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,17 @@ list(APPEND PFILES
2020
Jamfile
2121
)
2222

23-
set(UNIT_TEST_LINK_LIBRARIES boost_http_proto)
24-
if (ZLIB_FOUND)
25-
set(UNIT_TEST_LINK_LIBRARIES ${UNIT_TEST_LINK_LIBRARIES} boost_http_proto_zlib)
26-
endif()
27-
2823
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES ${PFILES})
2924
source_group("_extra" FILES ${EXTRAFILES})
3025
add_executable(boost_http_proto_tests ${PFILES} ${EXTRAFILES})
3126
target_include_directories(boost_http_proto_tests PRIVATE . ../../../url/extra)
32-
target_link_libraries(
33-
boost_http_proto_tests PRIVATE
34-
${UNIT_TEST_LINK_LIBRARIES}
35-
Boost::filesystem)
27+
target_link_libraries(boost_http_proto_tests PRIVATE Boost::filesystem)
28+
3629
if (ZLIB_FOUND)
37-
target_link_libraries(boost_http_proto_tests PRIVATE ZLIB::ZLIB)
38-
endif()
30+
target_link_libraries(boost_http_proto_tests PRIVATE boost_http_proto_zlib ZLIB::ZLIB)
31+
else ()
32+
target_link_libraries(boost_http_proto_tests PRIVATE boost_http_proto)
33+
endif ()
34+
3935
add_test(NAME boost_http_proto_tests COMMAND boost_http_proto_tests)
36+
add_dependencies(tests boost_http_proto_tests)

0 commit comments

Comments
 (0)