Skip to content

Commit b611a2b

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 6c53640 commit b611a2b

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_initialization_with_flags(self):
2828
command,
2929
[
3030
"cmake",
31-
".",
31+
"-S" ".",
3232
"-DCMAKE_BUILD_TYPE=RelWithDebInfo",
3333
"-DCMAKE_INSTALL_PREFIX=/usr/local",
3434
"-DPLUGIN_ARCHIVE=YES",
@@ -52,7 +52,7 @@ def test_append_flags_successful(self):
5252
command,
5353
[
5454
"cmake",
55-
".",
55+
"-S" ".",
5656
"-DCMAKE_AR=ar",
5757
"-DCMAKE_LIBRARY_PATH=/usr/lib",
5858
],
@@ -79,7 +79,7 @@ def test_set_compiler(self):
7979
command,
8080
[
8181
"cmake",
82-
".",
82+
"-S" ".",
8383
"-DCMAKE_CXX_COMPILER=g++",
8484
"-DCMAKE_C_COMPILER=gcc",
8585
],
@@ -95,7 +95,7 @@ def test_use_ccache(self):
9595
command,
9696
[
9797
"cmake",
98-
".",
98+
"-S" ".",
9999
"-DCMAKE_CXX_COMPILER_LAUNCHER=ccache",
100100
"-DCMAKE_C_COMPILER_LAUNCHER=ccache",
101101
],
@@ -108,7 +108,7 @@ def test_generate_with_no_flags(self):
108108
"""
109109
generator = CMakeGenerator(flags=[])
110110
command = generator.generate()
111-
self.assertEqual(command, ["cmake", "."])
111+
self.assertEqual(command, ["cmake", "-S", "."])
112112

113113
def test_set_build_config(self):
114114
"""
@@ -124,7 +124,7 @@ def test_set_build_config(self):
124124
command,
125125
[
126126
"cmake",
127-
".",
127+
"-S" ".",
128128
"-DBUILD_CONFIG=mysql_release",
129129
],
130130
)
@@ -158,7 +158,7 @@ def test_set_build_config_with_other_flags(self):
158158
command,
159159
[
160160
"cmake",
161-
".",
161+
"-S" ".",
162162
"-DBUILD_CONFIG=mysql_release",
163163
"-DCMAKE_INSTALL_PREFIX=/usr/lib/test",
164164
],

0 commit comments

Comments
 (0)