|
86 | 86 | gsl_version = gsl_version.split(".") |
87 | 87 | extra_compile_args.append("-D GSL_MAJOR_VERSION=%s" % (gsl_version[0])) |
88 | 88 |
|
| 89 | +# Use gsl-config to get GSL include and library paths to ensure they can be |
| 90 | +# found by the compiler and linker even if CFLAGS/LDFLAGS are not set; |
| 91 | +# skip paths already present in CFLAGS/LDFLAGS (or INCLUDE/LIB on Windows) to avoid duplicates |
| 92 | +gsl_include_dirs = [] |
| 93 | +gsl_library_dirs = [] |
| 94 | +if "PYODIDE" not in os.environ: |
| 95 | + if WIN32: |
| 96 | + _existing_includes = set( |
| 97 | + filter(None, os.environ.get("INCLUDE", "").split(os.pathsep)) |
| 98 | + ) |
| 99 | + _existing_libdirs = set( |
| 100 | + filter(None, os.environ.get("LIB", "").split(os.pathsep)) |
| 101 | + ) |
| 102 | + else: |
| 103 | + _existing_includes = { |
| 104 | + f[2:] for f in os.environ.get("CFLAGS", "").split() if f.startswith("-I") |
| 105 | + } |
| 106 | + _existing_libdirs = { |
| 107 | + f[2:] for f in os.environ.get("LDFLAGS", "").split() if f.startswith("-L") |
| 108 | + } |
| 109 | + try: |
| 110 | + # shell=True required on Windows to execute gsl-config.bat |
| 111 | + # (https://docs.python.org/3/library/subprocess.html#converting-argument-sequence) |
| 112 | + gsl_cflags = ( |
| 113 | + subprocess.check_output( |
| 114 | + ["gsl-config", "--cflags"], shell=sys.platform.startswith("win") |
| 115 | + ) |
| 116 | + .decode("utf-8") |
| 117 | + .strip() |
| 118 | + ) |
| 119 | + for flag in gsl_cflags.split(): |
| 120 | + if flag.startswith("-I"): |
| 121 | + path = flag[2:].strip('"') |
| 122 | + # Verify the path actually contains GSL headers before using it |
| 123 | + if path not in _existing_includes and os.path.isfile( |
| 124 | + os.path.join(path, "gsl", "gsl_math.h") |
| 125 | + ): |
| 126 | + gsl_include_dirs.append(path) |
| 127 | + except (OSError, subprocess.CalledProcessError): |
| 128 | + pass |
| 129 | + try: |
| 130 | + gsl_libs = ( |
| 131 | + subprocess.check_output( |
| 132 | + ["gsl-config", "--libs"], shell=sys.platform.startswith("win") |
| 133 | + ) |
| 134 | + .decode("utf-8") |
| 135 | + .strip() |
| 136 | + ) |
| 137 | + for flag in gsl_libs.split(): |
| 138 | + if flag.startswith("-L"): |
| 139 | + path = flag[2:].strip('"') |
| 140 | + # Verify the path actually contains GSL libraries before using it |
| 141 | + if path not in _existing_libdirs and ( |
| 142 | + glob.glob(os.path.join(path, "libgsl*")) |
| 143 | + or os.path.isfile(os.path.join(path, "gsl.lib")) |
| 144 | + ): |
| 145 | + gsl_library_dirs.append(path) |
| 146 | + except (OSError, subprocess.CalledProcessError): |
| 147 | + pass |
| 148 | + |
89 | 149 | # HACK for testing |
90 | 150 | # gsl_version= ['0','0'] |
91 | 151 |
|
|
118 | 178 | "galpy/actionAngle/actionAngle_c_ext", |
119 | 179 | "xsf/include", |
120 | 180 | ] |
| 181 | +galpy_c_include_dirs.extend(gsl_include_dirs) |
121 | 182 |
|
122 | 183 | # actionAngleTorus C extension (files here, so we can compile a single extension if so desidered) |
123 | 184 | actionAngleTorus_c_src = glob.glob("galpy/actionAngle/actionAngleTorus_c_ext/*.cc") |
|
150 | 211 | "galpy/potential/potential_c_ext", |
151 | 212 | "xsf/include", |
152 | 213 | ] |
| 214 | +actionAngleTorus_include_dirs.extend(gsl_include_dirs) |
153 | 215 |
|
154 | 216 | if single_ext: # add the code and libraries for the actionAngleTorus extensions |
155 | 217 | if os.path.exists("galpy/actionAngle/actionAngleTorus_c_ext/torus/src"): |
|
167 | 229 | sources=galpy_c_src, |
168 | 230 | libraries=galpy_c_libraries, |
169 | 231 | include_dirs=galpy_c_include_dirs, |
| 232 | + library_dirs=gsl_library_dirs, |
| 233 | + runtime_library_dirs=[] if WIN32 else gsl_library_dirs, |
170 | 234 | extra_compile_args=extra_compile_args, |
171 | 235 | extra_link_args=extra_link_args, |
172 | 236 | ) |
|
185 | 249 | sources=actionAngleTorus_c_src, |
186 | 250 | libraries=galpy_c_libraries, |
187 | 251 | include_dirs=actionAngleTorus_include_dirs, |
| 252 | + library_dirs=gsl_library_dirs, |
| 253 | + runtime_library_dirs=[] if WIN32 else gsl_library_dirs, |
188 | 254 | extra_compile_args=extra_compile_args, |
189 | 255 | extra_link_args=extra_link_args, |
190 | 256 | ) |
|
0 commit comments