| 1 |
#!/usr/bin/python |
| 2 |
############################################################################### |
| 3 |
# # |
| 4 |
# This file is part of IfcOpenShell. # |
| 5 |
# # |
| 6 |
# IfcOpenShell is free software: you can redistribute it and/or modify # |
| 7 |
# it under the terms of the Lesser GNU General Public License as published by # |
| 8 |
# the Free Software Foundation, either version 3.0 of the License, or # |
| 9 |
# (at your option) any later version. # |
| 10 |
# # |
| 11 |
# IfcOpenShell is distributed in the hope that it will be useful, # |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
| 14 |
# Lesser GNU General Public License for more details. # |
| 15 |
# # |
| 16 |
# You should have received a copy of the Lesser GNU General Public License # |
| 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
| 18 |
# # |
| 19 |
############################################################################### |
| 20 |
|
| 21 |
############################################################################### |
| 22 |
# # |
| 23 |
# This script builds IfcOpenShell and its dependencies # |
| 24 |
# # |
| 25 |
# Prerequisites for this script to function correctly: # |
| 26 |
# * git * bzip2 * tar * c(++) compilers * yacc * autoconf # |
| 27 |
# # |
| 28 |
# if building with USE_OCCT additionally: # |
| 29 |
# * freetype * glx.h # |
| 30 |
# # |
| 31 |
# if building with -shared # |
| 32 |
# * libgl1-mesa-dev libxext-dev libxmu-dev libxmu-headers libxi-dev # |
| 33 |
# # |
| 34 |
# for python37 to install correctly additionally: # |
| 35 |
# * libffi(-dev[el]) # |
| 36 |
# # |
| 37 |
# on debian 7.8 these can be obtained with: # |
| 38 |
# $ apt-get install git gcc g++ autoconf bison bzip2 # |
| 39 |
# libfreetype6-dev mesa-common-dev libffi-dev # |
| 40 |
# # |
| 41 |
# on ubuntu 14.04: # |
| 42 |
# $ apt-get install git gcc g++ autoconf bison make # |
| 43 |
# libfreetype6-dev mesa-common-dev libffi-dev # |
| 44 |
# # |
| 45 |
# on OS X El Capitan with homebrew: # |
| 46 |
# $ brew install git bison autoconf automake freetype libffi # |
| 47 |
# # |
| 48 |
############################################################################### |
| 49 |
|
| 50 |
from __future__ import print_function |
| 51 |
|
| 52 |
import logging |
| 53 |
import os |
| 54 |
import sys |
| 55 |
import subprocess as sp |
| 56 |
import shutil |
| 57 |
import time |
| 58 |
import tarfile |
| 59 |
import multiprocessing |
| 60 |
|
| 61 |
PYTHON_MAJOR = sys.version_info[0] |
| 62 |
|
| 63 |
if PYTHON_MAJOR >= 3: |
| 64 |
from urllib.request import urlretrieve |
| 65 |
else: |
| 66 |
# Not Python 3 - today, it is most likely to be Python 2 |
| 67 |
# But note that this might need an update when Python 4 |
| 68 |
# might be around one day |
| 69 |
from urllib import urlretrieve |
| 70 |
|
| 71 |
|
| 72 |
logger = logging.getLogger(__name__) |
| 73 |
logger.setLevel(logging.INFO) |
| 74 |
ch = logging.StreamHandler() |
| 75 |
ch.setLevel(logging.INFO) |
| 76 |
logger.addHandler(ch) |
| 77 |
|
| 78 |
PROJECT_NAME="IfcOpenShell" |
| 79 |
PYTHON_VERSIONS=["2.7.16", "3.2.6", "3.3.6", "3.4.6", "3.5.3", "3.6.2", "3.7.3"] |
| 80 |
JSON_VERSION="v3.6.1" |
| 81 |
OCE_VERSION="0.18" |
| 82 |
# OCCT_VERSION="7.1.0" |
| 83 |
# OCCT_HASH="89aebde" |
| 84 |
# OCCT_VERSION="7.2.0" |
| 85 |
# OCCT_HASH="88af392" |
| 86 |
OCCT_VERSION="7.3.0p3" |
| 87 |
BOOST_VERSION="1.69.0" |
| 88 |
#PCRE_VERSION="8.39" |
| 89 |
PCRE_VERSION="8.41" |
| 90 |
#LIBXML2_VERSION="2.9.3" |
| 91 |
LIBXML2_VERSION="2.9.9" |
| 92 |
CMAKE_VERSION="3.4.1" |
| 93 |
#CMAKE_VERSION="3.14.5" |
| 94 |
SWIG_VERSION="3.0.12" |
| 95 |
#SWIG_VERSION="4.0.0" |
| 96 |
#OPENCOLLADA_VERSION="v1.6.63" |
| 97 |
OPENCOLLADA_VERSION="v1.6.68" |
| 98 |
GMP_VERSION="6.1.2" |
| 99 |
MPFR_VERSION="3.1.5" |
| 100 |
CGAL_VERSION="5.2" |
| 101 |
|
| 102 |
# binaries |
| 103 |
cp="cp" |
| 104 |
bash="bash" |
| 105 |
uname="uname" |
| 106 |
git="git" |
| 107 |
bunzip2="bunzip2" |
| 108 |
tar="tar" |
| 109 |
cc="cc" |
| 110 |
cplusplus="c++" |
| 111 |
autoconf="autoconf" |
| 112 |
automake="automake" |
| 113 |
yacc="yacc" |
| 114 |
make="make" |
| 115 |
date = "date" |
| 116 |
curl="curl" |
| 117 |
wget="wget" |
| 118 |
strip="strip" |
| 119 |
|
| 120 |
# Helper function for coloured printing |
| 121 |
|
| 122 |
NO_COLOR="\033[0m" # <ref>http://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux</ref> |
| 123 |
BLACK_ON_WHITE="\033[0;30;107m" |
| 124 |
RED="\033[31m" |
| 125 |
GREEN="\033[32m" |
| 126 |
YELLOW="\033[33m" |
| 127 |
MAGENTA="\033[35m" |
| 128 |
|
| 129 |
def cecho(message, color=NO_COLOR): |
| 130 |
"""Logs message `message` in color `color`.""" |
| 131 |
logger.info("%s%s\033[0m" % (color, message)) |
| 132 |
|
| 133 |
def which(cmd): |
| 134 |
for path in os.environ["PATH"].split(":"): |
| 135 |
if os.path.exists(path) and cmd in os.listdir(path): |
| 136 |
return cmd |
| 137 |
return None |
| 138 |
|
| 139 |
def get_os(): |
| 140 |
ret_value = sp.check_output([uname, "-s"]).strip() |
| 141 |
return ret_value |
| 142 |
|
| 143 |
def to_pystring(x): |
| 144 |
""" Python 2 & 3 compatibility function for strings handling |
| 145 |
(to solve TypeError "Can't mix strings and bytes in path components" for Python 3). |
| 146 |
Reference https://github.com/hugsy/gef/issues/382 """ |
| 147 |
res = str(x, encoding="utf-8") if PYTHON_MAJOR == 3 else x |
| 148 |
substs = [("\n","\\n"), ("\r","\\r"), ("\t","\\t"), ("\v","\\v"), ("\b","\\b"), ] |
| 149 |
for x,y in substs: res = res.replace(x,y) |
| 150 |
return res |
| 151 |
|
| 152 |
# Set defaults for missing empty environment variables |
| 153 |
|
| 154 |
USE_OCCT = os.environ.get("USE_OCCT", "true").lower() == "true" |
| 155 |
|
| 156 |
TOOLSET = None |
| 157 |
if get_os() == "Darwin": |
| 158 |
# C++11 features used in OCCT 7+ need a more recent stdlib |
| 159 |
TOOLSET = "10.9" if USE_OCCT else "10.6" |
| 160 |
|
| 161 |
try: |
| 162 |
IFCOS_NUM_BUILD_PROCS = os.environ["IFCOS_NUM_BUILD_PROCS"] |
| 163 |
except KeyError: |
| 164 |
IFCOS_NUM_BUILD_PROCS=multiprocessing.cpu_count() + 1 |
| 165 |
|
| 166 |
try: |
| 167 |
TARGET_ARCH = os.environ["TARGET_ARCH"] |
| 168 |
except KeyError: |
| 169 |
TARGET_ARCH = sp.check_output([uname, "-m"]).strip() |
| 170 |
|
| 171 |
CMAKE_DIR=os.path.realpath(os.path.join("..", "cmake")) |
| 172 |
|
| 173 |
try: |
| 174 |
DEPS_DIR = os.environ["DEPS_DIR"] |
| 175 |
except KeyError: |
| 176 |
path = [b"..", b"build", sp.check_output(uname).strip(), TARGET_ARCH] |
| 177 |
if TOOLSET: |
| 178 |
path.append(TOOLSET) |
| 179 |
|
| 180 |
DEPS_DIR = to_pystring(os.path.realpath(os.path.join(*path))) |
| 181 |
|
| 182 |
if not os.path.exists(DEPS_DIR): |
| 183 |
os.makedirs(DEPS_DIR) |
| 184 |
|
| 185 |
try: |
| 186 |
BUILD_CFG=os.environ["BUILD_CFG"] |
| 187 |
except KeyError: |
| 188 |
BUILD_CFG="RelWithDebInfo" |
| 189 |
|
| 190 |
|
| 191 |
# Print build configuration information |
| 192 |
|
| 193 |
cecho ("""This script fetches and builds %s and its dependencies |
| 194 |
""" % (PROJECT_NAME,), BLACK_ON_WHITE) |
| 195 |
cecho("""Script configuration: |
| 196 |
|
| 197 |
""", GREEN) |
| 198 |
cecho("""* Target Architecture = %s""" % (TARGET_ARCH,), MAGENTA) |
| 199 |
cecho(" - Whether 32-bit (i686) or 64-bit (x86_64) will be built.") |
| 200 |
cecho("""* USE_OCCT = %r""" % (USE_OCCT,), MAGENTA) |
| 201 |
if USE_OCCT: |
| 202 |
cecho(" - Compiling against official Open Cascade") |
| 203 |
else: |
| 204 |
cecho(" - Compiling against Open Cascade Community Edition") |
| 205 |
cecho("* Dependency Directory = %s" % (DEPS_DIR,), MAGENTA) |
| 206 |
cecho(" - The directory where %s dependencies are installed." % (PROJECT_NAME,)) |
| 207 |
cecho("* Build Config Type = %s" % (BUILD_CFG,), MAGENTA) |
| 208 |
cecho(""" - The used build configuration type for the dependencies. |
| 209 |
Defaults to RelWithDebInfo if not specified.""") |
| 210 |
|
| 211 |
if BUILD_CFG == "MinSizeRel": |
| 212 |
cecho(" WARNING: MinSizeRel build can suffer from a significant performance loss.", RED) |
| 213 |
|
| 214 |
cecho("* IFCOS_NUM_BUILD_PROCS = %s" % (IFCOS_NUM_BUILD_PROCS,), MAGENTA) |
| 215 |
cecho(""" - How many compiler processes may be run in parallel. |
| 216 |
""") |
| 217 |
|
| 218 |
dependency_tree = { |
| 219 |
'IfcParse': ('boost', 'libxml2'), |
| 220 |
'IfcGeom': ('IfcParse', 'occ', 'cgal', 'voxel', 'eigen'), |
| 221 |
'IfcConvert': ('IfcGeom', 'OpenCOLLADA', 'json'), |
| 222 |
'OpenCOLLADA': ('libxml2', 'pcre'), |
| 223 |
'IfcGeomServer': ('IfcGeom', ), |
| 224 |
'IfcOpenShell-Python': ('python', 'swig', 'IfcGeom'), |
| 225 |
'voxel': ('occ',), |
| 226 |
'swig': ('pcre',), |
| 227 |
'occ': (), |
| 228 |
} |
| 229 |
|
| 230 |
def v(dep): |
| 231 |
yield dep |
| 232 |
for d in dependency_tree.get(dep, []): |
| 233 |
for x in v(d): |
| 234 |
yield x |
| 235 |
|
| 236 |
tgts = [s for s in sys.argv[1:] if not s.startswith("-")] |
| 237 |
flags = set(s for s in sys.argv[1:] if s.startswith("-")) |
| 238 |
|
| 239 |
BUILD_STATIC = not "-shared" in flags |
| 240 |
ENABLE_FLAG = "--enable-static" if BUILD_STATIC else "--enable-shared" |
| 241 |
DISABLE_FLAG = "--disable-shared" if BUILD_STATIC else "--disable-static" |
| 242 |
LINK_TYPE = "static" if BUILD_STATIC else "shared" |
| 243 |
LINK_TYPE_UCFIRST = LINK_TYPE[0].upper() + LINK_TYPE[1:] |
| 244 |
LIBRARY_EXT = "a" if BUILD_STATIC else "so" |
| 245 |
PIC = "-fPIC" if BUILD_STATIC else "" |
| 246 |
|
| 247 |
if len(tgts): |
| 248 |
targets = set(sum((list(v(target)) for target in tgts), [])) |
| 249 |
else: |
| 250 |
targets = set(tuple(dependency_tree.keys()) + sum(dependency_tree.values(), ())) |
| 251 |
|
| 252 |
print("Building:", *sorted(targets, key=lambda t: len(list(v(t))))) |
| 253 |
|
| 254 |
# Check that required tools are in PATH |
| 255 |
|
| 256 |
for cmd in [git, bunzip2, tar, cc, cplusplus, autoconf, automake, yacc, make, "patch", "m4", "cmake"]: |
| 257 |
if which(cmd) is None: |
| 258 |
raise ValueError("Required tool '%s' not installed or not added to PATH" % (cmd,)) |
| 259 |
|
| 260 |
# identifiers for the download tool (could be less memory consuming as ints, but are more verbose as strings) |
| 261 |
download_tool_default = download_tool_py = "py" |
| 262 |
download_tool_git = "git" |
| 263 |
|
| 264 |
# Create log directory and file |
| 265 |
|
| 266 |
log_dir = os.path.join(DEPS_DIR, "logs") |
| 267 |
if not os.path.exists(log_dir): |
| 268 |
os.makedirs(log_dir) |
| 269 |
LOG_FILE="%s.log" % (os.path.join(log_dir, to_pystring(sp.check_output([date, "+%Y%m%d"]).strip())),) |
| 270 |
if not os.path.exists(LOG_FILE): |
| 271 |
open(LOG_FILE, "w").close() |
| 272 |
logger.info("using command log file '%s'" % (LOG_FILE,)) |
| 273 |
|
| 274 |
def run(cmds, cwd=None): |
| 275 |
|
| 276 |
""" |
| 277 |
Wraps `subprocess.Popen.communicate()` and logs the command being executed, |
| 278 |
sets up logging `stderr` to `LOG_FILE` (in append mode) and returns stdout |
| 279 |
with leading and trailing whitespace removed. |
| 280 |
""" |
| 281 |
|
| 282 |
logger.debug("running command %r in directory %r" % (" ".join(cmds), cwd)) |
| 283 |
log_file_handle = open(LOG_FILE, "ab") |
| 284 |
proc = sp.Popen(cmds, cwd=cwd, stdout=sp.PIPE, stderr=sp.PIPE) |
| 285 |
stdout, stderr = proc.communicate() |
| 286 |
log_file_handle.write(stdout) |
| 287 |
log_file_handle.write(stderr) |
| 288 |
log_file_handle.close() |
| 289 |
logger.debug("command returned %r" % proc.returncode) |
| 290 |
|
| 291 |
if proc.returncode != 0: |
| 292 |
print("-" * 70) |
| 293 |
print(stderr) |
| 294 |
print("-" * 70) |
| 295 |
raise Exception("Command `%s` returned exit code %d" % (" ".join(cmds), proc.returncode)) |
| 296 |
|
| 297 |
return stdout.strip() |
| 298 |
|
| 299 |
BOOST_VERSION_UNDERSCORE=BOOST_VERSION.replace(".", "_") |
| 300 |
CMAKE_VERSION_2=CMAKE_VERSION[:CMAKE_VERSION.rindex('.')] |
| 301 |
|
| 302 |
OCE_LOCATION="https://github.com/tpaviot/oce/archive/OCE-%s.tar.gz" % (OCE_VERSION,) |
| 303 |
BOOST_LOCATION="http://downloads.sourceforge.net/project/boost/boost/%s/boost_%s.tar.bz2" % (BOOST_VERSION, BOOST_VERSION_UNDERSCORE) |
| 304 |
|
| 305 |
# Helper functions |
| 306 |
|
| 307 |
def run_autoconf(arg1, configure_args, cwd): |
| 308 |
configure_path = os.path.realpath(os.path.join(cwd, "..", "configure")) |
| 309 |
install_dir = os.path.realpath("%s/install/%s" % (DEPS_DIR, arg1)) |
| 310 |
if not os.path.exists(install_dir): |
| 311 |
# Some (MPFR) need to have prefix dir manually created |
| 312 |
os.makedirs(install_dir) |
| 313 |
if not os.path.exists(configure_path): |
| 314 |
run([bash, "./autogen.sh"], cwd=os.path.realpath(os.path.join(cwd, ".."))) # only run autogen.sh in the directory it is located and use cwd to achieve that in order to not mess up things |
| 315 |
# Using `sh` over `bash` fixes issues with building swig |
| 316 |
run(["/bin/sh", "../configure"]+configure_args+["--prefix=%s" % install_dir], cwd=cwd) |
| 317 |
|
| 318 |
def run_cmake(arg1, cmake_args, cmake_dir=None, cwd=None): |
| 319 |
if cmake_dir is None: |
| 320 |
P=".." |
| 321 |
else: |
| 322 |
P=cmake_dir |
| 323 |
# @todo this is already in v0.6 |
| 324 |
cmake_path = "cmake" |
| 325 |
run([cmake_path, P]+cmake_args+["-DCMAKE_BUILD_TYPE=%s" % (BUILD_CFG,)], cwd=cwd) |
| 326 |
|
| 327 |
def git_clone_or_pull_repository(clone_url, target_dir, revision=None): |
| 328 |
"""Lazily clones the `git` repository denoted by `clone_url` into |
| 329 |
the `target_dir` or pulls latest changes if the `target_dir` exists (naively assumes |
| 330 |
that a working clone exists there) and optionally checks out a revision |
| 331 |
`revision` after cloning or in the existing clone if `revision` is not |
| 332 |
`None`.""" |
| 333 |
if not os.path.exists(target_dir): |
| 334 |
logger.info("cloning '%s' into '%s'" % (clone_url, target_dir)) |
| 335 |
run([git, "clone", clone_url, target_dir]) |
| 336 |
else: |
| 337 |
logger.info("directory '%s' already cloned. Pulling latest changes." % (target_dir,)) |
| 338 |
|
| 339 |
# detect whether we are on a branch and pull |
| 340 |
if run([git, "rev-parse", "--abbrev-ref", "HEAD"], cwd=target_dir) != "HEAD": |
| 341 |
run([git, "pull", clone_url], cwd=target_dir) |
| 342 |
|
| 343 |
if revision != None: |
| 344 |
run([git, "checkout", revision], cwd=target_dir) |
| 345 |
|
| 346 |
|
| 347 |
def build_dependency(name, mode, build_tool_args, download_url, download_name, download_tool=download_tool_default, revision=None, patch=None, additional_files={}, no_append_name=False): |
| 348 |
"""Handles building of dependencies with different tools (which are |
| 349 |
distinguished with the `mode` argument. `build_tool_args` is expected to be |
| 350 |
a list which is necessary in order to not mess up quoting of compiler and |
| 351 |
linker flags.""" |
| 352 |
check_dir = os.path.join(DEPS_DIR, "install", name) |
| 353 |
if os.path.exists(check_dir): |
| 354 |
logger.info( "Found existing %s, skipping" % (name,)) |
| 355 |
return |
| 356 |
build_dir = os.path.join(DEPS_DIR, "build") |
| 357 |
if not os.path.exists(build_dir): |
| 358 |
os.makedirs(build_dir) |
| 359 |
|
| 360 |
logger.info("\rFetching %s... " % (name,)) |
| 361 |
|
| 362 |
if download_tool == download_tool_py: |
| 363 |
if no_append_name: |
| 364 |
url = download_url |
| 365 |
else: |
| 366 |
url = os.path.join(download_url, download_name) |
| 367 |
|
| 368 |
download_path = os.path.join(build_dir, download_name) |
| 369 |
if not os.path.exists(download_path): |
| 370 |
urlretrieve(url, os.path.join(build_dir, download_path)) |
| 371 |
else: |
| 372 |
logger.info("Download '%s' already exists, assuming it's an undamaged download and that it has been extracted if possible, skipping" % (download_path,)) |
| 373 |
elif download_tool == download_tool_git: |
| 374 |
logger.info("\rChecking %s... " % (name,)) |
| 375 |
git_clone_or_pull_repository(download_url, target_dir=os.path.join(build_dir, download_name), revision=revision) |
| 376 |
else: |
| 377 |
raise ValueError("download tool '%s' is not supported" % (download_tool,)) |
| 378 |
download_dir = os.path.join(build_dir, download_name) |
| 379 |
|
| 380 |
if os.path.isdir(download_dir): |
| 381 |
extract_dir_name=download_name |
| 382 |
extract_dir = os.path.join(build_dir, extract_dir_name) |
| 383 |
else: |
| 384 |
download_tarfile_path = os.path.join(build_dir, download_name) |
| 385 |
if download_name.endswith(".tar.gz") or download_name.endswith(".tgz"): |
| 386 |
compr = "gz" |
| 387 |
elif download_name.endswith(".tar.bz2"): |
| 388 |
compr = "bz2" |
| 389 |
else: |
| 390 |
raise RuntimeError("fix source for new download type") |
| 391 |
download_tarfile = tarfile.open(name=download_tarfile_path, mode="r:%s" % (compr,)) |
| 392 |
extract_dir_name= os.path.commonprefix(download_tarfile.getnames()) # tarfile seriously doesn't have a function to retrieve the root directory more easily |
| 393 |
#run([tar, "--exclude=\"*/*\"", "-tf", download_name], cwd=build_dir).strip() no longer works |
| 394 |
if extract_dir_name is None: |
| 395 |
extract_dir_name= run([bash, "-c", "tar -tf %s 2> /dev/null | head -n 1 | cut -f1 -d /" % (download_name,)], cwd=build_dir) |
| 396 |
extract_dir = os.path.join(build_dir, extract_dir_name) |
| 397 |
if not os.path.exists(extract_dir): |
| 398 |
run([tar, "-xf", download_name], cwd=build_dir) |
| 399 |
|
| 400 |
for path, url in additional_files.items(): |
| 401 |
if not os.path.exists(path): |
| 402 |
urlretrieve(url, os.path.join(extract_dir, path)) |
| 403 |
|
| 404 |
if patch is not None: |
| 405 |
patch_abs = os.path.abspath(os.path.join(os.path.dirname(__file__), patch)) |
| 406 |
if os.path.exists(patch_abs): |
| 407 |
try: run(["patch", "-p1", "--batch", "--forward", "-i", patch_abs], cwd=extract_dir) |
| 408 |
except Exception as e: |
| 409 |
# Assert that the patch has already been applied |
| 410 |
run(["patch", "-p1", "--batch", "--reverse", "--dry-run", "-i", patch_abs], cwd=extract_dir) |
| 411 |
|
| 412 |
if mode != "bjam": |
| 413 |
extract_build_dir = os.path.join(extract_dir, "build") |
| 414 |
if os.path.exists(extract_build_dir): |
| 415 |
shutil.rmtree(extract_build_dir) |
| 416 |
os.makedirs(extract_build_dir) |
| 417 |
|
| 418 |
logger.info("\rConfiguring %s..." % (name,)) |
| 419 |
if mode == "autoconf": |
| 420 |
run_autoconf(name, build_tool_args, cwd=extract_build_dir) |
| 421 |
elif mode == "cmake": |
| 422 |
run_cmake(name, build_tool_args, cwd=extract_build_dir) |
| 423 |
else: |
| 424 |
raise ValueError() |
| 425 |
logger.info("\rBuilding %s... " % (name,)) |
| 426 |
run([make, "-j%s" % (IFCOS_NUM_BUILD_PROCS,)], cwd=extract_build_dir) |
| 427 |
logger.info( "\rInstalling %s... " % (name,)) |
| 428 |
run([make, "install"], cwd=extract_build_dir) |
| 429 |
logger.info( "\rInstalled %s \n" % (name,)) |
| 430 |
else: |
| 431 |
logger.info( "\rConfiguring %s..." % (name,)) |
| 432 |
run([bash, "./bootstrap.sh"] + (['--with-toolset=clang'] if "clang" in os.environ.get('CXX', '') else []), cwd=extract_dir) |
| 433 |
logger.info("\rBuilding %s... " % (name,)) |
| 434 |
run(["./b2", "-j%s" % (IFCOS_NUM_BUILD_PROCS,)]+build_tool_args, cwd=extract_dir) |
| 435 |
logger.info("\rInstalling %s... " % (name,)) |
| 436 |
shutil.copytree(os.path.join(extract_dir, "boost"), os.path.join(DEPS_DIR, "install", "boost-%s" % BOOST_VERSION, "boost")) |
| 437 |
logger.info("\rInstalled %s \n" % (name,)) |
| 438 |
|
| 439 |
cecho("Collecting dependencies:", GREEN) |
| 440 |
|
| 441 |
# Set compiler flags for 32bit builds on 64bit system |
| 442 |
# TODO: This is untested |
| 443 |
|
| 444 |
ADDITIONAL_ARGS=[] |
| 445 |
BOOST_ADDRESS_MODEL=[] |
| 446 |
if TARGET_ARCH == "i686" and run([uname, "-m"]).strip() == "x86_64": |
| 447 |
ADDITIONAL_ARGS=["-m32", "-arch i386"] |
| 448 |
BOOST_ADDRESS_MODEL=["architecture=x86", "address-model=32"] |
| 449 |
|
| 450 |
if get_os() == "Darwin": |
| 451 |
ADDITIONAL_ARGS=["-mmacosx-version-min=%s" % TOOLSET]+ADDITIONAL_ARGS |
| 452 |
|
| 453 |
# If the linker supports GC sections, set it up to reduce binary file size |
| 454 |
# -fPIC is required for the shared libraries to work |
| 455 |
|
| 456 |
CXXFLAGS=os.environ.get("CXXFLAGS", "") |
| 457 |
CFLAGS=os.environ.get("CFLAGS", "") |
| 458 |
LDFLAGS=os.environ.get("LDFLAGS", "") |
| 459 |
|
| 460 |
if sp.call([bash, "-c", "ld --gc-sections 2>&1 | grep -- --gc-sections &> /dev/null"]) != 0: |
| 461 |
CXXFLAGS_MINIMAL="%s %s %s" % (CXXFLAGS, PIC, str.join(" ", ADDITIONAL_ARGS)) |
| 462 |
CFLAGS_MINIMAL="%s %s %s" % (CFLAGS, PIC, str.join(" ", ADDITIONAL_ARGS)) |
| 463 |
if BUILD_STATIC: |
| 464 |
CXXFLAGS="%s %s -fdata-sections -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden %s" % (CXXFLAGS, PIC, str.join(" ", ADDITIONAL_ARGS)) |
| 465 |
CFLAGS="%s %s -fdata-sections -ffunction-sections -fvisibility=hidden %s"% (CFLAGS, PIC, str.join(" ", ADDITIONAL_ARGS)) |
| 466 |
else: |
| 467 |
CXXFLAGS=CXXFLAGS_MINIMAL |
| 468 |
CFLAGS=CFLAGS_MINIMAL |
| 469 |
LDFLAGS="%s -Wl,--gc-sections %s" % (LDFLAGS, str.join(" ", ADDITIONAL_ARGS)) |
| 470 |
else: |
| 471 |
CXXFLAGS_MINIMAL="%s %s %s" % (CXXFLAGS, PIC, str.join(" ", ADDITIONAL_ARGS)) |
| 472 |
CFLAGS_MINIMAL="%s %s %s" % (CFLAGS, PIC, str.join(" ", ADDITIONAL_ARGS)) |
| 473 |
if BUILD_STATIC: |
| 474 |
CXXFLAGS="%s %s -fvisibility=hidden -fvisibility-inlines-hidden %s" % (CXXFLAGS, PIC, str.join(" ", ADDITIONAL_ARGS)) |
| 475 |
CFLAGS="%s %s -fvisibility=hidden -fvisibility-inlines-hidden %s" % (CFLAGS, PIC, str.join(" ", ADDITIONAL_ARGS)) |
| 476 |
else: |
| 477 |
CXXFLAGS=CXXFLAGS_MINIMAL |
| 478 |
CFLAGS=CFLAGS_MINIMAL |
| 479 |
LDFLAGS="%s %s" % (LDFLAGS, str.join(" ", ADDITIONAL_ARGS)) |
| 480 |
|
| 481 |
os.environ["CXXFLAGS"] = CXXFLAGS |
| 482 |
os.environ["CFLAGS"] = CFLAGS |
| 483 |
os.environ["LDFLAGS"] = LDFLAGS |
| 484 |
|
| 485 |
if "json" in targets: |
| 486 |
json_url = "https://github.com/nlohmann/json/releases/download/{JSON_VERSION}/json.hpp".format(**locals()) |
| 487 |
json_install_path = "{DEPS_DIR}/install/json/nlohmann/json.hpp".format(**locals()) |
| 488 |
if not os.path.exists(os.path.dirname(json_install_path)): |
| 489 |
os.makedirs(os.path.dirname(json_install_path)) |
| 490 |
if not os.path.exists(json_install_path): |
| 491 |
urlretrieve(json_url, json_install_path) |
| 492 |
|
| 493 |
if "eigen" in targets: |
| 494 |
git_clone_or_pull_repository("https://gitlab.com/libeigen/eigen.git", "{DEPS_DIR}/install/eigen-3.3.7".format(**locals()), revision="3.3.7") |
| 495 |
|
| 496 |
if "pcre" in targets: |
| 497 |
build_dependency( |
| 498 |
name="pcre-{PCRE_VERSION}".format(**locals()), |
| 499 |
mode="autoconf", |
| 500 |
build_tool_args=[DISABLE_FLAG], |
| 501 |
download_url="https://downloads.sourceforge.net/project/pcre/pcre/{PCRE_VERSION}/".format(**locals()), |
| 502 |
download_name="pcre-{PCRE_VERSION}.tar.bz2".format(**locals()) |
| 503 |
) |
| 504 |
|
| 505 |
# An issue exists with swig-1.3 and python >= 3.2 |
| 506 |
# Therefore, build a recent copy from source |
| 507 |
if "swig" in targets: |
| 508 |
build_dependency( |
| 509 |
name="swig", |
| 510 |
mode="autoconf", |
| 511 |
build_tool_args=["--with-pcre-prefix={DEPS_DIR}/install/pcre-{PCRE_VERSION}".format(**locals())], |
| 512 |
download_url="https://github.com/swig/swig.git", |
| 513 |
download_name="swig", |
| 514 |
download_tool=download_tool_git, |
| 515 |
revision="rel-{SWIG_VERSION}".format(**locals()) |
| 516 |
) |
| 517 |
|
| 518 |
if USE_OCCT and "occ" in targets: |
| 519 |
build_dependency( |
| 520 |
name="occt-{OCCT_VERSION}".format(**locals()), |
| 521 |
mode="cmake", |
| 522 |
build_tool_args=[ |
| 523 |
"-DINSTALL_DIR={DEPS_DIR}/install/occt-{OCCT_VERSION}".format(**locals()), |
| 524 |
"-DBUILD_LIBRARY_TYPE={LINK_TYPE_UCFIRST}".format(**locals()), |
| 525 |
"-DBUILD_MODULE_Draw=0", |
| 526 |
], |
| 527 |
download_url = "https://git.dev.opencascade.org/repos/occt.git", |
| 528 |
download_name = "occt", |
| 529 |
download_tool=download_tool_git, |
| 530 |
patch="./patches/occt/enable-exception-handling.patch", |
| 531 |
revision="V" + OCCT_VERSION.replace('.', '_') |
| 532 |
) |
| 533 |
occ_include_dir = "{DEPS_DIR}/install/occt-{OCCT_VERSION}/include/opencascade".format(**locals()) |
| 534 |
occ_library_dir = "{DEPS_DIR}/install/occt-{OCCT_VERSION}/lib".format(**locals()) |
| 535 |
elif "occ" in targets: |
| 536 |
build_dependency( |
| 537 |
name="oce-{OCE_VERSION}".format(**locals()), |
| 538 |
mode="cmake", |
| 539 |
build_tool_args=[ |
| 540 |
"-DOCE_DISABLE_TKSERVICE_FONT=ON", |
| 541 |
"-DOCE_TESTING=OFF", |
| 542 |
"-DOCE_BUILD_SHARED_LIB=OFF", |
| 543 |
"-DOCE_DISABLE_X11=ON", |
| 544 |
"-DOCE_VISUALISATION=OFF", |
| 545 |
"-DOCE_OCAF=OFF", |
| 546 |
"-DOCE_INSTALL_PREFIX={DEPS_DIR}/install/oce-{OCE_VERSION}".format(**locals()) |
| 547 |
], |
| 548 |
download_url="https://github.com/tpaviot/oce/archive/", |
| 549 |
download_name="OCE-{OCE_VERSION}.tar.gz".format(**locals()) |
| 550 |
) |
| 551 |
occ_include_dir = "{DEPS_DIR}/install/oce-{OCE_VERSION}/include/oce".format(**locals()) |
| 552 |
occ_library_dir = "{DEPS_DIR}/install/oce-{OCE_VERSION}/lib" |
| 553 |
|
| 554 |
|
| 555 |
if "libxml2" in targets: |
| 556 |
build_dependency( |
| 557 |
"libxml2-{LIBXML2_VERSION}".format(**locals()), |
| 558 |
"autoconf", |
| 559 |
build_tool_args=[ |
| 560 |
"--without-python", |
| 561 |
ENABLE_FLAG, |
| 562 |
DISABLE_FLAG, |
| 563 |
"--without-zlib", |
| 564 |
"--without-iconv", |
| 565 |
"--without-lzma" |
| 566 |
], |
| 567 |
download_url="ftp://xmlsoft.org/libxml2/", |
| 568 |
download_name="libxml2-{LIBXML2_VERSION}.tar.gz".format(**locals()) |
| 569 |
) |
| 570 |
|
| 571 |
if "OpenCOLLADA" in targets: |
| 572 |
build_dependency( |
| 573 |
"OpenCOLLADA", |
| 574 |
"cmake", |
| 575 |
build_tool_args=[ |
| 576 |
"-DLIBXML2_INCLUDE_DIR={DEPS_DIR}/install/libxml2-{LIBXML2_VERSION}/include/libxml2".format(**locals()), |
| 577 |
"-DLIBXML2_LIBRARIES={DEPS_DIR}/install/libxml2-{LIBXML2_VERSION}/lib/libxml2.{LIBRARY_EXT}".format(**locals()), |
| 578 |
"-DPCRE_INCLUDE_DIR={DEPS_DIR}/install/pcre-{PCRE_VERSION}/include".format(**locals()), |
| 579 |
"-DPCRE_PCREPOSIX_LIBRARY={DEPS_DIR}/install/pcre-{PCRE_VERSION}/lib/libpcreposix.{LIBRARY_EXT}".format(**locals()), |
| 580 |
"-DPCRE_PCRE_LIBRARY={DEPS_DIR}/install/pcre-{PCRE_VERSION}/lib/libpcre.{LIBRARY_EXT}".format(**locals()), |
| 581 |
"-DCMAKE_INSTALL_PREFIX={DEPS_DIR}/install/OpenCOLLADA/".format(**locals()) |
| 582 |
], |
| 583 |
download_url="https://github.com/KhronosGroup/OpenCOLLADA.git", |
| 584 |
download_name="OpenCOLLADA", |
| 585 |
download_tool=download_tool_git, |
| 586 |
revision=OPENCOLLADA_VERSION |
| 587 |
) |
| 588 |
|
| 589 |
if "python" in targets: |
| 590 |
# Python should not be built with -fvisibility=hidden, from experience that introduces segfaults |
| 591 |
OLD_CXX_FLAGS=os.environ["CXXFLAGS"] |
| 592 |
OLD_C_FLAGS=os.environ["CFLAGS"] |
| 593 |
os.environ["CXXFLAGS"]=CXXFLAGS_MINIMAL |
| 594 |
os.environ["CFLAGS"]=CFLAGS_MINIMAL |
| 595 |
|
| 596 |
# On OSX a dynamic python library is built or it would not be compatible |
| 597 |
# with the system python because of some threading initialization |
| 598 |
PYTHON_CONFIGURE_ARGS=[] |
| 599 |
if get_os() == "Darwin": |
| 600 |
PYTHON_CONFIGURE_ARGS=["--disable-static", "--enable-shared"] |
| 601 |
|
| 602 |
def get_python_unicode_confs(py_ver): |
| 603 |
if py_ver < "3.3": |
| 604 |
return [("--enable-unicode=ucs2",""), ("--enable-unicode=ucs4","u")] |
| 605 |
else: return [("","")] |
| 606 |
|
| 607 |
def PYTHON_VERSION_CONFS(): |
| 608 |
for v in PYTHON_VERSIONS: |
| 609 |
for unicode_conf, abi_tag in get_python_unicode_confs(v): |
| 610 |
yield v, unicode_conf, abi_tag |
| 611 |
|
| 612 |
for PYTHON_VERSION, unicode_conf, abi_tag in PYTHON_VERSION_CONFS(): |
| 613 |
build_dependency( |
| 614 |
"python-{PYTHON_VERSION}{abi_tag}".format(**locals()), |
| 615 |
"autoconf", |
| 616 |
PYTHON_CONFIGURE_ARGS + [unicode_conf], |
| 617 |
"http://www.python.org/ftp/python/{PYTHON_VERSION}/".format(**locals()), |
| 618 |
"Python-{PYTHON_VERSION}.tgz".format(**locals()) |
| 619 |
) |
| 620 |
|
| 621 |
os.environ["CXXFLAGS"]=OLD_CXX_FLAGS |
| 622 |
os.environ["CFLAGS"]=OLD_C_FLAGS |
| 623 |
|
| 624 |
if "boost" in targets: |
| 625 |
str_concat = lambda prefix: lambda postfix: "" if postfix.strip() == "" else "=".join((prefix, postfix.strip())) |
| 626 |
build_dependency( |
| 627 |
"boost-{BOOST_VERSION}".format(**locals()), |
| 628 |
mode="bjam", |
| 629 |
build_tool_args=[ |
| 630 |
"--stagedir={DEPS_DIR}/install/boost-{BOOST_VERSION}".format(**locals()), |
| 631 |
"--with-system", |
| 632 |
"--with-program_options", |
| 633 |
"--with-regex", |
| 634 |
"--with-thread", |
| 635 |
"--with-date_time", |
| 636 |
"--with-iostreams", |
| 637 |
"link={LINK_TYPE}".format(**locals()), |
| 638 |
] + \ |
| 639 |
BOOST_ADDRESS_MODEL + \ |
| 640 |
list(map(str_concat("cxxflags"), CXXFLAGS.strip().split(' '))) + \ |
| 641 |
list(map(str_concat("linkflags"), LDFLAGS.strip().split(' '))) + \ |
| 642 |
(["toolset=clang"] if "clang" in os.environ.get('CXX', '') else []) +\ |
| 643 |
["stage", "-s", "NO_BZIP2=1"], |
| 644 |
download_url="http://downloads.sourceforge.net/project/boost/boost/{BOOST_VERSION}/".format(**locals()), |
| 645 |
download_name="boost_{BOOST_VERSION_UNDERSCORE}.tar.bz2".format(**locals()) |
| 646 |
) |
| 647 |
|
| 648 |
if "cgal" in targets: |
| 649 |
build_dependency(name="gmp-%s" % (GMP_VERSION,), mode="autoconf", build_tool_args=["--disable-shared", "--with-pic"], download_url="https://ftp.gnu.org/gnu/gmp/", download_name="gmp-%s.tar.bz2" % (GMP_VERSION,)) |
| 650 |
build_dependency(name="mpfr-%s" % (MPFR_VERSION,), mode="autoconf", build_tool_args=["--disable-shared", "--with-gmp=%s/install/gmp-%s" % (DEPS_DIR, GMP_VERSION)], download_url="http://www.mpfr.org/mpfr-%s/" % (MPFR_VERSION,), download_name="mpfr-%s.tar.bz2" % (MPFR_VERSION,)) |
| 651 |
|
| 652 |
OLD_BUILD_CFG = BUILD_CFG |
| 653 |
if BUILD_CFG != "Debug": |
| 654 |
# CGAL only supports Debug and Release for CMAKE_BUILD_TYPE |
| 655 |
BUILD_CFG = "Release" |
| 656 |
build_dependency( |
| 657 |
name="cgal-{CGAL_VERSION}".format(**locals()), |
| 658 |
mode="cmake", |
| 659 |
# applied upstream |
| 660 |
# patch="./patches/cgal/cgal_4768.patch", |
| 661 |
build_tool_args=[ |
| 662 |
"-DGMP_LIBRARIES=%s/install/gmp-%s/lib/libgmp.a" % (DEPS_DIR, GMP_VERSION), |
| 663 |
"-DGMP_INCLUDE_DIR=%s/install/gmp-%s/include" % (DEPS_DIR, GMP_VERSION), |
| 664 |
"-DMPFR_LIBRARIES=%s/install/mpfr-%s/lib/libmpfr.a" % (DEPS_DIR, MPFR_VERSION), |
| 665 |
"-DMPFR_INCLUDE_DIR=%s/install/mpfr-%s/include" % (DEPS_DIR, MPFR_VERSION), |
| 666 |
"-DBoost_INCLUDE_DIR=%s/install/boost-%s" % (DEPS_DIR, BOOST_VERSION), |
| 667 |
"-DCMAKE_INSTALL_PREFIX=%s/install/cgal-%s/" % (DEPS_DIR, CGAL_VERSION), |
| 668 |
# for now as the IfOpSh CMakeL expects libraries, we can probably safely turn this off though |
| 669 |
"-DCGAL_HEADER_ONLY=OFF", |
| 670 |
"-DBUILD_SHARED_LIBS=Off"], |
| 671 |
download_url="https://github.com/CGAL/cgal.git", |
| 672 |
download_name="cgal", |
| 673 |
download_tool=download_tool_git, |
| 674 |
revision="v{CGAL_VERSION}".format(**locals()) |
| 675 |
) |
| 676 |
BUILD_CFG = OLD_BUILD_CFG |
| 677 |
|
| 678 |
if "voxel" in targets: |
| 679 |
build_dependency( |
| 680 |
"voxel", |
| 681 |
"cmake", |
| 682 |
build_tool_args=[ |
| 683 |
"-DIFC_SUPPORT=Off", |
| 684 |
"-DOCC_INCLUDE_DIR=" +occ_include_dir, |
| 685 |
"-DOCC_LIBRARY_DIR=" +occ_library_dir, |
| 686 |
"-DCMAKE_INSTALL_PREFIX={DEPS_DIR}/install/voxel".format(**locals()), |
| 687 |
"-DBOOST_ROOT=" "{DEPS_DIR}/install/boost-{BOOST_VERSION}".format(**locals()) |
| 688 |
], |
| 689 |
download_url="https://github.com/opensourceBIM/voxel.git", |
| 690 |
download_name="voxel", |
| 691 |
download_tool=download_tool_git, |
| 692 |
revision="master" |
| 693 |
) |
| 694 |
|
| 695 |
cecho("Building IfcOpenShell:", GREEN) |
| 696 |
|
| 697 |
IFCOS_DIR=os.path.join(DEPS_DIR, "build", "ifcopenshell") |
| 698 |
if os.path.exists(IFCOS_DIR): |
| 699 |
shutil.rmtree(IFCOS_DIR) |
| 700 |
os.makedirs(IFCOS_DIR) |
| 701 |
|
| 702 |
executables_dir = os.path.join(IFCOS_DIR, "executables") |
| 703 |
if not os.path.exists(executables_dir): |
| 704 |
os.makedirs(executables_dir) |
| 705 |
|
| 706 |
logger.info("\rConfiguring executables...") |
| 707 |
|
| 708 |
OFF_ON = ["OFF", "ON"] |
| 709 |
|
| 710 |
cmake_args=[ |
| 711 |
"-DUSE_MMAP=" "OFF", |
| 712 |
"-DBUILD_EXAMPLES=" "OFF", |
| 713 |
"-DBUILD_IFCPYTHON=" "OFF", |
| 714 |
"-DBUILD_SHARED_LIBS=" +OFF_ON[not BUILD_STATIC], |
| 715 |
"-DBUILD_IFCGEOM=" +OFF_ON["IfcGeom" in targets], |
| 716 |
"-DBUILD_GEOMSERVER=" +OFF_ON["IfcGeomServer" in targets], |
| 717 |
"-DBUILD_CONVERT=" +OFF_ON["IfcConvert" in targets], |
| 718 |
"-DCMAKE_INSTALL_PREFIX=" "{DEPS_DIR}/install/ifcopenshell".format(**locals()), |
| 719 |
"-DBOOST_ROOT=" "{DEPS_DIR}/install/boost-{BOOST_VERSION}".format(**locals()), |
| 720 |
"-DGLTF_SUPPORT=" "ON", |
| 721 |
"-DJSON_INCLUDE_DIR=" "{DEPS_DIR}/install/json".format(**locals()), |
| 722 |
"-DEIGEN_DIR=" "{DEPS_DIR}/install/eigen-3.3.7".format(**locals()) |
| 723 |
] |
| 724 |
|
| 725 |
if "occ" in targets: |
| 726 |
cmake_args.extend([ |
| 727 |
"-DOCC_INCLUDE_DIR=" +occ_include_dir, |
| 728 |
"-DOCC_LIBRARY_DIR=" +occ_library_dir |
| 729 |
]) |
| 730 |
elif "occ" in targets: |
| 731 |
cmake_args.extend([ |
| 732 |
"-DOCC_INCLUDE_DIR=" +occ_include_dir, |
| 733 |
"-DOCC_LIBRARY_DIR=" +occ_library_dir |
| 734 |
]) |
| 735 |
|
| 736 |
if "cgal" in targets: |
| 737 |
cmake_args.extend([ |
| 738 |
"-DCGAL_INCLUDE_DIR=" "{DEPS_DIR}/install/cgal-{CGAL_VERSION}/include".format(**locals()), |
| 739 |
"-DCGAL_LIBRARY_DIR=" "{DEPS_DIR}/install/cgal-{CGAL_VERSION}/lib".format(**locals()), |
| 740 |
"-DGMP_INCLUDE_DIR=" "{DEPS_DIR}/install/gmp-{GMP_VERSION}/include".format(**locals()), |
| 741 |
"-DGMP_LIBRARY_DIR=" "{DEPS_DIR}/install/gmp-{GMP_VERSION}/lib".format(**locals()), |
| 742 |
"-DMPFR_INCLUDE_DIR=" "{DEPS_DIR}/install/mpfr-{MPFR_VERSION}/include".format(**locals()), |
| 743 |
"-DMPFR_LIBRARY_DIR=" "{DEPS_DIR}/install/mpfr-{MPFR_VERSION}/lib".format(**locals()), |
| 744 |
"-DUSE_CGAL=ON" |
| 745 |
]) |
| 746 |
|
| 747 |
if "OpenCOLLADA" in targets: |
| 748 |
cmake_args.extend([ |
| 749 |
"-DOPENCOLLADA_INCLUDE_DIR=" "{DEPS_DIR}/install/OpenCOLLADA/include/opencollada".format(**locals()), |
| 750 |
"-DOPENCOLLADA_LIBRARY_DIR=" "{DEPS_DIR}/install/OpenCOLLADA/lib/opencollada".format(**locals()) |
| 751 |
]) |
| 752 |
|
| 753 |
if "pcre" in targets: |
| 754 |
cmake_args.append( |
| 755 |
"-DPCRE_LIBRARY_DIR=" "{DEPS_DIR}/install/pcre-{PCRE_VERSION}/lib".format(**locals()) |
| 756 |
) |
| 757 |
|
| 758 |
if "libxml2" in targets: |
| 759 |
cmake_args.extend([ |
| 760 |
"-DLIBXML2_INCLUDE_DIR=" "{DEPS_DIR}/install/libxml2-{LIBXML2_VERSION}/include/libxml2".format(**locals()), |
| 761 |
"-DLIBXML2_LIBRARIES=" "{DEPS_DIR}/install/libxml2-{LIBXML2_VERSION}/lib/libxml2.{LIBRARY_EXT}".format(**locals()) |
| 762 |
]) |
| 763 |
|
| 764 |
run_cmake("", cmake_args, cmake_dir=CMAKE_DIR, cwd=executables_dir) |
| 765 |
|
| 766 |
logger.info("\rBuilding executables... ") |
| 767 |
|
| 768 |
run([make, "-j{IFCOS_NUM_BUILD_PROCS}".format(**locals())], cwd=executables_dir) |
| 769 |
run([make, "install/strip" if BUILD_CFG == "Release" else "install"], cwd=executables_dir) |
| 770 |
|
| 771 |
if "IfcOpenShell-Python" in targets: |
| 772 |
|
| 773 |
# On OSX the actual Python library is not linked against. |
| 774 |
ADDITIONAL_ARGS="" |
| 775 |
if get_os() == "Darwin": |
| 776 |
ADDITIONAL_ARGS="-Wl,-flat_namespace,-undefined,suppress" |
| 777 |
|
| 778 |
os.environ["CXXFLAGS"]="%s %s" % (CXXFLAGS_MINIMAL, ADDITIONAL_ARGS) |
| 779 |
os.environ["CFLAGS"]="%s %s" % (CFLAGS_MINIMAL, ADDITIONAL_ARGS) |
| 780 |
os.environ["LDFLAGS"]="%s %s" % (LDFLAGS, ADDITIONAL_ARGS) |
| 781 |
|
| 782 |
for PYTHON_VERSION, _, TAG in PYTHON_VERSION_CONFS(): |
| 783 |
logger.info("\rConfiguring python {PYTHON_VERSION}{TAG} wrapper...".format(**locals())) |
| 784 |
|
| 785 |
python_dir = os.path.join(IFCOS_DIR, "python-{PYTHON_VERSION}{TAG}".format(**locals())) |
| 786 |
if not os.path.exists(python_dir): |
| 787 |
os.makedirs(python_dir) |
| 788 |
|
| 789 |
PYTHON_LIBRARY=run([bash, "-c", "ls {DEPS_DIR}/install/python-{PYTHON_VERSION}{TAG}/lib/libpython*.*".format(**locals())]) |
| 790 |
PYTHON_INCLUDE=run([bash, "-c", "ls -d {DEPS_DIR}/install/python-{PYTHON_VERSION}{TAG}/include/python*".format(**locals())]) |
| 791 |
PYTHON_EXECUTABLE=os.path.join(DEPS_DIR, "install", "python-{PYTHON_VERSION}{TAG}".format(**locals()), "bin", "python{PYTHON_VERSION[0]}".format(**locals())) |
| 792 |
os.environ["PYTHON_LIBRARY_BASENAME"]=os.path.basename(PYTHON_LIBRARY) |
| 793 |
|
| 794 |
run_cmake("", |
| 795 |
cmake_args=[ |
| 796 |
"-DBUILD_SHARED_LIBS=" "OFF" if BUILD_STATIC else "ON", |
| 797 |
"-DBOOST_ROOT=" "{DEPS_DIR}/install/boost-{BOOST_VERSION}".format(**locals()), |
| 798 |
"-DOCC_INCLUDE_DIR=" +occ_include_dir, |
| 799 |
"-DOCC_LIBRARY_DIR=" +occ_library_dir, |
| 800 |
"-DPYTHON_LIBRARY=" +PYTHON_LIBRARY, |
| 801 |
"-DPYTHON_EXECUTABLE=" +PYTHON_EXECUTABLE, |
| 802 |
"-DPYTHON_INCLUDE_DIR=" +PYTHON_INCLUDE, |
| 803 |
"-DUSE_CGAL=ON", |
| 804 |
"-DEIGEN_DIR=" "{DEPS_DIR}/install/eigen-3.3.7".format(**locals()), |
| 805 |
"-DSWIG_EXECUTABLE=" "{DEPS_DIR}/install/swig/bin/swig".format(**locals()), |
| 806 |
"-DCMAKE_INSTALL_PREFIX=" "{DEPS_DIR}/install/ifcopenshell/tmp".format(**locals()), |
| 807 |
"-DLIBXML2_INCLUDE_DIR=" "{DEPS_DIR}/install/libxml2-{LIBXML2_VERSION}/include/libxml2".format(**locals()), |
| 808 |
"-DLIBXML2_LIBRARIES=" "{DEPS_DIR}/install/libxml2-{LIBXML2_VERSION}/lib/libxml2.{LIBRARY_EXT}".format(**locals()), |
| 809 |
"-DCOLLADA_SUPPORT=OFF" |
| 810 |
], cmake_dir=CMAKE_DIR, cwd=python_dir) |
| 811 |
|
| 812 |
logger.info("\rBuilding python %s%s wrapper... " % (PYTHON_VERSION, TAG)) |
| 813 |
|
| 814 |
run([make, "-j%s" % (IFCOS_NUM_BUILD_PROCS,), "_ifcopenshell_wrapper"], cwd=python_dir) |
| 815 |
run([make, "install/local"], cwd=os.path.join(python_dir, "ifcwrap")) |
| 816 |
|
| 817 |
module_dir = os.path.dirname(run([PYTHON_EXECUTABLE, "-c", "from __future__ import print_function; import inspect, ifcopenshell; print(inspect.getfile(ifcopenshell))"])) |
| 818 |
|
| 819 |
if get_os() != "Darwin": |
| 820 |
# TODO: This symbol name depends on the Python version? |
| 821 |
run([strip, "-s", "-K", "PyInit__ifcopenshell_wrapper", "_ifcopenshell_wrapper.so"], cwd=module_dir) |
| 822 |
|
| 823 |
run([cp, "-R", module_dir, os.path.join(DEPS_DIR, "install", "ifcopenshell", "python-%s%s" % (PYTHON_VERSION, TAG))]) |
| 824 |
|
| 825 |
logger.info("\rBuilt IfcOpenShell...\n\n") |