From dc0e9983abe969b32288b843e1366893641ded1b Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 30 Mar 2020 04:56:51 +0300 Subject: project.cmake: make it --boost aware --- .ci/Makefile | 25 +++++++++---------------- project/ci/appveyor/cmake.py | 3 +++ project/ci/travis/cmake.py | 3 +++ project/cmake/build.py | 31 +++++++++++++++++++++++++++++-- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/.ci/Makefile b/.ci/Makefile index ca41fef..8885f46 100644 --- a/.ci/Makefile +++ b/.ci/Makefile @@ -19,8 +19,7 @@ SHELL := bash .SHELLFLAGS := -eu -o pipefail -c endif -# Additional b2 flags: -b2_flags = +makefile_dir := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) # Basic stuff that needed to be abstracted away: ifeq ($(windows),1) @@ -46,15 +45,9 @@ else python := python3 endif -# The build scripts are not completely OS-agnostic, unfortunately: ifeq ($(windows),1) -x64_args = -A x64 -x86_args = -A Win32 install_prefix = C:/install else -makefile_dir := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) -x64_args := -D "CMAKE_TOOLCHAIN_FILE=$(makefile_dir)/../toolchains/cmake/gcc-x64.cmake" -x86_args := -D "CMAKE_TOOLCHAIN_FILE=$(makefile_dir)/../toolchains/cmake/gcc-x86.cmake" install_prefix := $$HOME/install endif @@ -190,7 +183,7 @@ boost/58/download: echo/boost/58/build .PHONY: boost/58/build boost/58/build: - "$(python)" -m project.boost.build --configuration Debug --platform x86 --link static -- ./boost_1_58_0 --with-filesystem --with-program_options $(b2_flags) + "$(python)" -m project.boost.build --configuration Debug --platform x86 --link static -- ./boost_1_58_0 --with-filesystem --with-program_options .PHONY: boost/58/ls boost/58/ls: echo/boost/58/ls @@ -198,7 +191,7 @@ boost/58/ls: echo/boost/58/ls .PHONY: boost/58/exe/build boost/58/exe/build: echo/boost/58/exe/build - "$(python)" -m project.cmake.build --install "$(install_prefix)/boost_1_58_0" --platform x86 --configuration Debug -- examples/boost -D "BOOST_ROOT=$(cwd)/boost_1_58_0" -D "BOOST_LIBRARYDIR=$(cwd)/boost_1_58_0/stage/x86/Debug/lib" + "$(python)" -m project.cmake.build --install "$(install_prefix)/boost_1_58_0" --platform x86 --configuration Debug --boost boost_1_58_0 examples/boost .PHONY: boost/58/exe/run # Boost should be linked statically, no need to adjust PATH: @@ -227,7 +220,7 @@ boost/72/download: echo/boost/72/build .PHONY: boost/72/build boost/72/build: - "$(python)" -m project.boost.build --platform x86 x64 --link shared -- ./boost_1_72_0 --with-filesystem --with-program_options $(b2_flags) + "$(python)" -m project.boost.build --platform x86 x64 --link shared -- ./boost_1_72_0 --with-filesystem --with-program_options .PHONY: boost/72/ls boost/72/ls: echo/boost/72/ls @@ -235,7 +228,7 @@ boost/72/ls: echo/boost/72/ls .PHONY: boost/72/exe/build boost/72/exe/build: echo/boost/72/exe/build - "$(python)" -m project.cmake.build --install "$(install_prefix)/boost_1_72_0" --platform x64 --configuration Release -- examples/boost -D "BOOST_ROOT=$(cwd)/boost_1_72_0" -D "BOOST_LIBRARYDIR=$(cwd)/boost_1_72_0/stage/x64/Release/lib" -D Boost_USE_STATIC_LIBS=OFF + "$(python)" -m project.cmake.build --install "$(install_prefix)/boost_1_72_0" --platform x64 --configuration Release --boost boost_1_72_0 -- examples/boost -D Boost_USE_STATIC_LIBS=OFF .PHONY: boost/72/exe/run # Boost is linked dynamically, we need to adjust PATH: @@ -265,7 +258,7 @@ boost/72: boost/72/download boost/72/build boost/72/ls boost/72/exe echo/boost/7 ifdef TRAVIS .PHONY: boost/65/build boost/65/build: echo/boost/65/build - "$(python)" -m project.ci.travis.boost --link static -- --with-filesystem --with-program_options $(b2_flags) + "$(python)" -m project.ci.travis.boost --link static -- --with-filesystem --with-program_options .PHONY: boost/65/ls boost/65/ls: echo/boost/65/ls @@ -273,12 +266,12 @@ boost/65/ls: echo/boost/65/ls .PHONY: boost/65/exe/build boost/65/exe/build: echo/boost/65/exe/build - TRAVIS_BUILD_DIR="$$TRAVIS_BUILD_DIR/examples/boost" "$(python)" -m project.ci.travis.cmake --install "$(install_prefix)/boost_1_65_0" -- -D "BOOST_ROOT=$$HOME/boost" -D "BOOST_LIBRARYDIR=$$HOME/boost/stage/$$platform/$$configuration/lib" + TRAVIS_BUILD_DIR="$$TRAVIS_BUILD_DIR/examples/boost" "$(python)" -m project.ci.travis.cmake --install "$(install_prefix)/boost_1_65_0" --boost "$$HOME/boost" endif ifdef APPVEYOR .PHONY: boost/65/build boost/65/build: echo/boost/65/build - "$(python)" -m project.ci.appveyor.boost --link static -- --with-filesystem --with-program_options $(b2_flags) + "$(python)" -m project.ci.appveyor.boost --link static -- --with-filesystem --with-program_options .PHONY: boost/65/ls boost/65/ls: echo/boost/65/ls @@ -286,7 +279,7 @@ boost/65/ls: echo/boost/65/ls .PHONY: boost/65/exe/build boost/65/exe/build: echo/boost/65/exe/build - set "APPVEYOR_BUILD_FOLDER=%APPVEYOR_BUILD_FOLDER%\examples\boost" && "$(python)" -m project.ci.appveyor.cmake --install "$(install_prefix)/boost_1_65_0" -- -D "BOOST_ROOT=C:\projects\boost" -D "BOOST_LIBRARYDIR=C:\projects\boost\stage\%PLATFORM%\%CONFIGURATION%\lib" + set "APPVEYOR_BUILD_FOLDER=%APPVEYOR_BUILD_FOLDER%\examples\boost" && "$(python)" -m project.ci.appveyor.cmake --install "$(install_prefix)/boost_1_65_0" --boost "C:\projects\boost" endif .PHONY: boost/65/exe/run diff --git a/project/ci/appveyor/cmake.py b/project/ci/appveyor/cmake.py index c1b851c..b720f6b 100644 --- a/project/ci/appveyor/cmake.py +++ b/project/ci/appveyor/cmake.py @@ -105,6 +105,8 @@ def _parse_args(argv=None): parser.add_argument('--install', metavar='DIR', dest='install_dir', help='install directory') + parser.add_argument('--boost', metavar='DIR', dest='boost_dir', + help='set Boost directory path') parser.add_argument('cmake_args', nargs='*', metavar='CMAKE_ARG', default=[], help='additional CMake arguments, to be passed verbatim') return parser.parse_args(argv) @@ -122,6 +124,7 @@ def build_appveyor(argv=None): install_dir=args.install_dir, platform=_get_platform(), configuration=_get_configuration(), + boost_dir=args.boost_dir, cmake_args=cmake_args) build(params) diff --git a/project/ci/travis/cmake.py b/project/ci/travis/cmake.py index 47177bc..2814e41 100644 --- a/project/ci/travis/cmake.py +++ b/project/ci/travis/cmake.py @@ -61,6 +61,8 @@ def _parse_args(argv=None): parser.add_argument('--install', metavar='DIR', dest='install_dir', help='install directory') + parser.add_argument('--boost', metavar='DIR', dest='boost_dir', + help='set Boost directory path') parser.add_argument('cmake_args', nargs='*', metavar='CMAKE_ARG', default=[], help='additional CMake arguments, to be passed verbatim') return parser.parse_args(argv) @@ -75,6 +77,7 @@ def build_travis(argv=None): install_dir=args.install_dir, platform=_get_platform(), configuration=_get_configuration(), + boost_dir=args.boost_dir, cmake_args=args.cmake_args) build(params) diff --git a/project/cmake/build.py b/project/cmake/build.py index 5127c3d..e683eff 100644 --- a/project/cmake/build.py +++ b/project/cmake/build.py @@ -43,11 +43,13 @@ def run_cmake(cmake_args): class GenerationPhase: def __init__(self, src_dir, build_dir, install_dir=None, platform=None, configuration=DEFAULT_CONFIGURATION, - mingw=False, cmake_args=None): + boost_dir=None, mingw=False, 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) + if boost_dir is not None: + boost_dir = normalize_path(boost_dir) cmake_args = cmake_args or [] self.src_dir = src_dir @@ -55,6 +57,7 @@ class GenerationPhase: self.install_dir = install_dir self.platform = platform self.configuration = configuration + self.boost_dir = boost_dir self.mingw = mingw self.cmake_args = cmake_args @@ -64,10 +67,26 @@ class GenerationPhase: result += ['-D', f'CMAKE_INSTALL_PREFIX={self.install_dir}'] result += toolchain.get_cmake_args() result += ['-D', f'CMAKE_BUILD_TYPE={self.configuration}'] + result += self._get_boost_args() result += self.cmake_args result += [f'-B{self.build_dir}', f'-H{self.src_dir}'] return result + def _get_boost_args(self): + if self.boost_dir is None: + return [] + stagedir = self._stagedir(self.boost_dir, self.platform, self.configuration) + return [ + '-D', f'BOOST_ROOT={self.boost_dir}', + '-D', f'BOOST_LIBRARYDIR={stagedir}', + ] + + @staticmethod + def _stagedir(boost_dir, platform, configuration): + if platform is None: + 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)) @@ -97,13 +116,15 @@ class BuildPhase: class BuildParameters: def __init__(self, src_dir, build_dir=None, install_dir=None, platform=None, configuration=DEFAULT_CONFIGURATION, - mingw=False, cmake_args=None): + boost_dir=None, mingw=False, 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) + if boost_dir is not None: + boost_dir = normalize_path(boost_dir) cmake_args = cmake_args or [] self.src_dir = src_dir @@ -111,6 +132,7 @@ class BuildParameters: self.install_dir = install_dir self.platform = platform self.configuration = configuration + self.boost_dir = boost_dir self.mingw = mingw self.cmake_args = cmake_args @@ -140,6 +162,7 @@ def build(params): install_dir=params.install_dir, platform=params.platform, configuration=params.configuration, + boost_dir=params.boost_dir, mingw=params.mingw, cmake_args=params.cmake_args) gen_phase.run() @@ -174,6 +197,10 @@ def _parse_args(argv=None): type=Configuration.parse, default=DEFAULT_CONFIGURATION, help=f'build configuration ({configuration_options})') + parser.add_argument('--boost', metavar='DIR', dest='boost_dir', + type=normalize_path, + help='set Boost directory path') + parser.add_argument('--mingw', action='store_true', help='build using MinGW-w64') -- cgit v1.2.3