Skip to content

Commit f981d82

Browse files
committed
MDBF-143: prep - CMakeGenerator - add builddir
The builddir doesn't need to be the current dir. This adds builddir as an option with its default value of None meaning that the previous default behaviour is observed. builddir as chosen for consistency with the CompileCMake command and it looks a little out of place beside source_path in consistency of naming. Also source_path uses a CMake -S argument rather than just defaulting to this source_path value for additional clarity.
1 parent 5eb8019 commit f981d82

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

configuration/steps/generators/cmake/generator.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __init__(
2121
use_ccache: bool = False,
2222
compiler: CompilerCommand = None,
2323
source_path: str = ".",
24+
builddir: str = None,
2425
):
2526
"""
2627
Initializes the CMakeGenerator with an optional list of flags.
@@ -31,8 +32,12 @@ def __init__(
3132
compiler: An instance of CompilerCommand if you want to set it explicitly.
3233
source_path: The source path to the base CMakeLists.txt file.
3334
Default path is "in source build".
35+
builddir: The path of the build directory. Default is None.
3436
"""
35-
super().__init__(base_cmd=["cmake", source_path], flags=flags)
37+
base_command = ["cmake", "-S", source_path]
38+
if builddir:
39+
base_command += ["-B", builddir]
40+
super().__init__(base_cmd=base_command, flags=flags)
3641

3742
if use_ccache:
3843
self._use_ccache()

configuration/test/unit/test_cmake_generator.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def test_initialization_with_flags(self):
2828
command,
2929
[
3030
"cmake",
31+
"-S",
3132
".",
3233
"-DCMAKE_BUILD_TYPE=RelWithDebInfo",
3334
"-DCMAKE_INSTALL_PREFIX=/usr/local",
@@ -52,6 +53,7 @@ def test_append_flags_successful(self):
5253
command,
5354
[
5455
"cmake",
56+
"-S",
5557
".",
5658
"-DCMAKE_AR=ar",
5759
"-DCMAKE_LIBRARY_PATH=/usr/lib",
@@ -79,6 +81,7 @@ def test_set_compiler(self):
7981
command,
8082
[
8183
"cmake",
84+
"-S",
8285
".",
8386
"-DCMAKE_CXX_COMPILER=g++",
8487
"-DCMAKE_C_COMPILER=gcc",
@@ -95,6 +98,7 @@ def test_use_ccache(self):
9598
command,
9699
[
97100
"cmake",
101+
"-S",
98102
".",
99103
"-DCMAKE_CXX_COMPILER_LAUNCHER=ccache",
100104
"-DCMAKE_C_COMPILER_LAUNCHER=ccache",
@@ -108,7 +112,7 @@ def test_generate_with_no_flags(self):
108112
"""
109113
generator = CMakeGenerator(flags=[])
110114
command = generator.generate()
111-
self.assertEqual(command, ["cmake", "."])
115+
self.assertEqual(command, ["cmake", "-S", "."])
112116

113117
def test_set_build_config(self):
114118
"""
@@ -124,6 +128,7 @@ def test_set_build_config(self):
124128
command,
125129
[
126130
"cmake",
131+
"-S",
127132
".",
128133
"-DBUILD_CONFIG=mysql_release",
129134
],
@@ -158,6 +163,7 @@ def test_set_build_config_with_other_flags(self):
158163
command,
159164
[
160165
"cmake",
166+
"-S",
161167
".",
162168
"-DBUILD_CONFIG=mysql_release",
163169
"-DCMAKE_INSTALL_PREFIX=/usr/lib/test",

0 commit comments

Comments
 (0)