Skip to content

Commit ef48e48

Browse files
committed
cmake: fix test and examples options
1 parent e0ead3b commit ef48e48

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

CMakeLists.txt

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,35 @@ set(__ignore__ ${CMAKE_C_COMPILER})
3737
# Options
3838
#
3939
#-------------------------------------------------
40-
option(BOOST_OPENMETHOD_BUILD_TESTS "Build boost::openmethod tests even if BUILD_TESTING is OFF" OFF)
41-
option(BOOST_OPENMETHOD_BUILD_EXAMPLES "Build boost::openmethod examples" ${BOOST_OPENMETHOD_IS_ROOT})
42-
option(BOOST_OPENMETHOD_MRDOCS_BUILD "Build the target for MrDocs: see mrdocs.yml" OFF)
43-
option(BOOST_OPENMETHOD_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
40+
41+
option(
42+
BOOST_OPENMETHOD_BUILD_TESTS
43+
"Build boost::openmethod tests even if BUILD_TESTING is OFF"
44+
${BOOST_OPENMETHOD_IS_ROOT})
45+
46+
if (BUILD_TESTING)
47+
set(BOOST_OPENMETHOD_BUILD_TESTS ON)
48+
endif ()
49+
50+
option(
51+
BOOST_OPENMETHOD_BUILD_EXAMPLES
52+
"Build boost::openmethod examples"
53+
${BOOST_OPENMETHOD_IS_ROOT})
54+
option(
55+
BOOST_OPENMETHOD_MRDOCS_BUILD
56+
"Build the target for MrDocs: see mrdocs.yml"
57+
OFF)
58+
option(
59+
BOOST_OPENMETHOD_WARNINGS_AS_ERRORS
60+
"Treat warnings as errors"
61+
OFF)
62+
63+
if (BOOST_OPENMETHOD_BUILD_EXAMPLES AND NOT BOOST_OPENMETHOD_BUILD_TESTS)
64+
message(
65+
WARNING
66+
"BOOST_OPENMETHOD_BUILD_EXAMPLES requires BOOST_OPENMETHOD_BUILD_TESTS. Examples will not be built.")
67+
set(BOOST_OPENMETHOD_BUILD_EXAMPLES OFF)
68+
endif()
4469

4570
# Check if environment variable BOOST_SRC_DIR is set
4671
if (NOT DEFINED BOOST_SRC_DIR AND DEFINED ENV{BOOST_SRC_DIR})
@@ -77,9 +102,9 @@ endforeach ()
77102
if (NOT BOOST_OPENMETHOD_MRDOCS_BUILD)
78103
if (BUILD_TESTING OR BOOST_OPENMETHOD_BUILD_TESTS)
79104
set(BOOST_OPENMETHOD_UNIT_TEST_LIBRARIES test)
80-
endif()
81-
if (BOOST_OPENMETHOD_BUILD_EXAMPLES)
82-
set(BOOST_OPENMETHOD_EXAMPLE_LIBRARIES dll)
105+
if (BOOST_OPENMETHOD_BUILD_EXAMPLES)
106+
set(BOOST_OPENMETHOD_EXAMPLE_LIBRARIES dll)
107+
endif()
83108
endif()
84109
endif()
85110
# Complete dependency list
@@ -175,20 +200,15 @@ endif()
175200
# Tests
176201
#
177202
#-------------------------------------------------
178-
if (BUILD_TESTING OR BOOST_OPENMETHOD_BUILD_TESTS)
203+
if (BOOST_OPENMETHOD_BUILD_TESTS)
179204
enable_testing()
180205
add_subdirectory(test)
181206
if (BOOST_OPENMETHOD_IS_ROOT)
182207
add_custom_target(all_with_tests ALL DEPENDS tests)
183208
endif()
184-
endif ()
185209

186-
#-------------------------------------------------
187-
#
188-
# Examples
189-
#
190-
#-------------------------------------------------
191-
if (BOOST_OPENMETHOD_BUILD_EXAMPLES)
192-
enable_testing()
193-
add_subdirectory(doc/modules/ROOT/examples)
210+
# Examples
211+
if (BOOST_OPENMETHOD_BUILD_EXAMPLES)
212+
add_subdirectory(doc/modules/ROOT/examples)
213+
endif ()
194214
endif ()

0 commit comments

Comments
 (0)