Skip to content

Commit c39a853

Browse files
committed
wip
1 parent 7670639 commit c39a853

File tree

3 files changed

+201
-66
lines changed

3 files changed

+201
-66
lines changed

CMakeLists.txt

Lines changed: 153 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,58 @@
1-
# Generated by `boostdep --cmake openmethod`
2-
# Copyright 2020, 2021 Peter Dimov
3-
# Distributed under the Boost Software License, Version 1.0.
4-
# https://www.boost.org/LICENSE_1_0.txt
1+
#
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+
#
6+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
7+
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8+
#
9+
# Official repository: https://github.com/boostorg/openmethod
10+
#
511

12+
#-------------------------------------------------
13+
#
14+
# Project
15+
#
16+
#-------------------------------------------------
617
cmake_minimum_required(VERSION 3.8...3.20)
7-
8-
project(boost_openmethod VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
9-
18+
set(BOOST_OPENMETHOD_VERSION 1)
19+
if (BOOST_SUPERPROJECT_VERSION)
20+
set(BOOST_OPENMETHOD_VERSION ${BOOST_SUPERPROJECT_VERSION})
21+
endif ()
22+
project(boost_openmethod VERSION "${BOOST_OPENMETHOD_VERSION}" LANGUAGES CXX)
1023
set(BOOST_OPENMETHOD_IS_ROOT OFF)
11-
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
24+
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
1225
set(BOOST_OPENMETHOD_IS_ROOT ON)
13-
endif()
14-
15-
if(NOT BOOST_SUPERPROJECT_VERSION)
16-
option(BOOST_OPENMETHOD_INSTALL "Install boost::openmethod files" ON)
17-
option(BOOST_OPENMETHOD_BUILD_TESTS "Build boost::openmethod tests" ${BUILD_TESTING})
18-
option(BOOST_OPENMETHOD_BUILD_EXAMPLES "Build boost::openmethod examples" ${BOOST_OPENMETHOD_IS_ROOT})
19-
else()
20-
set(BOOST_OPENMETHOD_BUILD_TESTS ${BUILD_TESTING})
21-
endif()
26+
endif ()
27+
#set(__ignore__ ${CMAKE_C_COMPILER})
2228

29+
#-------------------------------------------------
30+
#
31+
# Options
32+
#
33+
#-------------------------------------------------
34+
option(BOOST_OPENMETHOD_BUILD_TESTS "Build boost::openmethod tests even if BUILD_TESTING is OFF" OFF)
35+
option(BOOST_OPENMETHOD_BUILD_EXAMPLES "Build boost::openmethod examples" ${BOOST_OPENMETHOD_IS_ROOT})
2336
option(BOOST_OPENMETHOD_MRDOCS_BUILD "Build the target for MrDocs: see mrdocs.yml" OFF)
37+
option(BOOST_OPENMETHOD_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
2438

25-
if(BOOST_OPENMETHOD_IS_ROOT)
26-
#
27-
# Building inside Boost tree, but as a separate project e.g. on Travis or
28-
# other CI, or when producing Visual Studio Solution and Projects.
29-
30-
include(CTest)
31-
32-
set(
33-
BOOST_INCLUDE_LIBRARIES dynamic_bitset
34-
mp11
35-
preprocessor
36-
assert
37-
config
38-
core)
39-
set(BOOST_EXCLUDE_LIBRARIES openmethod)
40-
if (NOT BOOST_OPENMETHOD_MRDOCS_BUILD)
41-
list(APPEND BOOST_INCLUDE_LIBRARIES test)
42-
endif()
43-
if(BOOST_OPENMETHOD_BUILD_EXAMPLES)
44-
# list(APPEND BOOST_INCLUDE_LIBRARIES optional)
45-
endif()
39+
# Check if environment variable BOOST_SRC_DIR is set
40+
if (NOT DEFINED BOOST_SRC_DIR AND DEFINED ENV{BOOST_SRC_DIR})
41+
set(DEFAULT_BOOST_SRC_DIR "$ENV{BOOST_SRC_DIR}")
42+
else ()
43+
set(DEFAULT_BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..")
44+
endif ()
45+
set(BOOST_SRC_DIR ${DEFAULT_BOOST_SRC_DIR} CACHE STRING "Boost source dir to use when running CMake from this directory")
4646

47-
set(CMAKE_FOLDER _deps)
48-
add_subdirectory(../.. _deps/boost EXCLUDE_FROM_ALL)
49-
unset(CMAKE_FOLDER)
50-
endif()
51-
52-
add_library(boost_openmethod INTERFACE)
53-
add_library(Boost::openmethod ALIAS boost_openmethod)
47+
#-------------------------------------------------
48+
#
49+
# Boost modules
50+
#
51+
#-------------------------------------------------
52+
# The boost super-project requires one explicit dependency per-line.
5453

55-
target_compile_features(boost_openmethod INTERFACE cxx_std_17)
56-
57-
target_include_directories(boost_openmethod INTERFACE include)
58-
59-
target_link_libraries(
60-
boost_openmethod
61-
INTERFACE
54+
set(
55+
BOOST_OPENMETHOD_DEPENDENCIES
6256
Boost::assert
6357
Boost::config
6458
Boost::core
@@ -67,13 +61,114 @@ target_link_libraries(
6761
Boost::preprocessor
6862
)
6963

64+
65+
foreach (BOOST_OPENMETHOD_DEPENDENCY ${BOOST_OPENMETHOD_DEPENDENCIES})
66+
if (BOOST_OPENMETHOD_DEPENDENCY MATCHES "^[ ]*Boost::([A-Za-z0-9_]+)[ ]*$")
67+
list(APPEND BOOST_OPENMETHOD_INCLUDE_LIBRARIES ${CMAKE_MATCH_1})
68+
endif ()
69+
endforeach ()
70+
# Conditional dependencies
7071
if (NOT BOOST_OPENMETHOD_MRDOCS_BUILD)
71-
if(BOOST_OPENMETHOD_BUILD_TESTS)
72-
enable_testing()
73-
add_subdirectory(test)
72+
if (BUILD_TESTING OR BOOST_OPENMETHOD_BUILD_TESTS)
73+
set(BOOST_OPENMETHOD_UNIT_TEST_LIBRARIES unit_test_framework)
7474
endif()
75-
76-
if(BOOST_OPENMETHOD_BUILD_EXAMPLES)
77-
add_subdirectory(example)
75+
if (BOOST_OPENMETHOD_BUILD_EXAMPLES)
76+
#set(BOOST_OPENMETHOD_EXAMPLE_LIBRARIES json regex beast)
7877
endif()
7978
endif()
79+
# Complete dependency list
80+
set(BOOST_INCLUDE_LIBRARIES ${BOOST_OPENMETHOD_INCLUDE_LIBRARIES} ${BOOST_OPENMETHOD_UNIT_TEST_LIBRARIES} ${BOOST_OPENMETHOD_EXAMPLE_LIBRARIES})
81+
set(BOOST_EXCLUDE_LIBRARIES openmethod)
82+
83+
#-------------------------------------------------
84+
#
85+
# Add Boost Subdirectory
86+
#
87+
#-------------------------------------------------
88+
if (BOOST_OPENMETHOD_IS_ROOT)
89+
set(CMAKE_FOLDER Dependencies)
90+
# Find absolute BOOST_SRC_DIR
91+
if (NOT IS_ABSOLUTE ${BOOST_SRC_DIR})
92+
set(BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${BOOST_SRC_DIR}")
93+
endif ()
94+
95+
# Validate BOOST_SRC_DIR
96+
set(BOOST_SRC_DIR_IS_VALID ON)
97+
foreach (F "CMakeLists.txt" "Jamroot" "boost-build.jam" "bootstrap.sh" "libs")
98+
if (NOT EXISTS "${BOOST_SRC_DIR}/${F}")
99+
message(STATUS "${BOOST_SRC_DIR}/${F} does not exist. Fallback to find_package.")
100+
set(BOOST_SRC_DIR_IS_VALID OFF)
101+
break()
102+
endif ()
103+
endforeach ()
104+
105+
# Create Boost interface targets
106+
if (BOOST_SRC_DIR_IS_VALID)
107+
# From BOOST_SRC_DIR
108+
if (BUILD_SHARED_LIBS)
109+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
110+
endif()
111+
set(BOOST_EXCLUDE_LIBRARIES ${PROJECT_NAME})
112+
set(PREV_BUILD_TESTING ${BUILD_TESTING})
113+
set(BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE)
114+
add_subdirectory(${BOOST_SRC_DIR} Dependencies/boost EXCLUDE_FROM_ALL)
115+
set(BUILD_TESTING ${PREV_BUILD_TESTING} CACHE BOOL "Build the tests." FORCE)
116+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${BOOST_SRC_DIR}/tools/cmake/include")
117+
else ()
118+
# From Boost Package
119+
find_package(Boost REQUIRED COMPONENTS container)
120+
foreach (BOOST_INCLUDE_LIBRARY ${BOOST_INCLUDE_LIBRARIES})
121+
if (NOT TARGET Boost::${BOOST_INCLUDE_LIBRARY})
122+
add_library(Boost::${BOOST_INCLUDE_LIBRARY} ALIAS Boost::headers)
123+
endif ()
124+
endforeach ()
125+
endif ()
126+
unset(CMAKE_FOLDER)
127+
endif ()
128+
129+
#-------------------------------------------------
130+
#
131+
# Library
132+
#
133+
#-------------------------------------------------
134+
file(GLOB_RECURSE BOOST_OPENMETHOD_HEADERS CONFIGURE_DEPENDS include/boost/*.hpp)
135+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
136+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include/boost PREFIX "" FILES ${BOOST_OPENMETHOD_HEADERS})
137+
function(boost_openmethod_setup_properties target)
138+
add_library(${target} INTERFACE ${BOOST_OPENMETHOD_HEADERS})
139+
add_library(Boost::openmethod ALIAS boost_openmethod)
140+
target_include_directories(${target} INTERFACE "${PROJECT_SOURCE_DIR}/include")
141+
target_link_libraries(${target} INTERFACE ${BOOST_OPENMETHOD_DEPENDENCIES})
142+
endfunction()
143+
144+
boost_openmethod_setup_properties(boost_openmethod)
145+
146+
if (BOOST_OPENMETHOD_MRDOCS_BUILD)
147+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/mrdocs.cpp" "#include <boost/openmethod.hpp>\n")
148+
add_library(boost_openmethod_mrdocs "${CMAKE_CURRENT_BINARY_DIR}/mrdocs.cpp")
149+
boost_openmethod_setup_properties(boost_openmethod_mrdocs)
150+
target_compile_definitions(boost_openmethod_mrdocs PUBLIC BOOST_OPENMETHOD_MRDOCS)
151+
return()
152+
endif()
153+
154+
155+
#-------------------------------------------------
156+
#
157+
# Tests
158+
#
159+
#-------------------------------------------------
160+
if (BUILD_TESTING OR BOOST_OPENMETHOD_BUILD_TESTS)
161+
if (BOOST_OPENMETHOD_IS_ROOT)
162+
include(CTest)
163+
endif ()
164+
add_subdirectory(test)
165+
endif ()
166+
167+
#-------------------------------------------------
168+
#
169+
# Examples
170+
#
171+
#-------------------------------------------------
172+
if (BOOST_OPENMETHOD_BUILD_EXAMPLES)
173+
add_subdirectory(example)
174+
endif ()

doc/mrdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ multipage: true
6969
# requires the user to clearly specify the targets via the
7070
# compilation database.
7171
#
72-
# The BOOST_URL_MRDOCS_BUILD=ON is the only option we usually need
72+
# The BOOST_OPENMETHOD_MRDOCS_BUILD=ON is the only option we usually need
7373
# here.
7474
# The other options are set just to ensure other targets are
7575
# ignored even if these options are set as ON in the cache.

test/CMakeLists.txt

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
1-
# Copyright (c) 2018-2025 Jean-Louis Leroy
2-
# Distributed under the Boost Software License, Version 1.0.
3-
# See accompanying file LICENSE_1_0.txt
4-
# or copy at http://www.boost.org/LICENSE_1_0.txt)
1+
#
2+
# Copyright (c) 2019 Vinnie Falco ([email protected])
3+
# Copyright (c) 2021 DMitry Arkhipov ([email protected])
4+
#
5+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
6+
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7+
#
8+
# Official repository: https://github.com/boostorg/url
9+
#
510

11+
# Custom target used by the boost super-project
612
if(NOT TARGET tests)
7-
add_custom_target(tests ${EXCLUDE_TESTS_FROM_ALL})
8-
set_property(TARGET tests PROPERTY FOLDER _deps)
13+
add_custom_target(tests)
14+
set_property(TARGET tests PROPERTY FOLDER Dependencies)
15+
endif()
16+
17+
# Replicate error flags from Jamfile
18+
if (BOOST_OPENMETHOD_WARNINGS_AS_ERRORS)
19+
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
20+
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7)
21+
set(BOOST_OPENMETHOD_TEST_FLAGS "-Wall -Werror -Wno-unused-but-set-variable -Wno-maybe-uninitialized")
22+
else()
23+
set(BOOST_OPENMETHOD_TEST_FLAGS "-Wall -Werror -Wno-unused-but-set-variable")
24+
endif()
25+
elseif (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
26+
set(BOOST_OPENMETHOD_TEST_FLAGS "-Wall -Werror")
27+
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
28+
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13)
29+
set(BOOST_OPENMETHOD_TEST_FLAGS "-Wall -Werror -Wno-unused-but-set-variable")
30+
else()
31+
set(BOOST_OPENMETHOD_TEST_FLAGS "-Wall -Werror")
32+
endif()
33+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
34+
set(BOOST_OPENMETHOD_TEST_FLAGS "/W4 /WX /we4265 /wd4251")
35+
endif()
36+
37+
# Print test configuration if running in CI
38+
# This is useful for debugging CI failures related to warnings which might be false positives
39+
if (DEFINED ENV{CI})
40+
message(STATUS "Boost.OpenMethod Tests - Compiler ID: ${CMAKE_CXX_COMPILER_ID} / ${CMAKE_CXX_COMPILER_VERSION}")
41+
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT)
42+
message(STATUS "Boost.OpenMethod Tests - Compiler Frontend: ${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}")
43+
endif()
44+
message(STATUS "Boost.OpenMethod Tests - Platform: ${CMAKE_SYSTEM_NAME} / ${CMAKE_SYSTEM_VERSION}")
45+
message(STATUS "Boost.OpenMethod Tests - C++ standard: ${CMAKE_CXX_STANDARD}")
46+
message(STATUS "Boost.OpenMethod Tests - Test error flags: ${BOOST_OPENMETHOD_TEST_FLAGS}")
47+
endif()
948
endif()
1049

1150
file(GLOB test_cpp_files "test_*.cpp")
@@ -14,7 +53,8 @@ foreach(test_cpp ${test_cpp_files})
1453
cmake_path(REMOVE_EXTENSION test_cpp LAST_ONLY OUTPUT_VARIABLE test)
1554
string(REGEX REPLACE ".*/" "" test ${test})
1655
add_executable(${test} ${test_cpp})
17-
target_link_libraries(${test} Boost::openmethod Boost::unit_test_framework)
56+
target_link_libraries(${test} PUBLIC Boost::openmethod)
57+
target_link_libraries(${test} PUBLIC Boost::unit_test_framework)
1858
add_test(NAME ${test} COMMAND ${test})
1959
add_dependencies(tests ${test})
2060
endforeach()

0 commit comments

Comments
 (0)