2022-11-24 09:53:12 -06:00
|
|
|
import os
|
|
|
|
import platform
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import sysconfig
|
|
|
|
from distutils.version import LooseVersion
|
2022-12-01 19:04:37 -06:00
|
|
|
from distutils.dir_util import copy_tree
|
2022-11-24 09:53:12 -06:00
|
|
|
from typing import Any, Dict
|
|
|
|
|
|
|
|
from setuptools.command.build_ext import build_ext
|
|
|
|
from setuptools.extension import Extension
|
|
|
|
|
|
|
|
|
|
|
|
class CMakeExtension(Extension):
|
|
|
|
name: str # exists, even though IDE doesn't find it
|
|
|
|
|
|
|
|
def __init__(self, name: str, sourcedir: str="") -> None:
|
|
|
|
super().__init__(name, sources=[])
|
|
|
|
self.sourcedir = os.path.abspath(sourcedir)
|
|
|
|
self.sourcedir_rel = sourcedir
|
|
|
|
|
|
|
|
|
|
|
|
class ExtensionBuilder(build_ext):
|
|
|
|
def run(self) -> None:
|
|
|
|
self.validate_cmake()
|
|
|
|
super().run()
|
|
|
|
|
|
|
|
def build_extension(self, ext: Extension) -> None:
|
|
|
|
if isinstance(ext, CMakeExtension):
|
|
|
|
self.build_cmake_extension(ext)
|
|
|
|
else:
|
|
|
|
super().build_extension(ext)
|
|
|
|
|
|
|
|
def validate_cmake(self) -> None:
|
|
|
|
cmake_extensions = [x for x in self.extensions if isinstance(x, CMakeExtension)]
|
|
|
|
if len(cmake_extensions) > 0:
|
|
|
|
try:
|
|
|
|
out = subprocess.check_output(["cmake", "--version"])
|
|
|
|
except OSError:
|
2022-11-27 11:28:15 -06:00
|
|
|
raise RuntimeError(
|
2022-11-24 09:53:12 -06:00
|
|
|
"CMake must be installed to build the following extensions: "
|
|
|
|
+ ", ".join(e.name for e in cmake_extensions)
|
|
|
|
)
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
cmake_version = LooseVersion(re.search(r"version\s*([\d.]+)", out.decode()).group(1)) # type: ignore
|
|
|
|
if cmake_version < "3.1.0":
|
|
|
|
raise RuntimeError("CMake >= 3.1.0 is required on Windows")
|
|
|
|
|
|
|
|
def build_cmake_extension(self, ext: CMakeExtension) -> None:
|
|
|
|
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
|
2022-11-25 20:41:26 -06:00
|
|
|
cmake_args = []
|
2022-11-24 09:53:12 -06:00
|
|
|
|
|
|
|
cfg = "Debug" if self.debug else "Release"
|
|
|
|
# cfg = 'Debug'
|
|
|
|
build_args = ["--config", cfg]
|
|
|
|
install_args = ["--config", cfg]
|
|
|
|
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
if sys.maxsize > 2 ** 32:
|
|
|
|
cmake_args += ["-A", "x64"]
|
|
|
|
build_args += ["--", "/m"]
|
|
|
|
else:
|
|
|
|
cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg]
|
|
|
|
build_args += ["--", "-j4", "VERBOSE=1"]
|
|
|
|
cmake_args += ["-DPYTHON_INCLUDE_DIR={}".format(sysconfig.get_path("include"))]
|
|
|
|
|
|
|
|
env = os.environ.copy()
|
|
|
|
env["CXXFLAGS"] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get("CXXFLAGS", ""), self.distribution.get_version())
|
|
|
|
|
|
|
|
build_dir = os.path.join(self.build_temp, ext.sourcedir_rel)
|
|
|
|
os.makedirs(build_dir,exist_ok=True)
|
|
|
|
|
|
|
|
cmake_args += [f"-DCMAKE_MODULE_PATH={os.path.abspath('bootstrap/cmake_modules')};"
|
2022-11-25 20:41:26 -06:00
|
|
|
f"{os.path.join(extdir, 'share/cmake/Modules')}"]
|
|
|
|
cmake_args += [f"-DCMAKE_INSTALL_PREFIX={extdir}"]
|
2022-11-24 09:53:12 -06:00
|
|
|
cmake_args += [f"-DPython_CORIOLISLIB={extdir}"]
|
|
|
|
cmake_args += [f"-DPython_CORIOLISARCH={extdir}"]
|
2022-11-25 20:41:26 -06:00
|
|
|
cmake_args += [f"-DSYS_CONF_DIR={extdir}"]
|
|
|
|
cmake_args += [f"-DCORIOLIS_TOP={extdir}"]
|
|
|
|
cmake_args += [f"-DCORIOLIS_USER_TOP={extdir}"]
|
|
|
|
cmake_args += [f"-DPOETRY=1"]
|
|
|
|
cmake_args += [f"-DWITH_QT5=1"]
|
2022-11-27 11:28:15 -06:00
|
|
|
cmake_args += [f"-DCMAKE_BUILD_RPATH_USE_ORIGIN=1"]
|
|
|
|
cmake_args += ["-DCMAKE_SKIP_BUILD_RPATH=FALSE"]
|
|
|
|
cmake_args += ["-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"]
|
|
|
|
cmake_args += ["-DCMAKE_INSTALL_RPATH=\${ORIGIN}/lib"]
|
|
|
|
cmake_args += ["-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE"]
|
2022-11-24 09:53:12 -06:00
|
|
|
|
|
|
|
subprocess.check_call(["cmake", "--debug-find", "--trace-redirect=build.cmake.trace", "--trace-expand", ext.sourcedir] + cmake_args, cwd=build_dir, env=env)
|
|
|
|
subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=build_dir)
|
2022-11-25 20:41:26 -06:00
|
|
|
subprocess.check_call(["cmake", "--install", ".", "--prefix", extdir] + install_args, cwd=build_dir)
|
2022-12-01 19:04:37 -06:00
|
|
|
copy_tree(os.path.join(extdir, "bin"), "Coriolis/data/bin")
|
2022-11-24 09:53:12 -06:00
|
|
|
|
|
|
|
def build(setup_kwargs: Dict[str, Any]) -> None:
|
2022-11-25 20:41:26 -06:00
|
|
|
cmake_modules = [
|
2022-11-27 11:28:15 -06:00
|
|
|
CMakeExtension("coloquinte", sourcedir="coloquinte"),
|
|
|
|
CMakeExtension("Hurricane", sourcedir="hurricane"),
|
|
|
|
CMakeExtension("crlcore", sourcedir="crlcore"),
|
|
|
|
CMakeExtension("flute", sourcedir="flute"),
|
|
|
|
CMakeExtension("etesian", sourcedir="etesian"),
|
|
|
|
CMakeExtension("anabatic", sourcedir="anabatic"),
|
|
|
|
CMakeExtension("katana", sourcedir="katana"),
|
|
|
|
CMakeExtension("equinox", sourcedir="equinox"),
|
|
|
|
CMakeExtension("solstice", sourcedir="solstice"),
|
|
|
|
CMakeExtension("oroshi", sourcedir="oroshi"),
|
|
|
|
CMakeExtension("bora", sourcedir="bora"),
|
|
|
|
CMakeExtension("karakaze", sourcedir="karakaze"),
|
|
|
|
#CMakeExtension("knik", sourcedir="knik"),
|
|
|
|
#CMakeExtension("unicorn", sourcedir="unicorn"),
|
|
|
|
CMakeExtension("tutorial", sourcedir="tutorial"),
|
|
|
|
CMakeExtension("cumulus", sourcedir="cumulus"),
|
|
|
|
CMakeExtension("stratus1", sourcedir="stratus1"),
|
|
|
|
CMakeExtension("documentation", sourcedir="documentation"),
|
|
|
|
CMakeExtension("unittests", sourcedir="unittests")
|
2022-11-25 20:41:26 -06:00
|
|
|
]
|
|
|
|
|
2022-11-24 09:53:12 -06:00
|
|
|
ext_modules = cmake_modules
|
|
|
|
setup_kwargs.update(
|
|
|
|
{
|
|
|
|
"ext_modules": ext_modules,
|
|
|
|
"cmdclass": dict(build_ext=ExtensionBuilder),
|
|
|
|
"zip_safe": False,
|
|
|
|
}
|
|
|
|
)
|