Skip to content

Commit 1b31578

Browse files
committed
tooling: Use CMake standard BUILD_TESTING variable
This is more portable than defining our own variable and is also directly supported by Conan. This simplifies our packages because they no longer have a `test` option.
1 parent f5ffe92 commit 1b31578

22 files changed

+49
-131
lines changed

conanfile.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ class Cloe(ConanFile):
1717
"with_engine": [True, False],
1818

1919
# Doesn't affect package ID:
20-
"test": [True, False],
2120
"pedantic": [True, False],
2221
}
2322
default_options = {
2423
"with_vtd": False,
2524
"with_engine": True,
2625

27-
"test": True,
2826
"pedantic": True,
2927

3028
"cloe-engine:server": True,
@@ -76,7 +74,6 @@ def _configure_cmake(self):
7674
return self._cmake
7775
self._cmake = CMake(self)
7876
self._cmake.definitions["CMAKE_EXPORT_COMPILE_COMMANDS"] = True
79-
self._cmake.definitions["BuildTests"] = self.options.test
8077
self._cmake.definitions["TargetLintingExtended"] = self.options.pedantic
8178
self._cmake.configure()
8279
return self._cmake
@@ -86,9 +83,8 @@ def build(self):
8683
if not self.in_local_cache:
8784
cmake = self._configure_cmake()
8885
cmake.build()
89-
if self.options.test:
90-
with tools.environment_append(RunEnvironment(self).vars):
91-
cmake.test()
86+
with tools.environment_append(RunEnvironment(self).vars):
87+
cmake.test()
9288

9389
def package(self):
9490
# This build is for a workspace build. See: conanws.yml
@@ -97,5 +93,4 @@ def package(self):
9793
cmake.install()
9894

9995
def package_id(self):
100-
del self.info.options.test
10196
del self.info.options.pedantic

engine/CMakeLists.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ set(target cloe-engine)
66
set(output cloe-engine)
77
set(libstack cloe-stack)
88

9-
option(BuildTests "Build tests?" ON)
109
option(WithServer "Enable integrated server component?" ON)
1110

1211
# Conan / Editor -----------------------------------------------------
1312
include(${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo.cmake)
1413
conan_basic_setup(TARGETS)
1514

1615
include(TargetLinting)
16+
include(CTest)
1717

1818
# Compiler definitions
1919
string(TIMESTAMP CLOE_ENGINE_TIMESTAMP "%Y-%m-%d")
@@ -41,9 +41,7 @@ target_link_libraries(${libstack}
4141
dl
4242
)
4343

44-
if(BuildTests)
45-
message(STATUS "-> Enable testing")
46-
enable_testing()
44+
if(BUILD_TESTING)
4745
include(GoogleTest)
4846

4947
set(test-libstack test-${libstack})

engine/conanfile.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@ class CloeEngine(ConanFile):
1818
# server dependencies are incompatible with your target system.
1919
"server": [True, False],
2020

21-
# Build and run unit tests.
22-
"test": [True, False],
23-
2421
# Make the compiler be strict and pedantic.
2522
# Disable if you upgrade compilers and run into new warnings preventing
2623
# the build from completing. May be removed in the future.
2724
"pedantic": [True, False],
2825
}
2926
default_options = {
3027
"server": True,
31-
"test": True,
3228
"pedantic": True,
3329

3430
"fable:allow_comments": True,
@@ -64,15 +60,13 @@ def requirements(self):
6460
self.requires("nlohmann_json/[~=3.10.5]", override=True)
6561

6662
def build_requirements(self):
67-
if self.options.test:
68-
self.build_requires("gtest/[~1.10]")
63+
self.test_requires("gtest/[~1.10]")
6964

7065
def _configure_cmake(self):
7166
if self._cmake:
7267
return self._cmake
7368
self._cmake = CMake(self)
7469
self._cmake.definitions["CMAKE_EXPORT_COMPILE_COMMANDS"] = True
75-
self._cmake.definitions["BuildTests"] = self.options.test
7670
self._cmake.definitions["WithServer"] = self.options.server
7771
self._cmake.definitions["TargetLintingExtended"] = self.options.pedantic
7872
self._cmake.definitions["CLOE_PROJECT_VERSION"] = self.version
@@ -82,17 +76,15 @@ def _configure_cmake(self):
8276
def build(self):
8377
cmake = self._configure_cmake()
8478
cmake.build()
85-
if self.options.test:
86-
with tools.environment_append(RunEnvironment(self).vars):
87-
cmake.test()
79+
with tools.environment_append(RunEnvironment(self).vars):
80+
cmake.test()
8881

8982
def package(self):
9083
cmake = self._configure_cmake()
9184
cmake.install()
9285

9386
def package_id(self):
9487
self.info.requires["boost"].full_package_mode()
95-
del self.info.options.test
9688
del self.info.options.pedantic
9789

9890
def package_info(self):

fable/CMakeLists.txt

+3-5
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ else()
4747
endif()
4848

4949
# Testing ------------------------------------------------------------
50-
option(BuildTests "Build tests?" ON)
51-
if(BuildTests)
52-
message(STATUS "-> Enable testing")
53-
enable_testing()
50+
include(CTest)
51+
if(BUILD_TESTING)
5452
include(GoogleTest)
5553

5654
add_executable(test-fable
@@ -79,7 +77,7 @@ if(BuildTests)
7977
gtest_add_tests(TARGET test-fable)
8078
endif()
8179

82-
option(BuildExamples "Build examples?" ${BuildTests})
80+
option(BuildExamples "Build examples?" ${BUILD_TESTING})
8381
if(BuildExamples)
8482
message(STATUS "-> Build examples")
8583
add_executable(example-contacts

fable/conanfile.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ class Fable(ConanFile):
1515
"allow_comments": [True, False],
1616
"shared": [True, False],
1717
"fPIC": [True, False],
18-
"test": [True, False],
1918
}
2019
default_options = {
2120
"allow_comments": True,
2221
"shared": False,
2322
"fPIC": True,
24-
"test": True,
2523
}
2624
generators = "cmake"
2725
no_copy_source = True
@@ -48,9 +46,8 @@ def set_version(self):
4846
self.version = git.run("describe --dirty=-dirty")[1:]
4947

5048
def build_requirements(self):
51-
if self.options.test:
52-
self.build_requires("gtest/[~=1.10]")
53-
self.build_requires("cli11/[~=2.1.2]")
49+
self.test_requires("gtest/[~=1.10]")
50+
self.test_requires("cli11/[~2.1.2]")
5451

5552
def _configure_cmake(self):
5653
if self._cmake:
@@ -59,24 +56,21 @@ def _configure_cmake(self):
5956
self._cmake.definitions["CMAKE_EXPORT_COMPILE_COMMANDS"] = True
6057
self._cmake.definitions["FABLE_VERSION"] = self.version
6158
self._cmake.definitions["AllowComments"] = self.options.allow_comments
62-
self._cmake.definitions["BuildTests"] = self.options.test
6359
self._cmake.configure()
6460
return self._cmake
6561

6662
def build(self):
6763
cmake = self._configure_cmake()
6864
cmake.build()
69-
if self.options.test:
70-
with tools.environment_append(RunEnvironment(self).vars):
71-
cmake.test()
65+
with tools.environment_append(RunEnvironment(self).vars):
66+
cmake.test()
7267

7368
def package(self):
7469
cmake = self._configure_cmake()
7570
cmake.install()
7671

7772
def package_id(self):
7873
self.info.requires["boost"].full_package_mode()
79-
del self.info.options.test
8074
del self.info.options.pedantic
8175

8276
def package_info(self):

models/CMakeLists.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ target_link_libraries(${target}
3939
)
4040

4141
# Testing -------------------------------------------------------------
42-
option(BuildTests "Build tests?" ON)
43-
if(BuildTests)
44-
message(STATUS "-> Enable testing")
45-
enable_testing()
42+
include(CTest)
43+
if(BUILD_TESTING)
4644
include(GoogleTest)
4745

4846
add_executable(test-models

models/conanfile.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ class CloeModels(ConanFile):
1414
options = {
1515
"shared": [True, False],
1616
"fPIC": [True, False],
17-
"test": [True, False],
1817
"pedantic": [True, False],
1918
}
2019
default_options = {
2120
"shared": False,
2221
"fPIC": True,
23-
"test": True,
2422
"pedantic": True,
2523
}
2624
generators = "cmake"
@@ -49,15 +47,13 @@ def requirements(self):
4947
self.requires(f"cloe-runtime/{self.version}@cloe/develop")
5048

5149
def build_requirements(self):
52-
if self.options.test:
53-
self.build_requires("gtest/[~1.10]")
50+
self.test_requires("gtest/[~1.10]")
5451

5552
def _configure_cmake(self):
5653
if self._cmake:
5754
return self._cmake
5855
self._cmake = CMake(self)
5956
self._cmake.definitions["CMAKE_EXPORT_COMPILE_COMMANDS"] = True
60-
self._cmake.definitions["BuildTests"] = self.options.test
6157
self._cmake.definitions["TargetLintingExtended"] = self.options.pedantic
6258
self._cmake.definitions["CLOE_PROJECT_VERSION"] = self.version
6359
self._cmake.configure()
@@ -66,17 +62,15 @@ def _configure_cmake(self):
6662
def build(self):
6763
cmake = self._configure_cmake()
6864
cmake.build()
69-
if self.options.test:
70-
with tools.environment_append(RunEnvironment(self).vars):
71-
cmake.test()
65+
with tools.environment_append(RunEnvironment(self).vars):
66+
cmake.test()
7267

7368
def package(self):
7469
cmake = self._configure_cmake()
7570
cmake.install()
7671

7772
def package_id(self):
7873
self.info.requires["boost"].full_package_mode()
79-
del self.info.options.test
8074
del self.info.options.pedantic
8175

8276
def package_info(self):

oak/CMakeLists.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ target_link_libraries(${target}
3434
)
3535

3636
# Testing ------------------------------------------------------------
37-
option(BuildTests "Build tests?" ON)
38-
if(BuildTests)
39-
message(STATUS "-> Enable testing")
40-
enable_testing()
37+
include(CTest)
38+
if(BUILD_TESTING)
4139
include(GoogleTest)
4240

4341
add_executable(test-oak

oak/conanfile.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ class CloeOak(ConanFile):
1414
options = {
1515
"shared": [True, False],
1616
"fPIC": [True, False],
17-
"test": [True, False],
1817
"pedantic": [True, False],
1918
}
2019
default_options = {
2120
"shared": False,
2221
"fPIC": True,
23-
"test": True,
2422
"pedantic": True,
2523
}
2624
generators = "cmake"
@@ -48,25 +46,22 @@ def requirements(self):
4846
self.requires(f"cloe-runtime/{self.version}@cloe/develop")
4947

5048
def build_requirements(self):
51-
if self.options.test:
52-
self.build_requires("gtest/[~1.10]")
49+
self.test_requires("gtest/[~1.10]")
5350

5451
def _configure_cmake(self):
5552
if self._cmake:
5653
return self._cmake
5754
self._cmake = CMake(self)
5855
self._cmake.definitions["CMAKE_EXPORT_COMPILE_COMMANDS"] = True
59-
self._cmake.definitions["BuildTests"] = self.options.test
6056
self._cmake.definitions["TargetLintingExtended"] = self.options.pedantic
6157
self._cmake.configure()
6258
return self._cmake
6359

6460
def build(self):
6561
cmake = self._configure_cmake()
6662
cmake.build()
67-
if self.options.test:
68-
with tools.environment_append(RunEnvironment(self).vars):
69-
cmake.test()
63+
with tools.environment_append(RunEnvironment(self).vars):
64+
cmake.test()
7065

7166
def package(self):
7267
cmake = self._configure_cmake()
@@ -80,5 +75,4 @@ def package_info(self):
8075

8176
def package_id(self):
8277
self.info.requires["boost"].full_package_mode()
83-
del self.info.options.test
8478
del self.info.options.pedantic

optional/vtd/CMakeLists.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ cloe_add_plugin(
4545
PYTHON_DRIVER module.py
4646
)
4747

48-
option(BuildTests "Build tests?" ON)
49-
if(BuildTests)
50-
message(STATUS "-> Enable testing")
51-
enable_testing()
48+
include(CTest)
49+
if(BUILD_TESTING)
5250
include(GoogleTest)
5351

5452
add_executable(test-vtd-binding

optional/vtd/conanfile.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ class CloeSimulatorVTD(ConanFile):
1515
license = "Apache-2.0"
1616
settings = "os", "compiler", "build_type", "arch"
1717
options = {
18-
"test": [True, False],
1918
"pedantic": [True, False],
2019
}
2120
default_options = {
22-
"test": True,
2321
"pedantic": True,
2422
}
2523
generators = "cmake"
@@ -61,8 +59,7 @@ def requirements(self):
6159
self.requires("incbin/cci.20211107", override=True),
6260

6361
def build_requirements(self):
64-
if self.options.test:
65-
self.build_requires("gtest/[~1.10]")
62+
self.test_requires("gtest/[~1.10]")
6663

6764
def _compress_and_remove(self, dir):
6865
if not dir.is_dir():
@@ -88,7 +85,6 @@ def _configure_cmake(self):
8885
return self._cmake
8986
self._cmake = CMake(self)
9087
self._cmake.definitions["CMAKE_EXPORT_COMPILE_COMMANDS"] = True
91-
self._cmake.definitions["BuildTests"] = self.options.test
9288
self._cmake.definitions["TargetLintingExtended"] = self.options.pedantic
9389
self._cmake.configure()
9490
return self._cmake
@@ -100,9 +96,8 @@ def configure(self):
10096
def build(self):
10197
cmake = self._configure_cmake()
10298
cmake.build()
103-
if self.options.test:
104-
with tools.environment_append(RunEnvironment(self).vars):
105-
cmake.test()
99+
with tools.environment_append(RunEnvironment(self).vars):
100+
cmake.test()
106101

107102
def package(self):
108103
cmake = self._configure_cmake()
@@ -127,5 +122,4 @@ def package_info(self):
127122
self.env_info.VTD_SETUP_DIR = f"{self.package_folder}/{self._setup_folder}"
128123

129124
def package_id(self):
130-
del self.info.options.test
131125
del self.info.options.pedantic

plugins/basic/CMakeLists.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ cloe_add_plugin(
1818
PROJECT_SOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"
1919
)
2020

21-
option(BuildTests "Build tests?" ON)
22-
if(BuildTests)
23-
message(STATUS "-> Enable testing")
24-
enable_testing()
21+
include(CTest)
22+
if(BUILD_TESTING)
2523
include(GoogleTest)
2624

2725
add_executable(test-basic-controller

0 commit comments

Comments
 (0)