mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 14:31:39 +00:00
build-all: support --occt-shared
This commit is contained in:
+39
-13
@@ -205,6 +205,7 @@ class Args(NamedTuple):
|
|||||||
verbose: bool
|
verbose: bool
|
||||||
shared: bool
|
shared: bool
|
||||||
ifcopenshell_shared: bool
|
ifcopenshell_shared: bool
|
||||||
|
occt_shared: bool
|
||||||
mac_cross_compile_intel: bool
|
mac_cross_compile_intel: bool
|
||||||
wasm: bool
|
wasm: bool
|
||||||
|
|
||||||
@@ -295,6 +296,12 @@ def parse_args() -> tuple[Args, DynamicArgs]:
|
|||||||
help="Build only IfcOpenShell's own libraries as shared (dependencies stay static). "
|
help="Build only IfcOpenShell's own libraries as shared (dependencies stay static). "
|
||||||
"Redundant if -shared is also passed.",
|
"Redundant if -shared is also passed.",
|
||||||
)
|
)
|
||||||
|
arg_parser.add_argument(
|
||||||
|
"--occt-shared",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Build OCCT as shared. Redundant if -shared is also passed.",
|
||||||
|
)
|
||||||
arg_parser.add_argument(
|
arg_parser.add_argument(
|
||||||
"-mac-cross-compile-intel",
|
"-mac-cross-compile-intel",
|
||||||
"--mac-cross-compile-intel",
|
"--mac-cross-compile-intel",
|
||||||
@@ -311,7 +318,8 @@ def parse_args() -> tuple[Args, DynamicArgs]:
|
|||||||
lto=namespace.lto,
|
lto=namespace.lto,
|
||||||
verbose=namespace.verbose,
|
verbose=namespace.verbose,
|
||||||
shared=namespace.shared,
|
shared=namespace.shared,
|
||||||
ifcopenshell_shared=namespace.ifcopenshell_shared,
|
ifcopenshell_shared=namespace.ifcopenshell_shared or namespace.shared,
|
||||||
|
occt_shared=namespace.occt_shared or namespace.shared,
|
||||||
mac_cross_compile_intel=namespace.mac_cross_compile_intel,
|
mac_cross_compile_intel=namespace.mac_cross_compile_intel,
|
||||||
wasm=namespace.wasm,
|
wasm=namespace.wasm,
|
||||||
)
|
)
|
||||||
@@ -520,12 +528,9 @@ else:
|
|||||||
OFF_ON = ["OFF", "ON"]
|
OFF_ON = ["OFF", "ON"]
|
||||||
BUILD_STATIC = not ARGS.shared
|
BUILD_STATIC = not ARGS.shared
|
||||||
"""Whether dependencies are built static."""
|
"""Whether dependencies are built static."""
|
||||||
IFCOPENSHELL_STATIC = BUILD_STATIC and not ARGS.ifcopenshell_shared
|
|
||||||
"""Whether IfcOpenShell's own libraries are built static."""
|
|
||||||
ENABLE_FLAG = "--enable-static" if BUILD_STATIC else "--enable-shared"
|
ENABLE_FLAG = "--enable-static" if BUILD_STATIC else "--enable-shared"
|
||||||
DISABLE_FLAG = "--disable-shared" if BUILD_STATIC else "--disable-static"
|
DISABLE_FLAG = "--disable-shared" if BUILD_STATIC else "--disable-static"
|
||||||
LINK_TYPE = "static" if BUILD_STATIC else "shared"
|
LINK_TYPE = "static" if BUILD_STATIC else "shared"
|
||||||
LINK_TYPE_UCFIRST = LINK_TYPE.capitalize()
|
|
||||||
LIBRARY_EXT = "a" if BUILD_STATIC else "so"
|
LIBRARY_EXT = "a" if BUILD_STATIC else "so"
|
||||||
PIC = "-fPIC" if BUILD_STATIC else ""
|
PIC = "-fPIC" if BUILD_STATIC else ""
|
||||||
|
|
||||||
@@ -1039,6 +1044,8 @@ ADDITIONAL_ARGS_STR = " ".join(ADDITIONAL_ARGS)
|
|||||||
|
|
||||||
CXXFLAGS_MINIMAL = f"{CXXFLAGS} {PIC} {ADDITIONAL_ARGS_STR}"
|
CXXFLAGS_MINIMAL = f"{CXXFLAGS} {PIC} {ADDITIONAL_ARGS_STR}"
|
||||||
CFLAGS_MINIMAL = f"{CFLAGS} {PIC} {ADDITIONAL_ARGS_STR}"
|
CFLAGS_MINIMAL = f"{CFLAGS} {PIC} {ADDITIONAL_ARGS_STR}"
|
||||||
|
CXXFLAGS_SHARED = CXXFLAGS_MINIMAL
|
||||||
|
CFLAGS_SHARED = CFLAGS_MINIMAL
|
||||||
if WASM:
|
if WASM:
|
||||||
# WASM `SIDE_MODULE_` are absorbed by `emcmake` automatically.
|
# WASM `SIDE_MODULE_` are absorbed by `emcmake` automatically.
|
||||||
CXXFLAGS = CXXFLAGS_MINIMAL
|
CXXFLAGS = CXXFLAGS_MINIMAL
|
||||||
@@ -1048,16 +1055,16 @@ elif sp.call([bash, "-c", "ld --gc-sections 2>&1 | grep -- --gc-sections &> /dev
|
|||||||
CXXFLAGS = f"{CXXFLAGS} {PIC} -fdata-sections -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden {ADDITIONAL_ARGS_STR}"
|
CXXFLAGS = f"{CXXFLAGS} {PIC} -fdata-sections -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden {ADDITIONAL_ARGS_STR}"
|
||||||
CFLAGS = f"{CFLAGS} {PIC} -fdata-sections -ffunction-sections -fvisibility=hidden {ADDITIONAL_ARGS_STR}"
|
CFLAGS = f"{CFLAGS} {PIC} -fdata-sections -ffunction-sections -fvisibility=hidden {ADDITIONAL_ARGS_STR}"
|
||||||
else:
|
else:
|
||||||
CXXFLAGS = CXXFLAGS_MINIMAL
|
CXXFLAGS = CXXFLAGS_SHARED
|
||||||
CFLAGS = CFLAGS_MINIMAL
|
CFLAGS = CFLAGS_SHARED
|
||||||
LDFLAGS = f"{LDFLAGS} -Wl,--gc-sections {ADDITIONAL_ARGS_STR}"
|
LDFLAGS = f"{LDFLAGS} -Wl,--gc-sections {ADDITIONAL_ARGS_STR}"
|
||||||
else:
|
else:
|
||||||
if BUILD_STATIC:
|
if BUILD_STATIC:
|
||||||
CXXFLAGS = f"{CXXFLAGS} {PIC} -fvisibility=hidden -fvisibility-inlines-hidden {ADDITIONAL_ARGS_STR}"
|
CXXFLAGS = f"{CXXFLAGS} {PIC} -fvisibility=hidden -fvisibility-inlines-hidden {ADDITIONAL_ARGS_STR}"
|
||||||
CFLAGS = f"{CFLAGS} {PIC} -fvisibility=hidden -fvisibility-inlines-hidden {ADDITIONAL_ARGS_STR}"
|
CFLAGS = f"{CFLAGS} {PIC} -fvisibility=hidden -fvisibility-inlines-hidden {ADDITIONAL_ARGS_STR}"
|
||||||
else:
|
else:
|
||||||
CXXFLAGS = CXXFLAGS_MINIMAL
|
CXXFLAGS = CXXFLAGS_SHARED
|
||||||
CFLAGS = CFLAGS_MINIMAL
|
CFLAGS = CFLAGS_SHARED
|
||||||
LDFLAGS = f"{LDFLAGS} {ADDITIONAL_ARGS_STR}"
|
LDFLAGS = f"{LDFLAGS} {ADDITIONAL_ARGS_STR}"
|
||||||
|
|
||||||
if ARGS.lto:
|
if ARGS.lto:
|
||||||
@@ -1143,6 +1150,9 @@ if "swig" in targets:
|
|||||||
if USE_OCCT and "occ" in targets:
|
if USE_OCCT and "occ" in targets:
|
||||||
occt_args: list[str] = []
|
occt_args: list[str] = []
|
||||||
patches: list[str] = []
|
patches: list[str] = []
|
||||||
|
occt_link_type = "Shared" if ARGS.occt_shared else "Static"
|
||||||
|
occt_name = f"occt-shared-{OCCT_VERSION}" if ARGS.occt_shared else f"occt-{OCCT_VERSION}"
|
||||||
|
OCCT_INSTALL_PATH = f"{DEPS_DIR}/install/{occt_name}"
|
||||||
if OCCT_VERSION < "7.4":
|
if OCCT_VERSION < "7.4":
|
||||||
patches.append("./patches/occt/enable-exception-handling.patch")
|
patches.append("./patches/occt/enable-exception-handling.patch")
|
||||||
|
|
||||||
@@ -1157,12 +1167,23 @@ if USE_OCCT and "occ" in targets:
|
|||||||
if WASM:
|
if WASM:
|
||||||
patches.append("./patches/occt/no_em_js.patch")
|
patches.append("./patches/occt/no_em_js.patch")
|
||||||
|
|
||||||
|
if ARGS.occt_shared:
|
||||||
|
# Using static flags for shared builds break it
|
||||||
|
# (e.g. `-fvisibility=hidden` hides many symbols).
|
||||||
|
# So we temporarily override flags.
|
||||||
|
OLD_CPP_FLAGS = os.environ["CPPFLAGS"]
|
||||||
|
OLD_CXX_FLAGS = os.environ["CXXFLAGS"]
|
||||||
|
OLD_C_FLAGS = os.environ["CFLAGS"]
|
||||||
|
os.environ["CXXFLAGS"] = CXXFLAGS_SHARED
|
||||||
|
os.environ["CPPFLAGS"] = CXXFLAGS_SHARED
|
||||||
|
os.environ["CFLAGS"] = CFLAGS_SHARED
|
||||||
|
|
||||||
build_dependency(
|
build_dependency(
|
||||||
name=f"occt-{OCCT_VERSION}",
|
name=occt_name,
|
||||||
mode="cmake",
|
mode="cmake",
|
||||||
build_tool_args=[
|
build_tool_args=[
|
||||||
f"-DINSTALL_DIR={DEPS_DIR}/install/occt-{OCCT_VERSION}",
|
f"-DINSTALL_DIR={OCCT_INSTALL_PATH}",
|
||||||
f"-DBUILD_LIBRARY_TYPE={LINK_TYPE_UCFIRST}",
|
f"-DBUILD_LIBRARY_TYPE={occt_link_type}",
|
||||||
f"-DBUILD_MODULE_Draw=0",
|
f"-DBUILD_MODULE_Draw=0",
|
||||||
f"-DBUILD_RELEASE_DISABLE_EXCEPTIONS=Off",
|
f"-DBUILD_RELEASE_DISABLE_EXCEPTIONS=Off",
|
||||||
# Disable xlib explicitly, as it tries to use it on Desktop Ubuntu, adding unnecessary dependency.
|
# Disable xlib explicitly, as it tries to use it on Desktop Ubuntu, adding unnecessary dependency.
|
||||||
@@ -1181,6 +1202,11 @@ if USE_OCCT and "occ" in targets:
|
|||||||
patch=patches,
|
patch=patches,
|
||||||
revision="V" + OCCT_VERSION.replace(".", "_"),
|
revision="V" + OCCT_VERSION.replace(".", "_"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if ARGS.occt_shared:
|
||||||
|
restore_env("CPPFLAGS", OLD_CPP_FLAGS)
|
||||||
|
restore_env("CXXFLAGS", OLD_CXX_FLAGS)
|
||||||
|
restore_env("CFLAGS", OLD_C_FLAGS)
|
||||||
elif "occ" in targets:
|
elif "occ" in targets:
|
||||||
build_dependency(
|
build_dependency(
|
||||||
name=f"oce-{OCE_VERSION}",
|
name=f"oce-{OCE_VERSION}",
|
||||||
@@ -1554,7 +1580,7 @@ os.makedirs(ifcos_build_dir, exist_ok=True)
|
|||||||
cmake_args = [
|
cmake_args = [
|
||||||
"-DUSE_MMAP=OFF",
|
"-DUSE_MMAP=OFF",
|
||||||
f"-DBUILD_EXAMPLES={OFF_ON[ARGS.build_examples]}",
|
f"-DBUILD_EXAMPLES={OFF_ON[ARGS.build_examples]}",
|
||||||
"-DBUILD_SHARED_LIBS=" + OFF_ON[not IFCOPENSHELL_STATIC],
|
"-DBUILD_SHARED_LIBS=" + OFF_ON[ARGS.ifcopenshell_shared],
|
||||||
"-DGLTF_SUPPORT=ON",
|
"-DGLTF_SUPPORT=ON",
|
||||||
"-DBoost_NO_BOOST_CMAKE=On",
|
"-DBoost_NO_BOOST_CMAKE=On",
|
||||||
"-DCREATE_BUNDLE=On",
|
"-DCREATE_BUNDLE=On",
|
||||||
@@ -1599,7 +1625,7 @@ if "cgal" in targets:
|
|||||||
cmake_args.append(f"-DCGAL_WITH_GMPXX=Off")
|
cmake_args.append(f"-DCGAL_WITH_GMPXX=Off")
|
||||||
|
|
||||||
if "occ" in targets and USE_OCCT:
|
if "occ" in targets and USE_OCCT:
|
||||||
cmake_args_prefix_path.append(f"{DEPS_DIR}/install/occt-{OCCT_VERSION}")
|
cmake_args_prefix_path.append(OCCT_INSTALL_PATH)
|
||||||
|
|
||||||
elif "occ" in targets:
|
elif "occ" in targets:
|
||||||
# We don't support find_package for OCE.
|
# We don't support find_package for OCE.
|
||||||
|
|||||||
Reference in New Issue
Block a user