Skip to content

Commit

Permalink
(#17882) b2: Support CXX from a VirtualBuildEnv
Browse files Browse the repository at this point in the history
* Use environment from VirtualBuildEnv to get CXX/CXXFLAGS

* Write a project-config.jam file containing the toolset from CXX

This ensures the b2 install command can find the correct compiler binary.

---------

Co-authored-by: Chris Mc <christopherm@jfrog.com>
  • Loading branch information
PeteAudinate and Chris Mc authored Aug 11, 2023
1 parent 49ccd98 commit 1485a37
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions recipes/b2/portable/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import cross_building
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import chdir, copy, get
from conan.tools.layout import basic_layout

Expand Down Expand Up @@ -107,6 +108,12 @@ def _bootstrap_env(self):
os.environ.clear()
os.environ.update(saved_env)

def _write_project_config(self, cxx):
with open(os.path.join(self.source_folder, "project-config.jam"), "w") as f:
f.write(
f"using {self.options.toolset} : : {cxx} ;\n"
)

def build(self):
# The order of the with:with: below is important. The first one changes
# the current dir. While the second does env changes that guarantees
Expand Down Expand Up @@ -139,10 +146,14 @@ def build(self):
command += "build" if use_windows_commands else "./build.sh"

if self.options.use_cxx_env:
cxx = os.environ.get("CXX")
envvars = VirtualBuildEnv(self).vars()

cxx = envvars.get("CXX")
if cxx:
command += f" --cxx={cxx}"
cxxflags = os.environ.get("CXXFLAGS")
self._write_project_config(cxx)

cxxflags = envvars.get("CXXFLAGS")
if cxxflags:
command += f" --cxxflags={cxxflags}"

Expand Down

0 comments on commit 1485a37

Please sign in to comment.