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+ #-------------------------------------------------
617cmake_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)
1023set (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} )
2336option (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
7071if (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 ()
7978endif ()
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 ()
0 commit comments