Skip to content

Commit

Permalink
build: only apply -static if working (fails on mac)
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Apr 13, 2020
1 parent 468e25a commit b004aa8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
20 changes: 18 additions & 2 deletions iri2016/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ DESCRIPTION "IRI2016 command line driver"
HOMEPAGE_URL https://github.com/space-physics/iri2016)
enable_testing()

# --- compiler options

include(CheckFortranCompilerFlag)
include(CheckFortranSourceCompiles)
check_fortran_compiler_flag(-w nowarn)

set(OLD_FLAGS)
Expand All @@ -17,11 +20,24 @@ if(nowarn)
endif()

if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
string(APPEND CMAKE_Fortran_FLAGS " -std=legacy -static")
set(CMAKE_REQUIRED_FLAGS -static)
check_fortran_source_compiles("end" static_ok SRC_EXT f90)

string(APPEND CMAKE_Fortran_FLAGS " -std=legacy")
if(static_ok)
string(APPEND CMAKE_Fortran_FLAGS " -static")
endif()

elseif(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
string(APPEND CMAKE_Fortran_FLAGS " -static-intel")
set(CMAKE_REQUIRED_FLAGS -static-intel)
check_fortran_source_compiles("end" static_ok SRC_EXT f90)
if(static_ok)
string(APPEND CMAKE_Fortran_FLAGS " -static-intel")
endif()
endif()

# --- main program

add_subdirectory(src)

add_executable(iri2016_driver src/iri2016_driver.f90)
Expand Down
17 changes: 9 additions & 8 deletions iri2016/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ def build(src_dir: Path = SRCDIR, bin_dir: Path = BINDIR, build_sys: str = "cmak
if build_sys == "meson":
meson_setup(src_dir, bin_dir)
elif build_sys == "cmake":
if not check_cmake_version("3.13"):
raise ValueError("Need at least CMake 3.13")
cmake_setup(src_dir, bin_dir)
else:
raise ValueError("Unknown build system {}".format(build_sys))
Expand All @@ -36,9 +34,9 @@ def cmake_setup(src_dir: Path, bin_dir: Path):
"""
attempt to build using CMake >= 3
"""
cmake_exe = shutil.which("cmake")
if not cmake_exe:
raise FileNotFoundError("CMake not available")

cmake_exe = check_cmake_version("3.13")

cfgfn = bin_dir / "CMakeCache.txt"
if cfgfn.is_file():
cfgfn.unlink()
Expand Down Expand Up @@ -68,17 +66,20 @@ def meson_setup(src_dir: Path, bin_dir: Path):
subprocess.run([meson_exe, "test", "-C", str(bin_dir)])


def check_cmake_version(min_version: str) -> bool:
def check_cmake_version(min_version: str) -> str:
cmake = shutil.which("cmake")
if not cmake:
return False
raise FileNotFoundError("CMake not found")

cmake_version = subprocess.check_output([cmake, "--version"], universal_newlines=True).split()[2]

pmin = pkg_resources.parse_version(min_version)
pcmake = pkg_resources.parse_version(cmake_version)

return pcmake >= pmin
if pcmake < pmin:
raise ValueError(f"CMake {cmake_version} < {min_version}")

return cmake


def get_libpath(bin_dir: Path, stem: str) -> Path:
Expand Down
6 changes: 0 additions & 6 deletions iri2016/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ project('iri2016', 'fortran',

fc = meson.get_compiler('fortran')

if fc.get_id() == 'gcc'
add_project_arguments('-static', language: 'fortran')
elif fc.get_id() == 'intel'
add_project_arguments('-static-intel', language: 'fortran')
endif

subdir('src')

driver = executable('iri2016_driver',
Expand Down

0 comments on commit b004aa8

Please sign in to comment.