xref: /libCEED/python/build_ceed_cffi.py (revision 1d83af800c39d52e8338743310d4d813bfba9d04)
17b8bbb42Svaleriabarra# Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
27b8bbb42Svaleriabarra# the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
37b8bbb42Svaleriabarra# reserved. See files LICENSE and NOTICE for details.
47b8bbb42Svaleriabarra#
57b8bbb42Svaleriabarra# This file is part of CEED, a collection of benchmarks, miniapps, software
67b8bbb42Svaleriabarra# libraries and APIs for efficient high-order finite element and spectral
77b8bbb42Svaleriabarra# element discretizations for exascale applications. For more information and
87b8bbb42Svaleriabarra# source code availability see http://github.com/ceed.
97b8bbb42Svaleriabarra#
107b8bbb42Svaleriabarra# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
117b8bbb42Svaleriabarra# a collaborative effort of two U.S. Department of Energy organizations (Office
127b8bbb42Svaleriabarra# of Science and the National Nuclear Security Administration) responsible for
137b8bbb42Svaleriabarra# the planning and preparation of a capable exascale ecosystem, including
147b8bbb42Svaleriabarra# software, applications, hardware, advanced system engineering and early
157b8bbb42Svaleriabarra# testbed platforms, in support of the nation's exascale computing imperative.
167b8bbb42Svaleriabarra
177b8bbb42Svaleriabarraimport os
187b8bbb42Svaleriabarrafrom cffi import FFI
197b8bbb42Svaleriabarraffibuilder = FFI()
207b8bbb42Svaleriabarra
217b8bbb42Svaleriabarra# ------------------------------------------------------------------------------
227b8bbb42Svaleriabarra# Provide C definitions to CFFI
237b8bbb42Svaleriabarra# ------------------------------------------------------------------------------
247b8bbb42Svaleriabarrawith open(os.path.abspath("include/ceed.h")) as f:
257b8bbb42Svaleriabarra    lines = [line.strip() for line in f if
267b8bbb42Svaleriabarra               not line.startswith("#") and
277b8bbb42Svaleriabarra               not line.startswith("  static") and
287b8bbb42Svaleriabarra               "CeedErrorImpl" not in line and
297b8bbb42Svaleriabarra               "const char *, ...);" not in line and
307b8bbb42Svaleriabarra               not line.startswith("CEED_EXTERN const char *const")]
317b8bbb42Svaleriabarra    lines = [line.replace("CEED_EXTERN", "extern") for line in lines]
32*1d83af80SJed Brown    header = '\n'.join(lines)
337b8bbb42Svaleriabarra    header = header.split("static inline CeedInt CeedIntPow", 1)[0]
347b8bbb42Svaleriabarraffibuilder.cdef(header)
357b8bbb42Svaleriabarra
367b8bbb42Svaleriabarra# ------------------------------------------------------------------------------
377b8bbb42Svaleriabarra# Set source of libCEED header file
387b8bbb42Svaleriabarra# ------------------------------------------------------------------------------
39c794122cSjeremyltceed_dir = os.getenv("CEED_DIR", None)
40c794122cSjeremyltif ceed_dir:
41c794122cSjeremylt  ceed_lib_dirs = [os.path.abspath("lib"), os.path.join(ceed_dir, "lib")]
42c794122cSjeremyltelse:
43c794122cSjeremylt  ceed_lib_dirs = [os.path.abspath("lib")]
44c794122cSjeremylt
457b8bbb42Svaleriabarraffibuilder.set_source("_ceed_cffi",
467b8bbb42Svaleriabarra  """
477b8bbb42Svaleriabarra  #include <ceed.h>   // the C header of the library
487b8bbb42Svaleriabarra  """,
497b8bbb42Svaleriabarra  include_dirs = [os.path.abspath("include")], # include path
507b8bbb42Svaleriabarra  libraries = ["ceed"],   # library name, for the linker
517b8bbb42Svaleriabarra  library_dirs = [os.path.abspath("lib")], # library path, for the linker
52c794122cSjeremylt  runtime_library_dirs = ceed_lib_dirs # library path, at runtime
537b8bbb42Svaleriabarra)
547b8bbb42Svaleriabarra
557b8bbb42Svaleriabarra# ------------------------------------------------------------------------------
567b8bbb42Svaleriabarra# Builder
577b8bbb42Svaleriabarra# ------------------------------------------------------------------------------
587b8bbb42Svaleriabarraif __name__ == "__main__":
597b8bbb42Svaleriabarra    ffibuilder.compile(verbose=True)
607b8bbb42Svaleriabarra
617b8bbb42Svaleriabarra# ------------------------------------------------------------------------------
62