aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/project/cmake/build.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2021-01-17 13:54:57 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2021-01-17 13:54:57 +0300
commitdd2c5b58c4fe77d7ce35f3abb6e1bb399560a2db (patch)
tree813808b873a5895d7f212f890c68ff14820dc591 /project/cmake/build.py
parentTravis/AppVeyor: pause (diff)
downloadcmake-common-dd2c5b58c4fe77d7ce35f3abb6e1bb399560a2db.tar.gz
cmake-common-dd2c5b58c4fe77d7ce35f3abb6e1bb399560a2db.zip
GIANT CLUSTERFUCK OF A COMMIT
OK, this is epic. I was basically just trying to a) support Clang and b) add more test coverage. _THREE MONTHS_ and a few hundred CI runs later, this is what I came up with. I don't know how it ended up being what it is, but here we go. Some highlights of the changes: 1) CI builds has been moved to GitHub Actions, 2) the entire notion of a toolchain has been reworked; it now supports Clang on all platforms. * .github: this directory contains the GitHub Actions workflow scripts/actions. In the process, I created like 6 external GitHub actions, but it's still pretty massive. An upside is that it covers much more platform/toolchain combinations _and_ check a lot of the expected post-conditions. TODO: .ci/Makefile is obsolete now, as well as .travis.yml and .appveyor.yml. * common.cmake: added Clang support. In the process, a great deal has been learned about how CMake works; in particular, static runtime support has been reworked to be more robust. * project: the entire notion of a "toolchain" has been reworked. Instead of a measly --mingw parameter, there's now a separate --toolset parameter, which allows you to choose between GCC, Clang, MSVC, etc. Both Boost and CMake build scripts were enhanced greatly to support Clang and other toolchains in a more robust way.
Diffstat (limited to 'project/cmake/build.py')
-rw-r--r--project/cmake/build.py53
1 files changed, 33 insertions, 20 deletions
diff --git a/project/cmake/build.py b/project/cmake/build.py
index e683eff..6bc7772 100644
--- a/project/cmake/build.py
+++ b/project/cmake/build.py
@@ -30,10 +30,13 @@ import tempfile
from project.cmake.toolchain import Toolchain
from project.configuration import Configuration
from project.platform import Platform
+from project.toolchain import ToolchainType
from project.utils import normalize_path, run, setup_logging
+DEFAULT_PLATFORM = Platform.native()
DEFAULT_CONFIGURATION = Configuration.DEBUG
+DEFAULT_TOOLSET = ToolchainType.AUTO
def run_cmake(cmake_args):
@@ -41,15 +44,18 @@ def run_cmake(cmake_args):
class GenerationPhase:
- def __init__(self, src_dir, build_dir, install_dir=None,
- platform=None, configuration=DEFAULT_CONFIGURATION,
- boost_dir=None, mingw=False, cmake_args=None):
+ def __init__(self, src_dir, build_dir, install_dir=None, platform=None,
+ configuration=None, boost_dir=None, toolset=None,
+ cmake_args=None):
src_dir = normalize_path(src_dir)
build_dir = normalize_path(build_dir)
if install_dir is not None:
install_dir = normalize_path(install_dir)
+ platform = platform or DEFAULT_PLATFORM
+ configuration = configuration or DEFAULT_CONFIGURATION
if boost_dir is not None:
boost_dir = normalize_path(boost_dir)
+ toolset = toolset or DEFAULT_TOOLSET
cmake_args = cmake_args or []
self.src_dir = src_dir
@@ -58,7 +64,7 @@ class GenerationPhase:
self.platform = platform
self.configuration = configuration
self.boost_dir = boost_dir
- self.mingw = mingw
+ self.toolset = toolset
self.cmake_args = cmake_args
def _cmake_args(self, toolchain):
@@ -87,44 +93,47 @@ class GenerationPhase:
platform = Platform.native()
return os.path.join(boost_dir, 'stage', str(platform), str(configuration), 'lib')
- def run(self):
- with Toolchain.detect(self.platform, self.build_dir, mingw=self.mingw) as toolchain:
- run_cmake(self._cmake_args(toolchain))
+ def run(self, toolchain):
+ run_cmake(self._cmake_args(toolchain))
class BuildPhase:
- def __init__(self, build_dir, install_dir=None,
- configuration=DEFAULT_CONFIGURATION):
+ def __init__(self, build_dir, install_dir=None, configuration=None):
build_dir = normalize_path(build_dir)
+ configuration = configuration or DEFAULT_CONFIGURATION
self.build_dir = build_dir
self.install_dir = install_dir
self.configuration = configuration
- def _cmake_args(self):
+ def _cmake_args(self, toolchain):
result = ['--build', self.build_dir]
result += ['--config', str(self.configuration)]
if self.install_dir is not None:
result += ['--target', 'install']
+ result += ['--'] + toolchain.get_build_args()
return result
- def run(self):
- run_cmake(self._cmake_args())
+ def run(self, toolchain):
+ run_cmake(self._cmake_args(toolchain))
class BuildParameters:
def __init__(self, src_dir, build_dir=None, install_dir=None,
- platform=None, configuration=DEFAULT_CONFIGURATION,
- boost_dir=None, mingw=False, cmake_args=None):
+ platform=None, configuration=None, boost_dir=None,
+ toolset=None, cmake_args=None):
src_dir = normalize_path(src_dir)
if build_dir is not None:
build_dir = normalize_path(build_dir)
if install_dir is not None:
install_dir = normalize_path(install_dir)
+ platform = platform or DEFAULT_PLATFORM
+ configuration = configuration or DEFAULT_CONFIGURATION
if boost_dir is not None:
boost_dir = normalize_path(boost_dir)
+ toolset = toolset or DEFAULT_TOOLSET
cmake_args = cmake_args or []
self.src_dir = src_dir
@@ -133,7 +142,7 @@ class BuildParameters:
self.platform = platform
self.configuration = configuration
self.boost_dir = boost_dir
- self.mingw = mingw
+ self.toolset = toolset
self.cmake_args = cmake_args
@staticmethod
@@ -158,17 +167,19 @@ class BuildParameters:
def build(params):
with params.create_build_dir() as build_dir:
+ toolchain = Toolchain.detect(params.toolset, params.platform, build_dir)
+
gen_phase = GenerationPhase(params.src_dir, build_dir,
install_dir=params.install_dir,
platform=params.platform,
configuration=params.configuration,
boost_dir=params.boost_dir,
- mingw=params.mingw,
+ toolset=params.toolset,
cmake_args=params.cmake_args)
- gen_phase.run()
+ gen_phase.run(toolchain)
build_phase = BuildPhase(build_dir, install_dir=params.install_dir,
configuration=params.configuration)
- build_phase.run()
+ build_phase.run(toolchain)
def _parse_args(argv=None):
@@ -201,8 +212,10 @@ def _parse_args(argv=None):
type=normalize_path,
help='set Boost directory path')
- parser.add_argument('--mingw', action='store_true',
- help='build using MinGW-w64')
+ toolset_options = '/'.join(map(str, ToolchainType.all()))
+ parser.add_argument('--toolset', metavar='TOOLSET',
+ type=ToolchainType.parse, default=ToolchainType.AUTO,
+ help=f'toolset to use ({toolset_options})')
parser.add_argument('src_dir', metavar='DIR',
type=normalize_path,