Skip to content

Commit

Permalink
* add pymake function to add syslibs option for Darwin + gcc toolchai…
Browse files Browse the repository at this point in the history
…n + CLT > 14.*
  • Loading branch information
jdhughes-usgs committed Jun 10, 2024
1 parent 61971f5 commit 44c7ff0
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
8 changes: 4 additions & 4 deletions autotest/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def test_build(function_tmpdir, target: str) -> None:
pm.target = target
pm.inplace = True
fc = os.environ.get("FC", "gfortran")
if system() == "Darwin" and fc == "gfortran":
pm.syslibs = "-Wl,-ld_classic"
# if system() == "Darwin" and fc == "gfortran":
# pm.syslibs = "-Wl,-ld_classic"
assert (
pymake.build_apps(
target,
Expand Down Expand Up @@ -116,8 +116,8 @@ def test_makefile_build(function_tmpdir, target: str) -> None:
pm.dryrun = True
pm.makeclean = False
fc = os.environ.get("FC", "gfortran")
if system() == "Darwin" and fc == "gfortran":
pm.syslibs = "-Wl,-ld_classic"
# if system() == "Darwin" and fc == "gfortran":
# pm.syslibs = "-Wl,-ld_classic"

with set_dir(function_tmpdir):
pm.download_target(target)
Expand Down
2 changes: 1 addition & 1 deletion autotest/test_cli_cmds.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
import pathlib as pl
import subprocess
from platform import system

import pytest
from flaky import flaky
from modflow_devtools.misc import set_dir, set_env
from platform import system

RERUNS = 3

Expand Down
4 changes: 2 additions & 2 deletions autotest/test_gridgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def pm(module_tmpdir, target) -> pymake.Pymake:
pm.appdir = str(module_tmpdir)
pm.cc = environ.get("CXX", "g++")
pm.fc = None
if system() == "Darwin" and pm.cc == "g++":
pm.syslibs = "-Wl,-ld_classic"
# if system() == "Darwin" and pm.cc == "g++":
# pm.syslibs = "-Wl,-ld_classic"
pm.inplace = True
pm.makeclean = True
yield pm
Expand Down
4 changes: 2 additions & 2 deletions autotest/test_mf6_existing_meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def pm(workspace, targets) -> pymake.Pymake:
pm.target = str(targets[0])
pm.appdir = str(workspace / "bin")
pm.fc = os.environ.get("FC", "gfortran")
if system() == "Darwin" and pm.fc == "gfortran":
pm.syslibs = "-Wl,-ld_classic"
# if system() == "Darwin" and pm.fc == "gfortran":
# pm.syslibs = "-Wl,-ld_classic"
pm.meson = True
pm.makeclean = True
pm.mesondir = str(workspace)
Expand Down
45 changes: 45 additions & 0 deletions pymake/utils/_compiler_switches.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
import sys
from subprocess import check_output

from ._compiler_language_files import (
_get_c_files,
Expand Down Expand Up @@ -970,6 +971,10 @@ def _set_syslibs(
# set default syslibs
if default_syslibs:
syslibs.append("-lc")

darwin_options = _darwin_syslibs(cc, fc, verbose)
if darwin_options is not None:
syslibs.append(darwin_options)

# add additional syslibs for select programs
if target == "triangle":
Expand Down Expand Up @@ -1033,3 +1038,43 @@ def _get_os_macro(osname=None):
else:
os_macro = None
return os_macro


def _darwin_syslibs(cc, fc, verbose=False):
"""Get additional syslibs for Darwin systems using gcc
tool chain and command line tools greater than 14
Parameters
----------
cc : str
c compiler
fc : str
fortran compiler
verbose : bool
boolean for verbose output to terminal
Returns
-------
linker_str : str
additiona; linker flags for darwin systems. Default is None
"""
linker_str = None
if _get_osname() == "darwin":
if cc in ("gcc", "g++",) or fc in ("gfortran",):
cmd = ["pkgutil", "--pkg-info=com.apple.pkg.CLTools_Executables"]
out_lines = check_output(cmd).decode("utf-8").splitlines()
version = None
tag = "version: "
for line in out_lines:
if line.startswith(tag):
version = line.replace(tag, "")
break
if version is not None:
major = int(version.split(".")[0])
if major > 14:
linker_str = "-Wl,-ld_classic"
if verbose:
print(f"C/C++ compiler: {cc} \nFortran compiler: {fc}")
print(f"Command line tools version: {version}")
print(f"Command line tools major version number: {major}")
return linker_str

0 comments on commit 44c7ff0

Please sign in to comment.