Commit 25ce99fc authored by Pedro Eugenio Rocha Pedreira's avatar Pedro Eugenio Rocha Pedreira Committed by Facebook GitHub Bot

Add support for `extra_cmake_defines`

Summary:
`extra_cmake_defines` are extra flags that are passed to cmake when
compiling each one of the dependencies. For instance:
```
$ ./opensource/fbcode_builder/getdeps.py  build f4d --extra-cmake-define='{"CMAKE_CXX_FLAGS": "-mavx2 -mfma -mavx -mf16c -march=native"}'
```
It takes a json map as input, which can take a list of defines (key value
pairs).

Reviewed By: wez

Differential Revision: D25855781

fbshipit-source-id: 7f4fef2c66f4d12f23c8d7086d6a4f24fcc01ff7
parent 6bc74fbd
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
from __future__ import absolute_import, division, print_function, unicode_literals from __future__ import absolute_import, division, print_function, unicode_literals
import argparse import argparse
import json
import os import os
import shutil import shutil
import subprocess import subprocess
...@@ -500,6 +501,12 @@ class BuildCmd(ProjectCmdBase): ...@@ -500,6 +501,12 @@ class BuildCmd(ProjectCmdBase):
if dep_build: if dep_build:
sources_changed = True sources_changed = True
extra_cmake_defines = (
json.loads(args.extra_cmake_defines)
if args.extra_cmake_defines
else {}
)
if sources_changed or reconfigure or not os.path.exists(built_marker): if sources_changed or reconfigure or not os.path.exists(built_marker):
if os.path.exists(built_marker): if os.path.exists(built_marker):
os.unlink(built_marker) os.unlink(built_marker)
...@@ -512,6 +519,7 @@ class BuildCmd(ProjectCmdBase): ...@@ -512,6 +519,7 @@ class BuildCmd(ProjectCmdBase):
ctx, ctx,
loader, loader,
final_install_prefix=loader.get_project_install_prefix(m), final_install_prefix=loader.get_project_install_prefix(m),
extra_cmake_defines=extra_cmake_defines,
) )
builder.build(install_dirs, reconfigure=reconfigure) builder.build(install_dirs, reconfigure=reconfigure)
...@@ -639,6 +647,14 @@ class BuildCmd(ProjectCmdBase): ...@@ -639,6 +647,14 @@ class BuildCmd(ProjectCmdBase):
parser.add_argument( parser.add_argument(
"--schedule-type", help="Indicates how the build was activated" "--schedule-type", help="Indicates how the build was activated"
) )
parser.add_argument(
"--extra-cmake-defines",
help=(
"Input json map that contains extra cmake defines to be used "
"when compiling the current project and all its deps. "
'e.g: \'{"CMAKE_CXX_FLAGS": "--bla"}\''
),
)
@cmd("fixup-dyn-deps", "Adjusts dynamic dependencies for packaging purposes") @cmd("fixup-dyn-deps", "Adjusts dynamic dependencies for packaging purposes")
......
...@@ -387,6 +387,7 @@ if __name__ == "__main__": ...@@ -387,6 +387,7 @@ if __name__ == "__main__":
inst_dir, inst_dir,
defines, defines,
final_install_prefix=None, final_install_prefix=None,
extra_cmake_defines=None,
): ):
super(CMakeBuilder, self).__init__( super(CMakeBuilder, self).__init__(
build_opts, build_opts,
...@@ -398,6 +399,8 @@ if __name__ == "__main__": ...@@ -398,6 +399,8 @@ if __name__ == "__main__":
final_install_prefix=final_install_prefix, final_install_prefix=final_install_prefix,
) )
self.defines = defines or {} self.defines = defines or {}
if extra_cmake_defines:
self.defines.update(extra_cmake_defines)
def _invalidate_cache(self): def _invalidate_cache(self):
for name in [ for name in [
......
...@@ -436,6 +436,10 @@ def setup_build_options(args, host_type=None): ...@@ -436,6 +436,10 @@ def setup_build_options(args, host_type=None):
if not is_windows(): if not is_windows():
scratch_dir = os.path.realpath(scratch_dir) scratch_dir = os.path.realpath(scratch_dir)
# Save any extra cmake defines passed by the user in an env variable, so it
# can be used while hashing this build.
os.environ["GETDEPS_CMAKE_DEFINES"] = getattr(args, "extra_cmake_defines", "") or ""
host_type = _check_host_type(args, host_type) host_type = _check_host_type(args, host_type)
return BuildOptions( return BuildOptions(
......
...@@ -275,7 +275,14 @@ class ManifestLoader(object): ...@@ -275,7 +275,14 @@ class ManifestLoader(object):
env["os"] = self.build_opts.host_type.ostype env["os"] = self.build_opts.host_type.ostype
env["distro"] = self.build_opts.host_type.distro env["distro"] = self.build_opts.host_type.distro
env["distro_vers"] = self.build_opts.host_type.distrovers env["distro_vers"] = self.build_opts.host_type.distrovers
for name in ["CXXFLAGS", "CPPFLAGS", "LDFLAGS", "CXX", "CC"]: for name in [
"CXXFLAGS",
"CPPFLAGS",
"LDFLAGS",
"CXX",
"CC",
"GETDEPS_CMAKE_DEFINES",
]:
env[name] = os.environ.get(name) env[name] = os.environ.get(name)
for tool in ["cc", "c++", "gcc", "g++", "clang", "clang++"]: for tool in ["cc", "c++", "gcc", "g++", "clang", "clang++"]:
env["tool-%s" % tool] = path_search(os.environ, tool) env["tool-%s" % tool] = path_search(os.environ, tool)
......
...@@ -420,6 +420,7 @@ class ManifestParser(object): ...@@ -420,6 +420,7 @@ class ManifestParser(object):
ctx, ctx,
loader, loader,
final_install_prefix=None, final_install_prefix=None,
extra_cmake_defines=None,
): ):
builder = self.get("build", "builder", ctx=ctx) builder = self.get("build", "builder", ctx=ctx)
if not builder: if not builder:
...@@ -472,6 +473,7 @@ class ManifestParser(object): ...@@ -472,6 +473,7 @@ class ManifestParser(object):
inst_dir, inst_dir,
defines, defines,
final_install_prefix, final_install_prefix,
extra_cmake_defines,
) )
if builder == "python-wheel": if builder == "python-wheel":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment